public static ResponseBuilder responseOfOk(final ReprRenderer<?, ?> renderer, final Caching caching, final Version version) { final MediaType mediaType = renderer.getMediaType(); final ResponseBuilder response = responseOf(HttpStatusCode.OK).type(mediaType).cacheControl(caching.getCacheControl()).entity(jsonFor(renderer.render())); return addLastModifiedAndETagIfAvailable(response, version); }
/** * @param rootRepresentationIfAny - if specified, is used for entity; otherwise the renderer is used. The idea is that the renderer will be set up to render to some sub-node of root representation */ public static Response.ResponseBuilder ofOk( final ReprRenderer<?, ?> renderer, final Caching caching, final Version version, final JsonRepresentation rootRepresentationIfAny) { final JsonRepresentation representation = renderer.render(); // if a rootRepresentation is provided, then the assumption is that the rendered // will be rendering to some submap of the rootRepresentation final JsonRepresentation entityRepresentation = rootRepresentationIfAny != null? rootRepresentationIfAny : representation; final MediaType mediaType = renderer.getMediaType(); final Date now = IsisContext.getSessionFactory().getServicesInjector() .lookupService(ClockService.class).nowAsDateTime().toDate(); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); final Response.ResponseBuilder response = of(RestfulResponse.HttpStatusCode.OK) .header("Date", dateFormat.format(now)) .type(mediaType) .cacheControl(caching.getCacheControl()) .entity(JsonWriterUtil.jsonFor(entityRepresentation)); return addLastModifiedAndETagIfAvailable(response, version); }