当前位置: 首页>>代码示例>>Java>>正文


Java Request.evaluatePreconditions方法代码示例

本文整理汇总了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();
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:31,代码来源:TranslationService.java

示例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();
}
 
开发者ID:dehora,项目名称:outland,代码行数:24,代码来源:OpenApiDiscoveryResource.java

示例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();
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:36,代码来源:EntityResponseBuilder.java

示例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);
}
 
开发者ID:andreschaffer,项目名称:http-progressive-download-examples,代码行数:5,代码来源:VideoResource.java

示例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);
}
 
开发者ID:andreschaffer,项目名称:http-caching-and-concurrency-examples,代码行数:5,代码来源:ClimateResource.java

示例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());
    }
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:15,代码来源:BaseLdpHandler.java


注:本文中的javax.ws.rs.core.Request.evaluatePreconditions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。