當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityTag類代碼示例

本文整理匯總了Java中javax.ws.rs.core.EntityTag的典型用法代碼示例。如果您正苦於以下問題:Java EntityTag類的具體用法?Java EntityTag怎麽用?Java EntityTag使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EntityTag類屬於javax.ws.rs.core包,在下文中一共展示了EntityTag類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cacheAwareResponse

import javax.ws.rs.core.EntityTag; //導入依賴的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

示例2: show

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@GET
@Path("{derivate}{path: (/[^?#]*)?}")
public Response show(@Context HttpServletRequest request, @Context Request jaxReq,
    @Context ServletContext context, @Context ServletConfig config) throws Exception {
    MCRContent content = getContent(request);
    String contentETag = content.getETag();
    Response.ResponseBuilder responseBuilder = null;
    EntityTag eTag = contentETag == null ? null : new EntityTag(contentETag);
    if (eTag != null) {
        responseBuilder = jaxReq.evaluatePreconditions(eTag);
    }
    if (responseBuilder == null) {
        responseBuilder = Response.ok(content.asByteArray(), MediaType.valueOf(content.getMimeType()));
    }
    if (eTag != null) {
        responseBuilder.tag(eTag);
    }
    if (content.isUsingSession()) {
        CacheControl cc = new CacheControl();
        cc.setPrivate(true);
        cc.setMaxAge(0);
        cc.setMustRevalidate(true);
        responseBuilder.cacheControl(cc);
    }
    return responseBuilder.build();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MCRViewerResource.java

示例3: get

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@GET
public Response get(@HeaderParam(HttpHeaders.IF_NONE_MATCH) String ifNoneMatch,
                    @HeaderParam(HttpHeaders.IF_MODIFIED_SINCE) Date ifModifiedSince) {
    // Check the ETags to see if the resource has changed...
    if (ifNoneMatch != null) {
        for (String eTag : ETAG_SPLITTER.split(ifNoneMatch)) {
            if ("*".equals(eTag) || ETAG.equals(EntityTag.valueOf(eTag))) {
                return NOT_MODIFIED;
            }
        }
    }

    // Check the last modification time
    if (ifModifiedSince != null && ifModifiedSince.after(LAST_MODIFIED)) {
        return NOT_MODIFIED;
    }

    return Response.ok().lastModified(LAST_MODIFIED).tag(ETAG).type(CONTENT_TYPE).entity(FAVICON).build();
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:20,代碼來源:FaviconResource.java

示例4: filter

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {

    final EntityTag entityTag = getEntityTag(responseContext);
    final Date lastModified = getLastModified(responseContext);

    responseContext.getHeaders().putSingle(HttpHeaders.CACHE_CONTROL, cacheControl);
    writeHeader(responseContext, HttpHeaders.ETAG, entityTag);
    writeHeader(responseContext, HttpHeaders.LAST_MODIFIED, lastModified == null ? null : HttpUtils.getHttpDateFormat().format(lastModified));

    final Response.ResponseBuilder builder = evaluatePreconditions(requestContext, entityTag, lastModified);
    if (builder != null) {
        responseContext.setStatusInfo(Response.Status.NO_CONTENT);
        responseContext.setEntity(null);
    }
}
 
開發者ID:Microbule,項目名稱:microbule,代碼行數:17,代碼來源:ContainerCacheFilter.java

示例5: testCustomerResource

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@Test
public void testCustomerResource() throws Exception
{
   WebTarget customerTarget = client.target("http://localhost:8080/services/customers/1");
   Response response = customerTarget.request().get();
   Assert.assertEquals(200, response.getStatus());
   Customer cust = response.readEntity(Customer.class);

   EntityTag etag = response.getEntityTag();
   response.close();

   System.out.println("Doing a conditional GET with ETag: " + etag.toString());
   response = customerTarget.request()
                            .header("If-None-Match", etag).get();
   Assert.assertEquals(304, response.getStatus());
   response.close();

   // Update and send a bad etag with conditional PUT
   cust.setCity("Bedford");
   response = customerTarget.request()
           .header("If-Match", "JUNK")
           .put(Entity.xml(cust));
   Assert.assertEquals(412, response.getStatus());
   response.close();
}
 
開發者ID:resteasy,項目名稱:resteasy-examples,代碼行數:26,代碼來源:CustomerResourceTest.java

示例6: getJSON

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON(@Context Request request) {
  EntityTag etag = new EntityTag(data().getVersioned().getUniqueId().toString());
  ResponseBuilder builder = request.evaluatePreconditions(etag);
  if (builder != null) {
    return builder.build();
  }
  RegionSearchRequest search = new RegionSearchRequest();
  search.setPagingRequest(PagingRequest.ALL);  // may need to add paging
  search.setChildrenOfId(data().getVersioned().getUniqueId());
  RegionSearchResult children = data().getRegionMaster().search(search);
  data().setRegionChildren(children.getDocuments());

  for (UniqueId parentId : data().getRegion().getRegion().getParentRegionIds()) {
    RegionDocument parent = data().getRegionMaster().get(parentId);
    data().getRegionParents().add(parent);
  }
  
  FlexiBean out = createRootData();
  String json = getFreemarker().build(JSON_DIR + "region.ftl", out);
  return Response.ok(json).tag(etag).build();
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:24,代碼來源:WebRegionVersionResource.java

示例7: getJSON

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON(@Context final Request request) {
  final EntityTag etag = new EntityTag(data().getConfig().getUniqueId().toString());
  final ResponseBuilder builder = request.evaluatePreconditions(etag);
  if (builder != null) {
    return builder.build();
  }
  final FlexiBean out = createRootData();
  final ConfigDocument doc = data().getConfig();
  final String jsonConfig = StringUtils.stripToNull(toJSON(doc.getConfig().getValue(), doc.getType()));
  if (jsonConfig != null) {
    out.put("configJSON", jsonConfig);
  }
  out.put(CONFIG_XML, StringEscapeUtils.escapeJava(createBeanXML(doc.getConfig().getValue())));
  out.put("type", doc.getType().getSimpleName());
  final String json = getFreemarker().build(JSON_DIR + "config.ftl", out);
  return Response.ok(json).tag(etag).build();
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:20,代碼來源:WebConfigResource.java

示例8: getJSON

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getJSON(@Context Request request) {
  EntityTag etag = new EntityTag(data().getVersioned().getUniqueId().toString());
  ResponseBuilder builder = request.evaluatePreconditions(etag);
  if (builder != null) {
    return builder.build();
  }
  FlexiBean out = createRootData();
  ConfigDocument doc = data().getVersioned();
  String jsonConfig = toJSON(doc.getConfig().getValue());
  if (jsonConfig != null) {
    out.put("configJSON", jsonConfig);
  } else {
    out.put(CONFIG_XML, StringEscapeUtils.escapeJavaScript(createBeanXML(doc.getConfig().getValue())));
  }
  out.put("type", data().getTypeMap().inverse().get(doc.getType()));
  String json = getFreemarker().build(JSON_DIR + "config.ftl", out);
  return Response.ok(json).tag(etag).build();
}
 
開發者ID:DevStreet,項目名稱:FinanceAnalytics,代碼行數:21,代碼來源:WebConfigVersionResource.java

示例9: shouldGetStatusResponseEtag

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@Test
public void shouldGetStatusResponseEtag() {
    ZonedDateTime now = ZonedDateTime.now();
    doReturn(Optional.of(Job.Builder.build(job -> {
        job.setId("123");
        job.setStatus(JobStatus.EXECUTING);
        job.setStatusTimestamp(Date.from(now.toInstant()));
    }))).when(mockJobManager).getJob("123");

    EntityTag entityTag = EntityTagGenerator.entityTagFromLong(now.toInstant().toEpochMilli());

            doReturn(Response.notModified(entityTag)).when(mockRequest).evaluatePreconditions(any(EntityTag.class));
    Response response = statusResource.getStatus("123");
    assertThat(response.getStatus()).isEqualTo(304);
    assertThat(response.getEntity()).isNull();
    assertThat(response.getEntityTag()).isEqualToComparingFieldByField(entityTag);
}
 
開發者ID:projectomakase,項目名稱:omakase,代碼行數:18,代碼來源:StatusResourceTest.java

示例10: testPatchEtagUpdated

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@Test
public void testPatchEtagUpdated() throws Exception {
    // Create object
    final FcrepoResponse createResp = create();
    final EntityTag createdEtag = EntityTag.valueOf(createResp.getHeaderValue(ETAG));

    final InputStream body = new ByteArrayInputStream(sparqlUpdate.getBytes());

    // Update triples with sparql update
    final FcrepoResponse response = client.patch(url)
            .body(body)
            .ifMatch("\"" + createdEtag.getValue() + "\"")
            .perform();

    final EntityTag updateEtag = EntityTag.valueOf(response.getHeaderValue(ETAG));

    assertEquals(NO_CONTENT.getStatusCode(), response.getStatusCode());
    assertNotEquals("Etag did not change after patch", createdEtag, updateEtag);
}
 
開發者ID:fcrepo4-exts,項目名稱:fcrepo-java-client,代碼行數:20,代碼來源:FcrepoClientIT.java

示例11: put

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@Override
   public Response put(Model model)
   {
Model existing = getGraphStore().getModel(getURI().toString());

if (!existing.isEmpty()) // remove existing representation
{
    EntityTag entityTag = new EntityTag(Long.toHexString(ModelUtils.hashModel(model)));
    ResponseBuilder rb = getRequest().evaluatePreconditions(entityTag);
    if (rb != null)
    {
	if (log.isDebugEnabled()) log.debug("PUT preconditions were not met for resource: {} with entity tag: {}", this, entityTag);
	return rb.build();
    }
       }
       
       if (log.isDebugEnabled()) log.debug("PUT GRAPH {} to GraphStore {}", getURI(), getGraphStore());
       getGraphStore().put(model, Boolean.FALSE, getURI());
       
if (existing.isEmpty()) return Response.created(getURI()).build();        
       else return Response.ok(model).build();
   }
 
開發者ID:AtomGraph,項目名稱:Processor,代碼行數:23,代碼來源:Item.java

示例12: method

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
@javax.ws.rs.GET public Response method() {
    Response.ResponseBuilder responseBuilder = Response.ok();
    responseBuilder.header("X-Test", "Hello");
    responseBuilder.cacheControl(CacheControl.valueOf(""));
    responseBuilder.contentLocation(URI.create(""));
    responseBuilder.cookie();
    responseBuilder.entity(12d);
    responseBuilder.expires(new Date());
    responseBuilder.language(Locale.ENGLISH);
    responseBuilder.encoding("UTF-8");
    responseBuilder.lastModified(new Date());
    responseBuilder.link(URI.create(""), "rel");
    responseBuilder.location(URI.create(""));
    responseBuilder.status(433);
    responseBuilder.tag(new EntityTag(""));
    responseBuilder.type(MediaType.APPLICATION_JSON_TYPE);
    responseBuilder.variants(new LinkedList<>());

    return responseBuilder.build();
}
 
開發者ID:sdaschner,項目名稱:jaxrs-analyzer,代碼行數:21,代碼來源:TestClass22.java

示例13: testIfNoneMatch

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
/**
 * if-none-matchヘッダで転送量削減
 * 
 * @throws Exception
 */
@Test
public void testIfNoneMatch() throws Exception {

    //ハッシュファイルはGradleタスクで書き出すのでIDEでテスト実行
    //するとハッシュファイルが出來なくてアレなのでassume使っとく
    URL resource = getClass().getResource("/static/hello.txt.md5");
    Assume.assumeThat(resource, is(not(nullValue())));

    Response response = target("static/hello.txt").request().get();
    assertThat("Status code", response.getStatusInfo(), is(Status.OK));

    EntityTag eTag = response.getEntityTag();
    assertThat("ETag", eTag, is(not(nullValue())));

    Response response2 = target("static/hello.txt").request()
            .header(HttpHeaders.IF_NONE_MATCH, eTag).get();
    assertThat("Status code", response2.getStatusInfo(),
            is(Status.NOT_MODIFIED));

    assertThat("Count", counter.getCount(), is(2));
}
 
開發者ID:backpaper0,項目名稱:jaxrs-static-resource-sample,代碼行數:27,代碼來源:StaticResourcesTest.java

示例14: filterListEntityTest

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
/** Check if ETag is generated for a list of JSON */
@Test
public void filterListEntityTest() throws Exception {

  final ContainerResponse response =
      resourceLauncher.service(
          HttpMethod.GET, SERVICE_PATH + "/list", BASE_URI, null, null, null);
  assertEquals(response.getStatus(), OK.getStatusCode());
  // check entity
  Assert.assertEquals(response.getEntity(), Arrays.asList("a", "b", "c"));
  // Check etag
  List<Object> headerTags = response.getHttpHeaders().get("ETag");
  Assert.assertNotNull(headerTags);
  Assert.assertEquals(headerTags.size(), 1);
  Assert.assertEquals(headerTags.get(0), new EntityTag("900150983cd24fb0d6963f7d28e17f72"));
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:17,代碼來源:ETagResponseFilterTest.java

示例15: useExistingHeaders

import javax.ws.rs.core.EntityTag; //導入依賴的package包/類
/** Check if ETag is added in response if we're also using a custom header */
@Test
public void useExistingHeaders() throws Exception {

  final ContainerResponse response =
      resourceLauncher.service(
          HttpMethod.GET, SERVICE_PATH + "/modify", BASE_URI, null, null, null);
  assertEquals(response.getStatus(), OK.getStatusCode());
  // check entity
  Assert.assertEquals(response.getEntity(), "helloContent");

  // headers = 2
  Assert.assertEquals(response.getHttpHeaders().keySet().size(), 3);

  // Check custom header
  List<Object> customTags = response.getHttpHeaders().get(HttpHeaders.CONTENT_DISPOSITION);
  Assert.assertNotNull(customTags);
  Assert.assertEquals(customTags.size(), 1);
  Assert.assertEquals(customTags.get(0), "attachment; filename=my.json");

  // Check etag
  List<Object> headerTags = response.getHttpHeaders().get("ETag");
  Assert.assertNotNull(headerTags);
  Assert.assertEquals(headerTags.get(0), new EntityTag("77e671575d94cfd400ed26c5ef08e0fd"));
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:26,代碼來源:ETagResponseFilterTest.java


注:本文中的javax.ws.rs.core.EntityTag類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。