當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。