javax.ws.rs.core.Request.evaluatePreconditions()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中javax.ws.rs.core.Request.evaluatePreconditions方法的一些代码示例,展示了Request.evaluatePreconditions的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.evaluatePreconditions方法的具体详情如下:
包路径:javax.ws.rs.core.Request
类名称:Request
方法名:evaluatePreconditions

Request.evaluatePreconditions介绍

[英]Evaluate request preconditions for a resource that does not currently exist. The primary use of this method is to support the * If-Match: * and * If-None-Match: * preconditions.

Note that both preconditions If-None-Match: * and If-None-Match: something will always be considered to have been met and it is the applications responsibility to enforce any additional method-specific semantics. E.g. a PUT on a resource that does not exist might succeed whereas a GET on a resource that does not exist would likely result in a 404 response. It would be the responsibility of the application to generate the 404 response.
[中]评估当前不存在的资源的请求前提条件。此方法的主要用途是支持{$0$}和{$1$}先决条件。
请注意,如果没有匹配的前提条件:*和If-None-Match: something将始终被视为已满足,应用程序有责任强制执行任何其他特定于方法的语义。例如,放置不存在的资源可能会成功,而获取不存在的资源可能会导致404响应。应用程序负责生成404响应。

代码示例

代码示例来源:origin: jersey/jersey

public SparklinesResource(
    @QueryParam("d") final IntegerList data,
    @DefaultValue("0,100") @QueryParam("limits") final Interval limits,
    @Context final Request request,
    @Context final UriInfo ui) {
  if (data == null) {
    throw new WebApplicationException(400);
  }
  this.data = data;
  this.limits = limits;
  if (!limits.contains(data)) {
    throw new WebApplicationException(400);
  }
  this.tag = computeEntityTag(ui.getRequestUri());
  if ("GET".equals(request.getMethod())) {
    final Response.ResponseBuilder rb = request.evaluatePreconditions(tag);
    if (rb != null) {
      throw new WebApplicationException(rb.build());
    }
  }
}

代码示例来源:origin: Graylog2/graylog2-server

final EntityTag entityTag = new EntityTag(hashCode.toString());
final Response.ResponseBuilder response = request.evaluatePreconditions(lastModified, entityTag);
if (response != null) {
  return response.build();

代码示例来源:origin: soabase/exhibitor

EntityTag   tag = new EntityTag(Hashing.sha1().hashString(json, Charsets.UTF_8).toString());
Response.ResponseBuilder    builder = request.evaluatePreconditions(tag);
if ( builder == null )

代码示例来源:origin: stackoverflow.com

Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(
    updateTimestamp,
    etag

代码示例来源:origin: resteasy/Resteasy

Response.ResponseBuilder builder = validation.evaluatePreconditions(new EntityTag(entry.getEtag()));
CacheControl cc = new CacheControl();
cc.setMaxAge(entry.getExpirationInSeconds());

代码示例来源:origin: resteasy/Resteasy

Response.ResponseBuilder validatedResponse = validation.evaluatePreconditions(new EntityTag(etag));
if (validatedResponse != null)

代码示例来源:origin: org.mycore/mycore-restapi

static Optional<Response> getCachedResponse(Request request, Date lastModified, EntityTag eTag) {
    return Optional.ofNullable(request)
      .map(r -> r.evaluatePreconditions(lastModified, eTag))
      .map(Response.ResponseBuilder::build);
  }
}

代码示例来源:origin: org.mycore/mycore-restapi

static Optional<Response> getCachedResponse(Request request, Date lastModified) {
  return Optional.ofNullable(request)
    .map(r -> r.evaluatePreconditions(lastModified))
    .map(Response.ResponseBuilder::build);
}

代码示例来源:origin: danielolszewski/blog

@GET
@Path("/sample")
@Produces(MediaType.APPLICATION_JSON)
public Response getSample(@Context Request request) throws ParseException {
  Date lastUpdate = format.parse("2016-02-01 00:00:00.123");
  Response.ResponseBuilder responseBuilder = request.evaluatePreconditions(lastUpdate);
  if (responseBuilder == null) {
    responseBuilder = Response.ok("Significantly big payload ");
  }
  return responseBuilder.lastModified(lastUpdate).build();
}

代码示例来源:origin: apache/cxf

public ResponseBuilder evaluatePreconditions() {
    return get().evaluatePreconditions();
  }
}

代码示例来源:origin: apache/cxf

public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
  return get().evaluatePreconditions(lastModified, eTag);
}

代码示例来源:origin: org.apache.tomee/openejb-core

public ResponseBuilder evaluatePreconditions(final Date lastModified) {
  return get().evaluatePreconditions(lastModified);
}

代码示例来源:origin: apache/cxf

public ResponseBuilder evaluatePreconditions(Date lastModified) {
  return get().evaluatePreconditions(lastModified);
}

代码示例来源:origin: apache/cxf

public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
  return get().evaluatePreconditions(eTag);
}

代码示例来源:origin: com.isotrol.impe3/impe3-web-online

private ResponseBuilder evaluateFilePreconditions(String id) {
  final EntityTag tag = new EntityTag(id);
  return request.evaluatePreconditions(tag);
}

代码示例来源:origin: org.apache.openejb/openejb-core

public ResponseBuilder evaluatePreconditions(final EntityTag eTag) {
  return get().evaluatePreconditions(eTag);
}

代码示例来源:origin: org.apache.openejb/openejb-core

public ResponseBuilder evaluatePreconditions(final Date lastModified, final EntityTag eTag) {
  return get().evaluatePreconditions(lastModified, eTag);
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
  return get().evaluatePreconditions(eTag);
}

代码示例来源:origin: stackoverflow.com

public class MyEntityResourceImpl implements MyEntityResource

  @Override
  public Response getMyEntity(final Request request) {

    final MyEntity myEntity = ... // load entity
    final String eTagValue = ... // calclutate value of ETag

    final EntityTag eTag = new EntityTag(eTagValue);

    ResponseBuilder responseBuilder = request.evaluatePreconditions(eTag);

    if (responseBuilder == null) {
      return Response.ok(user).tag(eTag).build();
    }

    return responseBuilder.build();
  }
}

代码示例来源:origin: org.apache.syncope.core/syncope-core-rest-cxf

protected void checkETag(final String etag) {
  Response.ResponseBuilder builder = messageContext.getRequest().evaluatePreconditions(new EntityTag(etag));
  if (builder != null) {
    SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.ConcurrentModification);
    sce.getElements().add("Mismatching ETag value");
    throw sce;
  }
}

相关文章