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

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

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

Response.notModified介绍

[英]Create a new ResponseBuilder with a not-modified status.
[中]创建状态为“未修改”的新ResponseBuilder。

代码示例

代码示例来源:origin: find-sec-bugs/find-sec-bugs

public static ResponseBuilder notModified(EntityTag tag) {
  ResponseBuilder b = notModified();
  b.tag(tag);
  return b;
}

代码示例来源:origin: find-sec-bugs/find-sec-bugs

public static ResponseBuilder notModified(String tag) {
  ResponseBuilder b = notModified();
  b.tag(tag);
  return b;
}

代码示例来源:origin: pentaho/pentaho-kettle

@POST
@Path( "/rename/{id}/{path}/{newName}/{type}/{oldName}" )
public Response rename( @PathParam( "id" ) String id, @PathParam( "path" ) String path,
            @PathParam( "newName" ) String newName, @PathParam( "type" ) String type,
            @PathParam( "oldName" ) String oldName ) {
 try {
  ObjectId objectId = repositoryBrowserController.rename( id, path, newName, type, oldName );
  if ( objectId != null ) {
   return Response.ok( objectId ).build();
  }
 } catch ( KettleObjectExistsException koee ) {
  return Response.status( Response.Status.CONFLICT ).build();
 } catch ( KettleTransException | KettleJobException ktje ) {
  return Response.status( Response.Status.NOT_ACCEPTABLE ).build();
 } catch ( KettleException ke ) {
  return Response.notModified().build();
 }
 return Response.notModified().build();
}

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

private Response.ResponseBuilder evaluateIfModifiedSince(final long lastModified, final String ifModifiedSinceHeader) {
  try {
    final long ifModifiedSince = HttpHeaderReader.readDate(ifModifiedSinceHeader).getTime();
    if (roundDown(lastModified) <= ifModifiedSince) {
      // 304 Not modified
      return Response.notModified();
    }
  } catch (final ParseException ex) {
    // Ignore the header if parsing error
  }
  return null;
}

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

private Response.ResponseBuilder evaluateIfModifiedSince(final long lastModified, final String ifModifiedSinceHeader) {
  try {
    final long ifModifiedSince = HttpHeaderReader.readDate(ifModifiedSinceHeader).getTime();
    if (roundDown(lastModified) <= ifModifiedSince) {
      // 304 Not modified
      return Response.notModified();
    }
  } catch (final ParseException ex) {
    // Ignore the header if parsing error
  }
  return null;
}

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

private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags,
                           final boolean isGetOrHead) {
  if (isGetOrHead) {
    if (matchingTags == MatchingEntityTag.ANY_MATCH) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
    // The weak comparison function may be used to compare entity tags
    if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
  } else {
    // The strong comparison function must be used to compare the entity
    // tags. Thus if the entity tag of the entity is weak then matching
    // of entity tags in the If-None-Match header should fail if the
    // HTTP method is not GET or not HEAD.
    if (eTag.isWeak()) {
      return null;
    }
    if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) {
      // 412 Precondition Failed
      return Response.status(Response.Status.PRECONDITION_FAILED);
    }
  }
  return null;
}

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

@DELETE
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.COLLECTORS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete a collector")
@AuditEvent(type = SidecarAuditEventTypes.COLLECTOR_DELETE)
public Response deleteCollector(@ApiParam(name = "id", required = true)
                @PathParam("id") String id) {
  final long configurationsForCollector = configurationService.all().stream()
      .filter(configuration -> configuration.collectorId().equals(id))
      .count();
  if (configurationsForCollector > 0) {
    throw new BadRequestException("Collector still in use, cannot delete.");
  }
  int deleted = collectorService.delete(id);
  if (deleted == 0) {
    return Response.notModified().build();
  }
  etagService.invalidateAll();
  return Response.accepted().build();
}

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

private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags,
                           final boolean isGetOrHead) {
  if (isGetOrHead) {
    if (matchingTags == MatchingEntityTag.ANY_MATCH) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
    // The weak comparison function may be used to compare entity tags
    if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
  } else {
    // The strong comparison function must be used to compare the entity
    // tags. Thus if the entity tag of the entity is weak then matching
    // of entity tags in the If-None-Match header should fail if the
    // HTTP method is not GET or not HEAD.
    if (eTag.isWeak()) {
      return null;
    }
    if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) {
      // 412 Precondition Failed
      return Response.status(Response.Status.PRECONDITION_FAILED);
    }
  }
  return null;
}

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

@DELETE
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_DELETE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete a configuration")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_DELETE)
public Response deleteConfiguration(@ApiParam(name = "id", required = true)
                  @PathParam("id") String id) {
  if (isConfigurationInUse(id)) {
    throw new BadRequestException("Configuration still in use, cannot delete.");
  }
  int deleted = configurationService.delete(id);
  if (deleted == 0) {
    return Response.notModified().build();
  }
  etagService.invalidateAll();
  return Response.accepted().build();
}

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

@DELETE
@Path("/{id}")
@RequiresPermissions(SidecarRestPermissions.CONFIGURATIONS_UPDATE)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Delete a configuration variable")
@AuditEvent(type = SidecarAuditEventTypes.CONFIGURATION_VARIABLE_DELETE)
public Response deleteConfigurationVariable(@ApiParam(name = "id", required = true)
                        @PathParam("id") String id) {
  final ConfigurationVariable configurationVariable = findVariableOrFail(id);
  final List<Configuration> configurations = this.configurationService.findByConfigurationVariable(configurationVariable);
  if (!configurations.isEmpty()) {
    final ValidationResult validationResult = new ValidationResult();
    validationResult.addError("name", "Variable is still used in the following configurations: " +
        configurations.stream().map(c -> c.name()).collect(Collectors.joining(", ")));
    return Response.status(Response.Status.BAD_REQUEST).entity(validationResult).build();
  }
  int deleted = configurationVariableService.delete(id);
  if (deleted == 0) {
    return Response.notModified().build();
  }
  etagService.invalidateAll();
  return Response.accepted().build();
}

代码示例来源:origin: com.sun.jersey/jersey-server

private ResponseBuilder evaluateIfNoneMatch(
    EntityTag eTag,
    Set<MatchingEntityTag> matchingTags,
    boolean isGetOrHead) {
  if (isGetOrHead) {
    if (matchingTags == MatchingEntityTag.ANY_MATCH) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
    // The weak comparison function may be used to compare entity tags
    if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
  } else {
    // The strong comparison function must be used to compare the entity
    // tags. Thus if the entity tag of the entity is weak then matching
    // of entity tags in the If-None-Match header should fail if the
    // HTTP method is not GET or not HEAD.
    if (eTag.isWeak()) {
      return null;
    }
    if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) {
      // 412 Precondition Failed
      return Responses.preconditionFailed();
    }
  }
  return null;
}

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

if (etagService.isPresent(etag.toString())) {
  etagCached = true;
  builder = Response.notModified();
  builder.tag(etag);

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

if (etagService.isPresent(etag.toString())) {
  etagCached = true;
  builder = Response.notModified();
  builder.tag(etag);

代码示例来源:origin: apache/incubator-druid

queryLifecycle.emitLogsAndMetrics(null, req.getRemoteAddr(), -1);
successfulQueryCount.incrementAndGet();
return Response.notModified().build();

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

public Response.ResponseBuilder ifModifiedSince(String strDate, Date lastModified)
{
 Date date = DateUtil.parseDate(strDate);
 if (date.getTime() >= lastModified.getTime())
 {
   return Response.notModified();
 }
 return null;
}

代码示例来源:origin: org.glassfish.jersey.core/jersey-server

private Response.ResponseBuilder evaluateIfModifiedSince(final long lastModified, final String ifModifiedSinceHeader) {
  try {
    final long ifModifiedSince = HttpHeaderReader.readDate(ifModifiedSinceHeader).getTime();
    if (roundDown(lastModified) <= ifModifiedSince) {
      // 304 Not modified
      return Response.notModified();
    }
  } catch (final ParseException ex) {
    // Ignore the header if parsing error
  }
  return null;
}

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

public Response.ResponseBuilder ifNoneMatch(List<EntityTag> ifMatch, EntityTag eTag)
{
 boolean match = false;
 for (EntityTag tag : ifMatch)
 {
   if (tag.equals(eTag) || tag.getValue().equals("*"))
   {
    match = true;
    break;
   }
 }
 if (match)
 {
   if ("GET".equals(httpMethod) || "HEAD".equals(httpMethod))
   {
    return Response.notModified(eTag);
   }
   return Response.status(SC_PRECONDITION_FAILED).tag(eTag);
 }
 return null;
}

代码示例来源:origin: org.glassfish.jersey.core/jersey-server

private Response.ResponseBuilder evaluateIfNoneMatch(final EntityTag eTag, final Set<? extends EntityTag> matchingTags,
                           final boolean isGetOrHead) {
  if (isGetOrHead) {
    if (matchingTags == MatchingEntityTag.ANY_MATCH) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
    // The weak comparison function may be used to compare entity tags
    if (matchingTags.contains(eTag) || matchingTags.contains(new EntityTag(eTag.getValue(), !eTag.isWeak()))) {
      // 304 Not modified
      return Response.notModified(eTag);
    }
  } else {
    // The strong comparison function must be used to compare the entity
    // tags. Thus if the entity tag of the entity is weak then matching
    // of entity tags in the If-None-Match header should fail if the
    // HTTP method is not GET or not HEAD.
    if (eTag.isWeak()) {
      return null;
    }
    if (matchingTags == MatchingEntityTag.ANY_MATCH || matchingTags.contains(eTag)) {
      // 412 Precondition Failed
      return Response.status(Response.Status.PRECONDITION_FAILED);
    }
  }
  return null;
}

代码示例来源:origin: Impetus/Kundera

return Response.notModified().build();

代码示例来源:origin: org.jboss.resteasy/jaxrs-api

/**
 * Create a new ResponseBuilder with a not-modified status.
 *
 * @param tag a tag for the unmodified entity.
 * @return a new response builder.
 * @throws java.lang.IllegalArgumentException
 *          if tag is {@code null}.
 */
public static ResponseBuilder notModified(EntityTag tag) {
  return notModified().tag(tag);
}

相关文章