use of org.graylog.plugins.sidecar.rest.responses.CollectorListResponse 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