use of io.gravitee.rest.api.model.MediaEntity in project gravitee-management-rest-api by gravitee-io.
the class PortalMediaResource method getPortalMedia.
@GET
@Path("/{hash}")
@ApiOperation(value = "Retrieve a media")
@ApiResponses({ @ApiResponse(code = 200, message = "A media"), @ApiResponse(code = 500, message = "Internal server error") })
public Response getPortalMedia(@Context Request request, @PathParam("hash") String hash) {
MediaEntity mediaEntity = mediaService.findByHash(hash);
if (mediaEntity == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
CacheControl cc = new CacheControl();
cc.setNoTransform(true);
cc.setMustRevalidate(false);
cc.setNoCache(false);
cc.setMaxAge(86400);
EntityTag etag = new EntityTag(hash);
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
if (builder != null) {
// Preconditions are not met, returning HTTP 304 'not-modified'
return builder.cacheControl(cc).build();
}
return Response.ok(mediaEntity.getData()).type(mediaEntity.getMimeType()).cacheControl(cc).tag(etag).build();
}
Aggregations