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

The following examples show how to use javax.ws.rs.core.Response.ResponseBuilder#lastModified() . 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 File: SearchResource.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
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 2
Source File: TermsResource.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
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 3
Source File: FramedResource.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
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 4
Source File: GetHandler.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Get the standard headers.
 * @param builder the response builder
 * @return the response builder
 */
public ResponseBuilder standardHeaders(final ResponseBuilder builder) {

    // Standard HTTP Headers
    builder.lastModified(from(getResource().getModified()));

    if (syntax != null) {
        builder.type(syntax.mediaType());
    }

    final IRI model;
    if (getRequest().getExt() == null || DESCRIPTION.equals(getRequest().getExt())) {
        model = getResource().getBinaryMetadata().isPresent() && syntax != null
            ? LDP.RDFSource : getResource().getInteractionModel();
        // Link headers from User data
        getResource().getExtraLinkRelations().collect(toMap(Map.Entry::getKey, Map.Entry::getValue))
                .forEach((key, value) -> builder.link(key, join(" ", value)));
    } else {
        model = LDP.RDFSource;
    }

    // Add LDP-required headers
    addLdpHeaders(builder, model);

    // Memento-related headers
    if (isMemento) {
        builder.header(MEMENTO_DATETIME, from(getResource().getModified()));
    }

    return builder;
}
 
Example 5
Source File: FramedCollectionResource.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
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 6
Source File: ReferenceResource.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
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 7
Source File: FeedREST.java    From commafeed with 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();
}