/** * 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(); } }
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 \"" + "\" returns one or sets the status to 204 (No content)."); } else if (response.getStatus().equals(Status.SUCCESS_NO_CONTENT)) { addEntityHeaders(response); getLogger() .fine("Responses with a 204 (No content) status generally don't have an entity. Only adding entity headers for resource \"" + response.getRequest().getResourceRef() .equals(Status.SUCCESS_RESET_CONTENT)) { if (response.isEntityAvailable()) { getLogger() .warning( "Responses with a 205 (Reset content) status can't have an entity. Ignoring the entity for resource \"" getLogger() .warning( "Responses with an informational (1xx) status can't have an entity. Ignoring the entity for resource \""
HttpRequest result = new HttpRequest(getContext(), httpCall); result.getAttributes().put(ATTRIBUTE_HEADERS, httpCall.getRequestHeaders());
/** * 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()); } }