javax.ws.rs.core.Response.StatusType#getStatusCode()源码实例Demo

下面列出了javax.ws.rs.core.Response.StatusType#getStatusCode() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。


private String post(String request, MultivaluedMap<String, Object> headers) {
    Response response = target
            .request(APPLICATION_JSON_TYPE)
            .headers(headers)
            .post(Entity.json(request));
    StatusType status = response.getStatusInfo();
    if (status.getFamily() != SUCCESSFUL)
        throw new GraphQlClientException("expected successful status code but got " +
                status.getStatusCode() + " " + status.getReasonPhrase() + ":\n" +
                response.readEntity(String.class));
    return response.readEntity(String.class);
}
 

public void addStatusType(StatusType status) {
  if (statusMap.containsKey(status.getStatusCode())) {
    throw new IllegalStateException("repeated status code: " + status.getStatusCode());
  }

  statusMap.put(status.getStatusCode(), status);
}
 
源代码3 项目: jrestless   文件: ServiceRequestHandler.java

@Override
public void writeResponse(StatusType statusType, Map<String, List<String>> headers,
		OutputStream entityOutputStream) throws IOException {
	String body = ((ByteArrayOutputStream) entityOutputStream).toString(StandardCharsets.UTF_8.name());
	response = new DefaultServiceResponse(body, headers, statusType.getStatusCode(),
			statusType.getReasonPhrase());
}
 
源代码4 项目: jrestless   文件: GatewayResponse.java

public GatewayResponse(@Nullable String body, @Nonnull Map<String, String> headers,
		@Nonnull StatusType statusType, boolean base64Encoded) {
	requireNonNull(headers);
	requireNonNull(statusType);
	this.statusCode = statusType.getStatusCode();
	this.body = body;
	this.headers = Collections.unmodifiableMap(new HashMap<>(headers));
	this.base64Encoded = base64Encoded;
}
 
源代码5 项目: keycloak   文件: ApiUtil.java

public static String getCreatedId(Response response) {
    URI location = response.getLocation();
    if (!response.getStatusInfo().equals(Status.CREATED)) {
        StatusType statusInfo = response.getStatusInfo();
        response.bufferEntity();
        String body = response.readEntity(String.class);
        throw new WebApplicationException("Create method returned status "
                + statusInfo.getReasonPhrase() + " (Code: " + statusInfo.getStatusCode() + "); expected status: Created (201). Response body: " + body, response);
    }
    if (location == null) {
        return null;
    }
    String path = location.getPath();
    return path.substring(path.lastIndexOf('/') + 1);
}
 

public String convert(Response response) {
    StatusType statusInfo = response.getStatusInfo();
    return statusInfo.getStatusCode() + " " + statusInfo.getReasonPhrase() + entityInfo(response);
}
 
源代码7 项目: mycore   文件: MCRWorksPublisher.java

/**
 * If the response is not as expected and the request was not successful,
 * throws an exception with detailed error message from the ORCID REST API.
 *
 * @param response the response to the REST request
 * @param expectedStatus the status expected when request is successful
 * @throws MCRORCIDException if the ORCID API returned error information
 */
private void expect(Response response, Response.Status expectedStatus)
    throws IOException {
    StatusType status = response.getStatusInfo();
    if (status.getStatusCode() != expectedStatus.getStatusCode()) {
        throw new MCRORCIDException(response);
    }
}
 
源代码8 项目: jrestless   文件: SnsRequestHandler.java

/**
 * Hook method to deal with responses.
 * <p>
 * SNS cannot react to responses this is mainly here to log issues.
 * <p>
 * The default implementation logs all non 2xx responses to error and non
 * 204 responses to warning.
 *
 * @param snsRecordAndContext
 *            the request
 * @param statusType
 *            the response status type
 * @param headers
 *            the response headers
 * @param entityOutputStream
 *            the response body
 */
public void handleReponse(SnsRecordAndLambdaContext snsRecordAndContext, StatusType statusType,
		Map<String, List<String>> headers, ByteArrayOutputStream entityOutputStream) {
	Supplier<String> logMsgSupplier = () -> "endpoints consuming sns events should respond with 204 but got '"
			+ statusType.getStatusCode() + "' for topic '"
			+ snsRecordAndContext.getSnsRecord().getSNS().getTopicArn() + "'";
	if (!Status.Family.SUCCESSFUL.equals(statusType.getFamily())) {
		LOG.error(logMsgSupplier.get());
	} else if (!Status.NO_CONTENT.equals(statusType)) {
		LOG.warn(logMsgSupplier.get());
	}
}