Java Code Examples for javax.ws.rs.core.Response.Status#fromStatusCode()
The following examples show how to use
javax.ws.rs.core.Response.Status#fromStatusCode() .
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: DefaultDisseminationHandler.java From proarc with GNU General Public License v3.0 | 6 votes |
public static Response getResponse(RemoteObject remote, String dsId) throws DigitalObjectException { // This should limit fedora calls to 1. // XXX It works around FedoraClient.FedoraClient.getDatastreamDissemination that hides HTTP headers of the response. // Unfortunattely fedora does not return modification date as HTTP header // In case of large images it could be faster to ask datastream for modification date first. String pid = remote.getPid(); String path = String.format("objects/%s/datastreams/%s/content", pid, dsId); ClientResponse response = remote.getClient().resource().path(path).get(ClientResponse.class); if (Status.fromStatusCode(response.getStatus()) != Status.OK) { throw new DigitalObjectNotFoundException(pid, null, dsId, response.getEntity(String.class), null); } MultivaluedMap<String, String> headers = response.getHeaders(); String filename = headers.getFirst("Content-Disposition"); filename = filename != null ? filename : "inline; filename=" + pid + '-' + dsId; return Response.ok(response.getEntity(InputStream.class), headers.getFirst("Content-Type")) .header("Content-Disposition", filename) .build(); }
Example 2
Source File: ResourceNotFoundProvider.java From library with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * * @param exception * @return */ @Override public Response toResponse(ResourceNotFoundException exception) { final Status status = Status.fromStatusCode(exception.getHttpStatus()); return Response.status(status) .entity(ErrorMessage.of(exception)) .type(MediaType.APPLICATION_JSON) .build(); }
Example 3
Source File: BaseResponseHandler.java From agrest with Apache License 2.0 | 5 votes |
@Override public final T handleResponse(Response response) { Status status = Status.fromStatusCode(response.getStatus()); if (status.getFamily() != Status.Family.SUCCESSFUL) { throw new AgClientException(buildErrorMessage(status, response)); } return doHandleResponse(status, response); }
Example 4
Source File: JaxRsAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 4 votes |
@Override public String getReasonPhrase(int statusCode) { Status status = Status.fromStatusCode(statusCode); return status != null ? status.getReasonPhrase() : null; }
Example 5
Source File: BackchannelAuthenticationCompleteHandlerSpiImpl.java From java-oauth-server with Apache License 2.0 | 4 votes |
@Override public void sendNotification(BackchannelAuthenticationCompleteResponse info) { // The URL of the consumption device's notification endpoint. URI clientNotificationEndpointUri = info.getClientNotificationEndpoint(); // The token that is needed for client authentication at the consumption // device's notification endpoint. String notificationToken = info.getClientNotificationToken(); // The notification content (JSON) to send to the consumption device. String notificationContent = info.getResponseContent(); // Send the notification to the consumption device's notification endpoint. Response response = doSendNotification(clientNotificationEndpointUri, notificationToken, notificationContent); // The status of the response from the consumption device. Status status = Status.fromStatusCode(response.getStatusInfo().getStatusCode()); // TODO: CIBA specification does not specify how to deal with responses // returned from the consumption device in case of error push notification. // Then, even in case of error push notification, the current implementation // treats the responses as in the case of successful push notification. // Check if the "HTTP 200 OK" or "HTTP 204 No Content". if (status == Status.OK || status == Status.NO_CONTENT) { // In this case, the request was successfully processed by the consumption // device since the specification says as follows. // // CIBA Core spec, 10.2. Ping Callback and 10.3. Push Callback // For valid requests, the Client Notification Endpoint SHOULD // respond with an HTTP 204 No Content. The OP SHOULD also accept // HTTP 200 OK and any body in the response SHOULD be ignored. // return; } if (status.getFamily() == Status.Family.REDIRECTION) { // HTTP 3xx code. This case must be ignored since the specification // says as follows. // // CIBA Core spec, 10.2. Ping Callback, 10.3. Push Callback // The Client MUST NOT return an HTTP 3xx code. The OP MUST // NOT follow redirects. // return; } }
Example 6
Source File: SimpleClientResponse.java From osiris with Apache License 2.0 | 4 votes |
public Status getStatus() { return Status.fromStatusCode(statusCode); }
Example 7
Source File: ApiServiceDispatcher.java From iaf with Apache License 2.0 | 4 votes |
private JsonObjectBuilder mapResponses(IAdapter adapter, MediaTypes contentType, JsonObjectBuilder schemas) { JsonObjectBuilder responses = Json.createObjectBuilder(); PipeLine pipeline = adapter.getPipeLine(); Json2XmlValidator validator = getJsonValidator(pipeline); JsonObjectBuilder schema = null; if(validator != null) { JsonObject jsonSchema = validator.createJsonSchemaDefinitions("#/components/schemas/"); if(jsonSchema != null) { for (Entry<String,JsonValue> entry: jsonSchema.entrySet()) { schemas.add(entry.getKey(), entry.getValue()); } String ref = validator.getMessageRoot(true); schema = Json.createObjectBuilder(); schema.add("schema", Json.createObjectBuilder().add("$ref", "#/components/schemas/"+ref)); } } Map<String, PipeLineExit> pipeLineExits = pipeline.getPipeLineExits(); for(String exitPath : pipeLineExits.keySet()) { PipeLineExit ple = pipeLineExits.get(exitPath); int exitCode = ple.getExitCode(); if(exitCode == 0) { exitCode = 200; } JsonObjectBuilder exit = Json.createObjectBuilder(); Status status = Status.fromStatusCode(exitCode); exit.add("description", status.getReasonPhrase()); if(!ple.getEmptyResult()) { JsonObjectBuilder content = Json.createObjectBuilder(); if(schema == null) { content.addNull(contentType.getContentType()); } else { content.add(contentType.getContentType(), schema); } exit.add("content", content); } responses.add(""+exitCode, exit); } return responses; }
Example 8
Source File: ApiException.java From iaf with Apache License 2.0 | 4 votes |
public ApiException(Throwable t, int status) { this(t.getMessage(), t, Status.fromStatusCode(status)); }