Java Code Examples for javax.ws.rs.core.Response.ResponseBuilder#cacheControl()

The following examples show how to use javax.ws.rs.core.Response.ResponseBuilder#cacheControl() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Processor   File: ResourceBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates response builder from response dataset.
 * Adds matched sitemap class as affordance metadata in <pre>Link</pre> header.
 * 
 * @param dataset response RDF dataset
 * @return response builder
 */
@Override
public ResponseBuilder getResponseBuilder(Dataset dataset)
{
    ResponseBuilder rb = super.getResponseBuilder(dataset);
    
    rb.cacheControl(getCacheControl());

    rb.header("Link", new Link(URI.create(getTemplateCall().getTemplate().getURI()), LDT.template.getURI(), null));
    rb.header("Link", new Link(URI.create(getApplication().getOntology().getURI()), LDT.ontology.getURI(), null));
    rb.header("Link", new Link(getUriInfo().getBaseUri(), LDT.base.getURI(), null));
    
    Reasoner reasoner = getTemplateCall().getTemplate().getOntModel().getSpecification().getReasoner();
    if (reasoner instanceof GenericRuleReasoner)
    {
        GenericRuleReasoner grr = (GenericRuleReasoner)reasoner;
        rb.header("Rules", RulePrinter.print(grr.getRules())); // grr.getRules().toString() - prevented by JENA-1030 bug
    }
    
    return rb;
}
 
Example 2
Source Project: Processor   File: ResourceBase.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates response builder from response model.
 * Adds matched sitemap class as affordance metadata in <pre>Link</pre> header.
 * 
 * @param model response RDF model
 * @return response builder
 */
@Override
public ResponseBuilder getResponseBuilder(Model model)
{
    ResponseBuilder rb = super.getResponseBuilder(model);
    
    rb.cacheControl(getCacheControl());

    rb.header("Link", new Link(URI.create(getTemplateCall().getTemplate().getURI()), LDT.template.getURI(), null));
    rb.header("Link", new Link(URI.create(getApplication().getOntology().getURI()), LDT.ontology.getURI(), null));
    rb.header("Link", new Link(getUriInfo().getBaseUri(), LDT.base.getURI(), null));
    
    Reasoner reasoner = getTemplateCall().getTemplate().getOntModel().getSpecification().getReasoner();
    if (reasoner instanceof GenericRuleReasoner)
    {
        GenericRuleReasoner grr = (GenericRuleReasoner)reasoner;
        rb.header("Rules", RulePrinter.print(grr.getRules())); // grr.getRules().toString() - prevented by JENA-1030 bug
    }
    
    return rb;
}
 
Example 3
Source Project: hbase   File: SchemaResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    ResponseBuilder response =
      Response.ok(new TableSchemaModel(getTableSchema()));
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return processException(e);
  }
}
 
Example 4
Source Project: hbase   File: RootResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    ResponseBuilder response = Response.ok(getTableList());
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return processException(e);
  }
}
 
Example 5
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    StorageClusterVersionModel model = new StorageClusterVersionModel();
    model.setVersion(
      servlet.getAdmin().getClusterMetrics(EnumSet.of(Option.HBASE_VERSION))
          .getHBaseVersion());
    ResponseBuilder response = Response.ok(model);
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (IOException e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  }
}
 
Example 6
Source Project: hbase   File: ExistsResource.java    License: Apache License 2.0 6 votes vote down vote up
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF, MIMETYPE_BINARY})
public Response get(final @Context UriInfo uriInfo) {
  try {
    if (!tableResource.exists()) {
      return Response.status(Response.Status.NOT_FOUND)
        .type(MIMETYPE_TEXT).entity("Not found" + CRLF)
        .build();
    }
  } catch (IOException e) {
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  }
  ResponseBuilder response = Response.ok();
  response.cacheControl(cacheControl);
  return response.build();
}
 
Example 7
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) {
	String etagSource = DominoUtils.md5(jsonEntity);
	EntityTag etag = new EntityTag(etagSource);
	ResponseBuilder berg = null;
	if (request != null) {
		berg = request.evaluatePreconditions(etag);
	}
	if (berg == null) {
		berg = Response.ok();
		if (includeEtag) {
			berg.tag(etag);
		}
		berg.type(MediaType.APPLICATION_JSON_TYPE);
		berg.entity(jsonEntity);
		berg.lastModified(lastMod);
		CacheControl cc = new CacheControl();
		cc.setMustRevalidate(true);
		cc.setPrivate(true);
		cc.setMaxAge(86400);
		cc.setNoTransform(true);
		berg.cacheControl(cc);
	}
	return berg;
}
 
Example 8
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) {
	String etagSource = DominoUtils.md5(jsonEntity);
	EntityTag etag = new EntityTag(etagSource);
	ResponseBuilder berg = null;
	if (request != null) {
		berg = request.evaluatePreconditions(etag);
	}
	if (berg == null) {
		berg = Response.ok();
		if (includeEtag) {
			berg.tag(etag);
		}
		berg.type(MediaType.APPLICATION_JSON_TYPE);
		berg.entity(jsonEntity);
		berg.lastModified(lastMod);
		CacheControl cc = new CacheControl();
		cc.setMustRevalidate(true);
		cc.setPrivate(true);
		cc.setMaxAge(86400);
		cc.setNoTransform(true);
		berg.cacheControl(cc);
	}
	return berg;
}
 
Example 9
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) {
	String etagSource = DominoUtils.md5(jsonEntity);
	EntityTag etag = new EntityTag(etagSource);
	ResponseBuilder berg = null;
	if (request != null) {
		berg = request.evaluatePreconditions(etag);
	}
	if (berg == null) {
		// System.out.println("TEMP DEBUG creating a new builder");
		berg = Response.ok();
		if (includeEtag) {
			berg.tag(etag);
		}
		berg.type(MediaType.APPLICATION_JSON_TYPE);
		berg.entity(jsonEntity);
		berg.lastModified(lastMod);
		CacheControl cc = new CacheControl();
		cc.setMustRevalidate(true);
		cc.setPrivate(true);
		cc.setMaxAge(86400);
		cc.setNoTransform(true);
		berg.cacheControl(cc);
	}
	return berg;
}
 
Example 10
Source Project: localization_nifi   File: RuleResource.java    License: Apache License 2.0 5 votes vote down vote up
private ResponseBuilder noCache(ResponseBuilder response) {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(true);
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);
    return response.cacheControl(cacheControl);
}
 
Example 11
/**
 * Edit the response headers to indicating no caching.
 *
 * @param response response
 * @return builder
 */
protected ResponseBuilder noCache(final ResponseBuilder response) {
    final CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(true);
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);
    return response.cacheControl(cacheControl);
}
 
Example 12
Source Project: hbase   File: VersionResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build a response for a version request.
 * @param context servlet context
 * @param uriInfo (JAX-RS context variable) request URL
 * @return a response for a version request
 */
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context ServletContext context,
    final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  ResponseBuilder response = Response.ok(new VersionModel(context));
  response.cacheControl(cacheControl);
  servlet.getMetrics().incrementSucessfulGetRequests(1);
  return response.build();
}
 
Example 13
Source Project: hbase   File: ScannerInstanceResource.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Produces(MIMETYPE_BINARY)
public Response getBinary(final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath() + " as " +
      MIMETYPE_BINARY);
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    Cell value = generator.next();
    if (value == null) {
      if (LOG.isTraceEnabled()) {
        LOG.trace("generator exhausted");
      }
      return Response.noContent().build();
    }
    ResponseBuilder response = Response.ok(CellUtil.cloneValue(value));
    response.cacheControl(cacheControl);
    response.header("X-Row", Bytes.toString(Base64.getEncoder().encode(
        CellUtil.cloneRow(value))));
    response.header("X-Column", Bytes.toString(Base64.getEncoder().encode(
        CellUtil.makeColumn(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value)))));
    response.header("X-Timestamp", value.getTimestamp());
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (IllegalStateException e) {
    if (ScannerResource.delete(id)) {
      servlet.getMetrics().incrementSucessfulDeleteRequests(1);
    } else {
      servlet.getMetrics().incrementFailedDeleteRequests(1);
    }
    servlet.getMetrics().incrementFailedGetRequests(1);
    return Response.status(Response.Status.GONE)
      .type(MIMETYPE_TEXT).entity("Gone" + CRLF)
      .build();
  }
}
 
Example 14
Source Project: oxAuth   File: TokenRestWebServiceImpl.java    License: MIT License 5 votes vote down vote up
private Response response(ResponseBuilder builder, OAuth2AuditLog oAuth2AuditLog) {
    builder.cacheControl(ServerUtil.cacheControl(true, false));
    builder.header("Pragma", "no-cache");

    applicationAuditLogger.sendMessage(oAuth2AuditLog);

    return builder.build();
}
 
Example 15
Source Project: nifi   File: RuleResource.java    License: Apache License 2.0 5 votes vote down vote up
private ResponseBuilder noCache(ResponseBuilder response) {
    CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(true);
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);
    return response.cacheControl(cacheControl);
}
 
Example 16
Source Project: nifi   File: ApplicationResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Edit the response headers to indicating no caching.
 *
 * @param response response
 * @return builder
 */
protected ResponseBuilder noCache(final ResponseBuilder response) {
    final CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(true);
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);
    return response.cacheControl(cacheControl);
}
 
Example 17
private ResponseBuilder getBuilder(final String jsonEntity, final Date lastMod, final boolean includeEtag, final Request request) {
	String etagSource = DominoUtils.md5(jsonEntity);
	EntityTag etag = new EntityTag(etagSource);
	ResponseBuilder berg = null;
	if (request != null) {
		berg = request.evaluatePreconditions(etag);
	}

	if (berg == null) {
		berg = Response.ok();
		if (includeEtag) {
			berg.tag(etag);
		}
		berg.type(MediaType.APPLICATION_JSON_TYPE).entity(jsonEntity);
		berg.lastModified(lastMod);
		CacheControl cc = new CacheControl();
		cc.setMustRevalidate(true);
		cc.setPrivate(true);
		cc.setMaxAge(86400);
		cc.setNoTransform(true);
		berg.cacheControl(cc);
	} else {
		// System.out.println("TEMP DEBUG got a hit for etag " +
		// etagSource);
	}
	return berg;
}
 
Example 18
private ResponseBuilder getBuilder(String jsonEntity, Date lastMod, boolean includeEtag, Request request) {
	String etagSource = DominoUtils.md5(jsonEntity);
	EntityTag etag = new EntityTag(etagSource);
	ResponseBuilder berg = null;
	if (request != null) {
		berg = request.evaluatePreconditions(etag);
	}
	if (berg == null) {
		// System.out.println("TEMP DEBUG creating a new builder");
		berg = Response.ok();
		if (includeEtag) {
			berg.tag(etag);
		}
		berg.type(MediaType.APPLICATION_JSON_TYPE);
		berg.entity(jsonEntity);
		if (lastMod != null) {
			berg.lastModified(lastMod);
		}
		CacheControl cc = new CacheControl();
		cc.setMustRevalidate(true);
		cc.setPrivate(true);
		cc.setMaxAge(86400);
		cc.setNoTransform(true);
		berg.cacheControl(cc);
	}
	return berg;
}
 
Example 19
Source Project: commafeed   File: FeedREST.java    License: Apache License 2.0 5 votes vote down vote up
@GET
@Path("/favicon/{id}")
@UnitOfWork
@ApiOperation(value = "Fetch a feed's icon", notes = "Fetch a feed's icon")
@Timed
public Response getFeedFavicon(@ApiParam(hidden = true) @SecurityCheck User user,
		@ApiParam(value = "subscription id", required = true) @PathParam("id") Long id) {

	Preconditions.checkNotNull(id);
	FeedSubscription subscription = feedSubscriptionDAO.findById(user, id);
	if (subscription == null) {
		return Response.status(Status.NOT_FOUND).build();
	}
	Feed feed = subscription.getFeed();
	Favicon icon = feedService.fetchFavicon(feed);

	ResponseBuilder builder = Response.ok(icon.getIcon(), Optional.ofNullable(icon.getMediaType()).orElse("image/x-icon"));

	CacheControl cacheControl = new CacheControl();
	cacheControl.setMaxAge(2592000);
	cacheControl.setPrivate(false);
	builder.cacheControl(cacheControl);

	Calendar calendar = Calendar.getInstance();
	calendar.add(Calendar.MONTH, 1);
	builder.expires(calendar.getTime());
	builder.lastModified(CommaFeedApplication.STARTUP_TIME);

	return builder.build();
}
 
Example 20
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    ClusterMetrics status = servlet.getAdmin().getClusterMetrics(
      EnumSet.of(Option.LIVE_SERVERS, Option.DEAD_SERVERS));
    StorageClusterStatusModel model = new StorageClusterStatusModel();
    model.setRegions(status.getRegionCount());
    model.setRequests(status.getRequestCount());
    model.setAverageLoad(status.getAverageLoad());
    for (Map.Entry<ServerName, ServerMetrics> entry: status.getLiveServerMetrics().entrySet()) {
      ServerName sn = entry.getKey();
      ServerMetrics load = entry.getValue();
      StorageClusterStatusModel.Node node =
        model.addLiveNode(
          sn.getHostname() + ":" +
          Integer.toString(sn.getPort()),
          sn.getStartcode(), (int) load.getUsedHeapSize().get(Size.Unit.MEGABYTE),
          (int) load.getMaxHeapSize().get(Size.Unit.MEGABYTE));
      node.setRequests(load.getRequestCount());
      for (RegionMetrics region: load.getRegionMetrics().values()) {
        node.addRegion(region.getRegionName(), region.getStoreCount(),
          region.getStoreFileCount(),
          (int) region.getStoreFileSize().get(Size.Unit.MEGABYTE),
          (int) region.getMemStoreSize().get(Size.Unit.MEGABYTE),
          (long) region.getStoreFileIndexSize().get(Size.Unit.KILOBYTE),
          region.getReadRequestCount(),
          region.getCpRequestCount(),
          region.getWriteRequestCount(),
          (int) region.getStoreFileRootLevelIndexSize().get(Size.Unit.KILOBYTE),
          (int) region.getStoreFileUncompressedDataIndexSize().get(Size.Unit.KILOBYTE),
          (int) region.getBloomFilterSize().get(Size.Unit.KILOBYTE),
          region.getCompactingCellCount(),
          region.getCompactedCellCount());
      }
    }
    for (ServerName name: status.getDeadServerNames()) {
      model.addDeadNode(name.toString());
    }
    ResponseBuilder response = Response.ok(model);
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (IOException e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  }
}