Java Code Examples for com.sun.jersey.spi.container.ContainerResponse#getEntity()
The following examples show how to use
com.sun.jersey.spi.container.ContainerResponse#getEntity() .
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: StaashAuditFilter.java From staash with Apache License 2.0 | 6 votes |
/** * Private helper that adds the request-id to the response payload. * @param response */ private void addRequestIdToResponse(ContainerResponse response) { // The request-id to be injected in the response String requestId = StaashRequestContext.getRequestId(); // The key response attributes int status = response.getStatus(); MediaType mediaType = response.getMediaType(); if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) { String message = (String)response.getEntity(); JsonObject json = new JsonObject(message); json.putString("request-id", requestId); Response newJerseyResponse = Response.status(status).type(mediaType).entity(json.toString()).build(); response.setResponse(newJerseyResponse); } // Add the request id to the response regardless of the media type, // this allows non json responses to have a request id in the response response.getHttpHeaders().add("x-nflx-staash-request-id", requestId); }
Example 2
Source File: HypermediaFilter.java From Processor with Apache License 2.0 | 5 votes |
@Override public ContainerResponse filter(ContainerRequest request, ContainerResponse response) { if (request == null) throw new IllegalArgumentException("ContainerRequest cannot be null"); if (response == null) throw new IllegalArgumentException("ContainerResponse cannot be null"); // do not process hypermedia if the response is a redirect or 201 Created or 404 Not Found if (response.getStatusType().getFamily().equals(REDIRECTION) || response.getStatusType().equals(CREATED) || response.getStatusType().equals(NOT_FOUND) || response.getStatusType().equals(INTERNAL_SERVER_ERROR) || response.getEntity() == null || (!(response.getEntity() instanceof Dataset))) return response; TemplateCall templateCall = getTemplateCall(); if (templateCall == null) return response; Resource state = templateCall.build(); Resource absolutePath = state.getModel().createResource(request.getAbsolutePath().toString()); if (!state.equals(absolutePath)) state.addProperty(C.stateOf, absolutePath); Resource requestUri = state.getModel().createResource(request.getRequestUri().toString()); if (!state.equals(requestUri)) // add hypermedia if there are query parameters state.addProperty(C.viewOf, requestUri). // needed to lookup response state by request URI without redirection addProperty(RDF.type, C.View); if (log.isDebugEnabled()) log.debug("Added Number of HATEOAS statements added: {}", state.getModel().size()); Dataset newEntity = ((Dataset)response.getEntity()); newEntity.getDefaultModel().add(state.getModel()); response.setEntity(newEntity); return response; }