use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class AnnouncerRESTService method getMessageAttachment.
@GET
@Path("/attachment/{ATTACHMENTNAME}")
@RESTPermit(handling = Handling.UNSECURED)
public Response getMessageAttachment(@PathParam("ATTACHMENTNAME") String attachmentName, @Context Request request) {
if (StringUtils.isBlank(attachmentName)) {
return Response.status(Response.Status.BAD_REQUEST).build();
}
AnnouncementAttachment announcementAttachment = announcementController.findAttachmentByName(attachmentName);
if (announcementAttachment == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
EntityTag tag = new EntityTag(announcementAttachment.getName());
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok(announcementAttachment.getContent()).cacheControl(cacheControl).tag(tag).type(announcementAttachment.getContentType()).build();
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class HtmlMaterialRESTService method findMaterial.
@GET
@Path("/{id}")
@RESTPermitUnimplemented
public Response findMaterial(@PathParam("id") Long id, @QueryParam("revision") Long revision, @Context Request request) {
HtmlMaterial htmlMaterial = htmlMaterialController.findHtmlMaterialById(id);
if (htmlMaterial == null) {
return Response.status(Status.NOT_FOUND).build();
} else {
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(revision == null ? htmlMaterial.getRevisionNumber() : revision)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
if (revision == null) {
return Response.ok(createRestModel(htmlMaterial)).build();
} else {
File fileRevision;
try {
fileRevision = coOpsApi.fileGet(id.toString(), revision);
} catch (CoOpsNotImplementedException | CoOpsNotFoundException | CoOpsUsageException | CoOpsInternalErrorException | CoOpsForbiddenException e) {
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
}
if (fileRevision == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(createRestModel(htmlMaterial, fileRevision)).build();
}
}
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class BinaryMaterialRESTService method getMaterialContent.
@GET
@Path("/{id}/content")
@RESTPermitUnimplemented
public Response getMaterialContent(@PathParam("id") Long id, @Context Request request) {
BinaryMaterial material = binaryMaterialController.findBinaryMaterialById(id);
if (material == null) {
return Response.status(Status.NOT_FOUND).build();
} else {
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(material.getVersion())));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok(material.getContent()).cacheControl(cacheControl).tag(tag).type(material.getContentType()).build();
}
}
use of javax.ws.rs.core.EntityTag in project muikku by otavanopisto.
the class WorkspaceRESTService method getWorkspaceFileContent.
@GET
@Path("/workspaces/{WORKSPACEID}/workspacefile/{FILEIDENTIFIER}")
@RESTPermit(handling = Handling.INLINE)
public Response getWorkspaceFileContent(@PathParam("WORKSPACEID") Long workspaceId, @PathParam("FILEIDENTIFIER") String fileIdentifier, @Context Request request) {
WorkspaceEntity workspaceEntity = workspaceEntityController.findWorkspaceEntityById(workspaceId);
if (workspaceEntity == null)
return Response.status(Status.BAD_REQUEST).build();
WorkspaceEntityFile imageFile = workspaceEntityFileController.findWorkspaceEntityFile(workspaceEntity, fileIdentifier);
if (imageFile == null)
return Response.status(Status.NOT_FOUND).build();
StreamingOutput output = s -> fileController.outputFileToStream("workspace", imageFile.getDiskName(), s);
String contentType = imageFile.getContentType();
String tagIdentifier = String.format("%d-%s-%d", imageFile.getWorkspaceEntity(), imageFile.getDiskName(), imageFile.getLastModified().getTime());
EntityTag tag = new EntityTag(DigestUtils.md5Hex(String.valueOf(tagIdentifier)));
ResponseBuilder builder = request.evaluatePreconditions(tag);
if (builder != null) {
return builder.build();
}
CacheControl cacheControl = new CacheControl();
cacheControl.setMustRevalidate(true);
return Response.ok().cacheControl(cacheControl).tag(tag).type(contentType).entity(output).build();
}
use of javax.ws.rs.core.EntityTag in project graylog2-server by Graylog2.
the class CollectorResource method listCollectors.
@GET
@Timed
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_READ)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List all collectors")
public Response listCollectors(@Context HttpHeaders httpHeaders) {
String ifNoneMatch = httpHeaders.getHeaderString("If-None-Match");
Boolean etagCached = false;
Response.ResponseBuilder builder = Response.noContent();
// check if client is up to date with a known valid etag
if (ifNoneMatch != null) {
EntityTag etag = new EntityTag(ifNoneMatch.replaceAll("\"", ""));
if (etagService.isPresent(etag.toString())) {
etagCached = true;
builder = Response.notModified();
builder.tag(etag);
}
}
// fetch collector list from database if client is outdated
if (!etagCached) {
final List<Collector> result = this.collectorService.all();
CollectorListResponse collectorListResponse = CollectorListResponse.create(result.size(), result);
// add new etag to cache
String etagString = collectorsToEtag(collectorListResponse);
EntityTag collectorsEtag = new EntityTag(etagString);
builder = Response.ok(collectorListResponse);
builder.tag(collectorsEtag);
etagService.put(collectorsEtag.toString());
}
// set cache control
CacheControl cacheControl = new CacheControl();
cacheControl.setNoTransform(true);
cacheControl.setPrivate(true);
builder.cacheControl(cacheControl);
return builder.build();
}
Aggregations