@Override public void respondContent( Resource resource, Response response, Request request, Map<String, String> params) throws NotAuthorizedException, BadRequestException, NotFoundException { log.debug("respondContent: " + resource.getClass()); Auth auth = request.getAuthorization(); setRespondContentCommonHeaders(response, resource, auth); if (resource instanceof GetableResource) { GetableResource gr = (GetableResource) resource; String acc = request.getAcceptHeader(); String ct = gr.getContentType(acc); if (ct != null) { ct = pickBestContentType(ct); response.setContentTypeHeader(ct); } cacheControlHelper.setCacheControl(gr, response, request.getAuthorization()); Long contentLength = gr.getContentLength(); Boolean doBuffering = null; if (resource instanceof BufferingControlResource) { BufferingControlResource bcr = (BufferingControlResource) resource; doBuffering = bcr.isBufferingRequired(); } if (doBuffering == null) { if (buffering == null || buffering == BUFFERING.whenNeeded) { doBuffering = (contentLength == null); // if no content length then we buffer content to find content length } else { doBuffering = (buffering == BUFFERING .always); // if not null or whenNeeded then buffering is explicitly enabled or // disabled } } if (!doBuffering) { log.trace("sending content with known content length: " + contentLength); if (contentLength != null) { response.setContentLengthHeader(contentLength); } response.setEntity(new GetableResourceEntity(gr, params, ct)); } else { BufferingGetableResourceEntity e = new BufferingGetableResourceEntity(gr, params, ct, contentLength, getMaxMemorySize()); response.setEntity(e); } } }
@Override public void respondWithOptions( Resource resource, Response response, Request request, List<String> methodsAllowed) { setRespondCommonHeaders(response, resource, Status.SC_OK, request.getAuthorization()); response.setAllowHeader(methodsAllowed); response.setContentLengthHeader((long) 0); }
@Override public void respondHead(Resource resource, Response response, Request request) { // setRespondContentCommonHeaders(response, resource, Response.Status.SC_NO_CONTENT, // request.getAuthorization()); setRespondContentCommonHeaders( response, resource, Response.Status.SC_OK, request.getAuthorization()); if (!(resource instanceof GetableResource)) { return; } GetableResource gr = (GetableResource) resource; Long contentLength = gr.getContentLength(); if (contentLength != null) { response.setContentLengthHeader(contentLength); } else { log.trace("No content length is available for HEAD request"); } String acc = request.getAcceptHeader(); String ct = gr.getContentType(acc); if (ct != null) { ct = pickBestContentType(ct); if (ct != null) { response.setContentTypeHeader(ct); } } }
@Override public void respondNoContent(Resource resource, Response response, Request request) { // log.debug( "respondNoContent" ); // response.setStatus(Response.Status.SC_OK); // see comments in http://www.ettrema.com:8080/browse/MIL-87 setRespondCommonHeaders(response, resource, Status.SC_NO_CONTENT, request.getAuthorization()); }
@Override public void respondNotModified(GetableResource resource, Response response, Request request) { log.trace("respondNotModified"); response.setStatus(Response.Status.SC_NOT_MODIFIED); response.setDateHeader(new Date()); String etag = eTagGenerator.generateEtag(resource); if (etag != null) { response.setEtag(etag); } // Note that we use a simpler modified date handling here then when // responding with content, because in a not-modified situation the // modified date MUST be that of the actual resource Date modDate = resource.getModifiedDate(); response.setLastModifiedHeader(modDate); cacheControlHelper.setCacheControl(resource, response, request.getAuthorization()); }
@Override public void respondCreated(Resource resource, Response response, Request request) { // log.debug( "respondCreated" ); setRespondCommonHeaders(response, resource, Status.SC_CREATED, request.getAuthorization()); }