Java Code Examples for javax.ws.rs.core.Response.StatusType#getStatusCode()

The following examples show how to use javax.ws.rs.core.Response.StatusType#getStatusCode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphQlClientProxy.java    From smallrye-graphql with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 2
Source File: HttpStatusManager.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public void addStatusType(StatusType status) {
  if (statusMap.containsKey(status.getStatusCode())) {
    throw new IllegalStateException("repeated status code: " + status.getStatusCode());
  }

  statusMap.put(status.getStatusCode(), status);
}
 
Example 3
Source File: ServiceRequestHandler.java    From jrestless with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 4
Source File: GatewayResponse.java    From jrestless with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 5
Source File: ApiUtil.java    From keycloak with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: JaxRsLogConverters.java    From logging-interceptor with Apache License 2.0 4 votes vote down vote up
public String convert(Response response) {
    StatusType statusInfo = response.getStatusInfo();
    return statusInfo.getStatusCode() + " " + statusInfo.getReasonPhrase() + entityInfo(response);
}
 
Example 7
Source File: MCRWorksPublisher.java    From mycore with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
    }
}
 
Example 8
Source File: SnsRequestHandler.java    From jrestless with Apache License 2.0 3 votes vote down vote up
/**
 * 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());
	}
}