/** * Adds the entity headers for the handled uniform call. * * @param response * The response returned. */ protected void addEntityHeaders(HttpResponse response) { Series<Header> responseHeaders = response.getHttpCall() .getResponseHeaders(); Representation entity = response.getEntity(); HeaderUtils.addEntityHeaders(entity, responseHeaders); }
/** * Constructor. * * @param httpCall * The low-level HTTP server call. * @param request * The associated high-level request. */ public HttpResponse(ServerCall httpCall, Request request) { super(request); this.serverAdded = false; this.httpCall = httpCall; // Set the properties setStatus(Status.SUCCESS_OK); }
if ((response.getRequest().getMethod() != null) && response.getRequest().getMethod().equals(Method.HEAD)) { addEntityHeaders(response); response.setEntity(null); } else if (Method.GET.equals(response.getRequest().getMethod()) && Status.SUCCESS_OK.equals(response.getStatus()) && (!response.isEntityAvailable())) { addEntityHeaders(response); getLogger() .warning( "A response with a 200 (Ok) status should have an entity. Make sure that resource \"" + response.getRequest() .getResourceRef() + "\" returns one or sets the status to 204 (No content)."); } else if (response.getStatus().equals(Status.SUCCESS_NO_CONTENT)) { addEntityHeaders(response); if (response.isEntityAvailable()) { getLogger() .fine("Responses with a 204 (No content) status generally don't have an entity. Only adding entity headers for resource \"" + response.getRequest().getResourceRef() + "\"."); response.setEntity(null); } else if (response.getStatus() .equals(Status.SUCCESS_RESET_CONTENT)) { if (response.isEntityAvailable()) { getLogger() .warning(
/** * Adds the response headers for the handled uniform call. * * @param response * The response returned. */ protected void addResponseHeaders(HttpResponse response) { try { // Add all the necessary headers HeaderUtils.addGeneralHeaders(response, response.getHttpCall() .getResponseHeaders()); HeaderUtils.addResponseHeaders(response, response.getHttpCall() .getResponseHeaders()); // Set the status code in the response if (response.getStatus() != null) { response.getHttpCall().setStatusCode( response.getStatus().getCode()); response.getHttpCall().setReasonPhrase( response.getStatus().getReasonPhrase()); } } catch (Exception e) { getLogger().log(Level.WARNING, "Exception intercepted while adding the response headers", e); response.getHttpCall().setStatusCode( Status.SERVER_ERROR_INTERNAL.getCode()); response.getHttpCall().setReasonPhrase( Status.SERVER_ERROR_INTERNAL.getReasonPhrase()); } }
protected Series<org.restlet.engine.header.Header> getRawHeaders() { return getTarget().getHttpCall().getResponseHeaders(); }
@Override public Status getStatus() { return Status.SC_OK.fromCode(getTarget().getStatus().getCode()); }
public void setTargetEntity() { final Entity entity; if ((entity = getEntity()) != null) { MediaType contentType = MediaType.valueOf(getContentTypeHeader()); getTarget().setEntity(new OutputRepresentation(contentType) { @Override public void write(OutputStream outputStream) throws IOException { try { entity.write(ResponseAdapter.this, outputStream); } catch (IOException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } } }); } }
@Override public Cookie setCookie(Cookie cookie) { getTarget().getCookieSettings().add(new CookieAdapter(cookie).getTarget()); return cookie; }
/** * Handles the connector call. The default behavior is to create an REST * call and delegate it to the attached Restlet. * * @param httpCall * The HTTP server call. */ public void handle(ServerCall httpCall) { try { HttpRequest request = getAdapter().toRequest(httpCall); HttpResponse response = new HttpResponse(httpCall, request); handle(request, response); getAdapter().commit(response); } catch (Exception e) { getLogger().log(Level.WARNING, "Error while handling an HTTP server call", e); } finally { Engine.clearThreadLocalVariables(); } }
@Override public Cookie setCookie(String name, String value) { CookieAdapter cookie = new CookieAdapter(name, value); getTarget().getCookieSettings().add(cookie.getTarget()); return cookie; }
@Override public void setStatus(Status status) { getTarget().setStatus(org.restlet.data.Status.valueOf(status.code)); }