本文整理汇总了Java中javax.ws.rs.core.Request.evaluatePreconditions方法的典型用法代码示例。如果您正苦于以下问题:Java Request.evaluatePreconditions方法的具体用法?Java Request.evaluatePreconditions怎么用?Java Request.evaluatePreconditions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Request
的用法示例。
在下文中一共展示了Request.evaluatePreconditions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTranslations
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
/**
* Returns Translations of a given {@link Locale}
* @param locale to get the Translation of
* @param request The HTTP-Request - is injected automatically
* @return the translation
*/
@GET
public Response getTranslations(@PathParam("locale") final String locale,
@Context final Request request) {
final Translator translator = TranslatorManager.getTranslator(LocaleUtil.toLocale(locale));
if(translator == null) {
throw new NotFoundException();
}
final File file = translator.getFile();
final Date lastModified = new Date(file.lastModified());
ResponseBuilder respBuilder = request.evaluatePreconditions(lastModified);
if(respBuilder == null) {
respBuilder = Response.ok();
}
return respBuilder.lastModified(lastModified).entity(new StreamingOutput() {
@Override
public void write(final OutputStream output) throws IOException, WebApplicationException {
IOUtils.copy(new FileInputStream(file), output);
}
}).build();
}
示例2: cacheAwareResponse
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
private Response cacheAwareResponse(
Request request, String entity, EntityTag etag, Date lastModified, int maxAge
) {
final Response.ResponseBuilder builderLastMod = request.evaluatePreconditions(lastModified);
if (builderLastMod != null) {
return builderLastMod.build();
}
final Response.ResponseBuilder builderEtag = request.evaluatePreconditions(etag);
if (builderEtag != null) {
return builderEtag.build();
}
final CacheControl cc = new CacheControl();
cc.setMaxAge(maxAge);
return Response.ok(entity)
.tag(etag)
.lastModified(lastModified)
.cacheControl(cc)
.build();
}
示例3: build
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
/**
* Build a response given a concrete request. If the request contain an <code>if-modified-since</code> or
* <code>if-none-match</code> header this will be checked against the entity given to the builder returning
* a response with status not modified if appropriate.
*/
public Response build(Request req) {
EntityTag eTag = new EntityTag(Integer.toString(entity.hashCode()));
Date lastModified = entity instanceof AbstractAuditable ? ((AbstractAuditable) entity).getLastModifiedTime() : Date.from(Instant.now());
Response.ResponseBuilder notModifiedBuilder = req.evaluatePreconditions(lastModified, eTag);
if (notModifiedBuilder != null) {
return notModifiedBuilder.build();
}
Map<String, String> parameters = new ConcurrentHashMap<>();
if (name != null) {
parameters.put("concept", name);
}
if (version != null) {
parameters.put("v", version);
}
MediaType type = getMediaType(parameters, supportsContentTypeParameter);
Response.ResponseBuilder b = Response.ok(mapper.apply(entity))
.type(type)
.tag(eTag)
.lastModified(lastModified);
if (maxAge != null) {
CacheControl cc = new CacheControl();
cc.setMaxAge(maxAge);
b.cacheControl(cc).expires(Date.from(Instant.now().plusSeconds(maxAge)));
}
return b.build();
}
示例4: evaluateRequestPreconditions
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
private Optional<Response> evaluateRequestPreconditions(File file, Request request) {
ResponseBuilder notModifiedResponseBuilder = request.evaluatePreconditions(new Date(file.lastModified()));
return Optional.ofNullable(notModifiedResponseBuilder).map(ResponseBuilder::build);
}
示例5: evaluateETagPrecondition
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
private Optional<Response> evaluateETagPrecondition(Request request, EntityTag currentETag) {
ResponseBuilder notModifiedResponseBuilder = request.evaluatePreconditions(currentETag);
return Optional.ofNullable(notModifiedResponseBuilder).map(ResponseBuilder::build);
}
示例6: checkCache
import javax.ws.rs.core.Request; //导入方法依赖的package包/类
/**
* Check the request for a cache-related response.
*
* @param request the request
* @param modified the modified time
* @param etag the etag
* @throws WebApplicationException either a 412 Precondition Failed or a 304 Not Modified, depending on the context.
*/
protected static void checkCache(final Request request, final Instant modified, final EntityTag etag) {
final ResponseBuilder builder = request.evaluatePreconditions(from(modified), etag);
if (nonNull(builder)) {
throw new WebApplicationException(builder.build());
}
}