use of io.gravitee.rest.api.model.UrlPictureEntity in project gravitee-management-rest-api by gravitee-io.
the class ThemeResource method buildPictureResponse.
private Response buildPictureResponse(PictureEntity picture, @Context Request request) {
if (picture == null) {
return Response.ok().build();
}
if (picture instanceof UrlPictureEntity) {
return Response.temporaryRedirect(URI.create(((UrlPictureEntity) picture).getUrl())).build();
}
CacheControl cc = new CacheControl();
cc.setNoTransform(true);
cc.setMustRevalidate(false);
cc.setNoCache(false);
cc.setMaxAge(86400);
InlinePictureEntity image = (InlinePictureEntity) picture;
EntityTag etag = new EntityTag(Integer.toString(new String(image.getContent()).hashCode()));
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
if (builder != null) {
// Preconditions are not met, returning HTTP 304 'not-modified'
return builder.cacheControl(cc).build();
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(image.getContent(), 0, image.getContent().length);
return Response.ok().entity(baos).cacheControl(cc).tag(etag).type(image.getType()).build();
}
Aggregations