@Override public void handle(Request request, Response response) { response.setEntity("Hello.", MediaType.TEXT_PLAIN); } };
@Override public void handle(Request request, Response response) { response.setEntity("Bye", MediaType.TEXT_PLAIN); } };
public Response prepareResponse(Response response, boolean withEnvelope) { if (response == null || status == null || description == null) return null; // fill status with description and make sure entity is of type JSON response.setStatus(status, description); Gson gson = new Gson(); if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE); else response.setEntity(gson.toJson(this), MEDIA_TYPE); return response; }
public Response prepareResponse(Response response, boolean withEnvelope) { if (response == null || status == null || description == null) return null; // fill status with description and make sure entity is of type JSON response.setStatus(status, description); Gson gson = new Gson(); if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE); else response.setEntity(gson.toJson(this), MEDIA_TYPE); return response; }
public Response prepareResponse(Response response, boolean withEnvelope) { if (response == null || status == null || description == null) return null; // fill status with description and make sure entity is of type JSON response.setStatus(status, description); Gson gson = new Gson(); if (!withEnvelope && result != null) response.setEntity(gson.toJson(result), MEDIA_TYPE); else response.setEntity(gson.toJson(this), MEDIA_TYPE); return response; }
/** * Sets a textual entity. * * @param value * The represented string. * @param mediaType * The representation's media type. */ @Override public void setEntity(String value, MediaType mediaType) { getWrappedResponse().setEntity(value, mediaType); }
/** * Sets the entity representation. * * @param entity * The entity representation. */ @Override public void setEntity(Representation entity) { getWrappedResponse().setEntity(entity); }
@Override public void handle(Request request, Response response) { // Print the user name of the requested orders String message = "Orders of user \"" + request.getAttributes().get("user") + "\""; response.setEntity(message, MediaType.TEXT_PLAIN); } };
@Override public void handle(Request request, Response response) { // Print the requested URI path String message = "Account of user \"" + request.getAttributes().get("user") + "\""; response.setEntity(message, MediaType.TEXT_PLAIN); } };
@Override public void handle(Request request, Response response) { // Print the user name of the requested orders String message = "Order \"" + request.getAttributes().get("order") + "\" for user \"" + request.getAttributes().get("user") + "\""; response.setEntity(message, MediaType.TEXT_PLAIN); } };
private int sendErrorPage(Response response, Exception ex) { response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ex.getMessage()); response.setEntity(getErrorPage(ex)); return STOP; }
@Override public void challenge(Response response, boolean stale) { // Load the FreeMarker template Representation ftl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Login.ftl").get(); // Wraps the bean with a FreeMarker representation response.setEntity(new TemplateRepresentation(ftl, response .getRequest().getResourceRef(), MediaType.TEXT_HTML)); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); }
@Override public void challenge(Response response, boolean stale) { // Load the FreeMarker template Representation ftl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Login.ftl").get(); // Wraps the bean with a FreeMarker representation response.setEntity(new TemplateRepresentation(ftl, response .getRequest().getResourceRef(), MediaType.TEXT_HTML)); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); }
@Override protected void afterHandle(Request request, Response response) { if ((getMode() == MODE_RESPONSE) && canTransform(response.getEntity())) { response.setEntity(transform(response.getEntity())); } }
@Override protected void doCatch(Throwable t) { final OAuthException oex = OAuthException.toOAuthException(t); // XXX: Generally, we only communicate with TokenVerifier. So we don't // need HTTP 400 code. // getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); getResponse().setStatus(Status.SUCCESS_OK); getResponse().setEntity(responseErrorRepresentation(oex)); }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings() .contains(Encoding.FREEMARKER)) { TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); representation.setDataModel(createDataModel(request, response)); response.setEntity(representation); } }
@Override public void handle(Request request, Response response) { String entity = "Method : " + request.getMethod() + "\nResource URI : " + request.getResourceRef() + "\nIP address : " + request.getClientInfo().getAddress() + "\nAgent name : " + request.getClientInfo().getAgentName() + "\nAgent version: " + request.getClientInfo().getAgentVersion(); response.setEntity(entity, MediaType.TEXT_PLAIN); }
@Override public void handle(Request request, Response response) { String entity = "Method : " + request.getMethod() + "\nResource URI : " + request.getResourceRef() + "\nIP address : " + request.getClientInfo().getAddress() + "\nAgent name : " + request.getClientInfo().getAgentName() + "\nAgent version: " + request.getClientInfo().getAgentVersion(); response.setEntity(entity, MediaType.TEXT_PLAIN); }
@Override public void handle(Request request, Response response) { String entity = "Method : " + request.getMethod() + "\nResource URI : " + request.getResourceRef() + "\nIP address : " + request.getClientInfo().getAddress() + "\nAgent name : " + request.getClientInfo().getAgentName() + "\nAgent version: " + request.getClientInfo().getAgentVersion(); response.setEntity(entity, MediaType.TEXT_PLAIN); } };
@Override public void handle(Request request, Response response) { String entity = "Method : " + request.getMethod() + "\nResource URI : " + request.getResourceRef() + "\nIP address : " + request.getClientInfo().getAddress() + "\nAgent name : " + request.getClientInfo().getAgentName() + "\nAgent version: " + request.getClientInfo().getAgentVersion(); response.setEntity(entity, MediaType.TEXT_PLAIN); } };