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

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

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

Response.getLinks介绍

[英]Get the links attached to the message as headers. Any links in the message that are relative must be resolved with respect to the actual request URI that produced this response. Note that request URIs may be updated by filters, so the actual request URI may differ from that in the original invocation.
[中]获取作为标题附加到邮件的链接。消息中的任何相对链接都必须根据生成此响应的实际请求URI进行解析。请注意,请求URI可能会被过滤器更新,因此实际的请求URI可能与原始调用中的不同。

代码示例

代码示例来源:origin: SAP/cloud-s4-sdk-examples

@Override
public Set<Link> getLinks()
{
  return delegate.getLinks();
}

代码示例来源:origin: com.cerner.beadledom/beadledom-resteasy-genericresponse

@Override
public Set<Link> getLinks() {
 return rawResponse.getLinks();
}

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

public Set<Link> getLinks() {
  return r.getLinks();
}

代码示例来源:origin: trellis-ldp/trellis

protected Stream<Executable> checkLdpType(final Response res, final IRI type) {
  final Set<String> types = HttpUtils.ldpResourceTypes(type).map(IRI::getIRIString).collect(toSet());
  final Set<String> responseTypes = res.getLinks().stream().filter(link -> TYPE.equals(link.getRel()))
    .map(link -> link.getUri().toString()).collect(toSet());
  return of(LDP.Resource, LDP.RDFSource, LDP.NonRDFSource, LDP.Container, LDP.BasicContainer, LDP.DirectContainer,
      LDP.IndirectContainer).map(t -> checkLdpType(types, responseTypes, t));
}

代码示例来源:origin: trellis-ldp/trellis

private Stream<Executable> checkBinaryDescription(final Response res) {
  return Stream.of(
      () -> assertEquals(OK, res.getStatusInfo(), "Incorrect response code!"),
      () -> assertEquals(-1, res.getLength(), "Incorrect response size!"),
      () -> assertEquals(from(time), res.getLastModified(), "Incorrect modified date!"),
      () -> assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE), "Incompatible content-type!"),
      () -> assertTrue(res.getLinks().stream()
          .anyMatch(link -> link.getRel().equals("describes") &&
            !link.getUri().toString().endsWith("?ext=description")), "MIssing rel=describes header!"),
      () -> assertTrue(res.getLinks().stream()
          .anyMatch(link -> link.getRel().equals("canonical") &&
            link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!"),
      () -> assertAll("Check LDP type link headers", checkLdpType(res, LDP.RDFSource)));
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testExtraLinks() {
  final String inbox = "http://ldn.example.com/inbox";
  final String annService = "http://annotation.example.com/resource";
  when(mockResource.getExtraLinkRelations()).thenAnswer(inv -> Stream.of(
      new SimpleEntry<>(annService, OA.annotationService.getIRIString()),
      new SimpleEntry<>(SKOS.Concept.getIRIString(), "type"),
      new SimpleEntry<>(inbox, "inbox")));
  final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, false, true, true, null, baseUrl);
  final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource)))
    .toCompletableFuture().join().build();
  assertEquals(OK, res.getStatusInfo(), "Incorrect response code!");
  assertTrue(res.getLinks().stream().anyMatch(hasType(SKOS.Concept)), "Missing extra type link header!");
  assertTrue(res.getLinks().stream().anyMatch(hasLink(rdf.createIRI(inbox), "inbox")), "No ldp:inbox header!");
  assertTrue(res.getLinks().stream().anyMatch(hasLink(rdf.createIRI(annService),
          OA.annotationService.getIRIString())), "Missing extra annotationService link header!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testNoLdpRsSupport() {
  when(mockTrellisRequest.getContentType()).thenReturn(APPLICATION_SPARQL_UPDATE);
  when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
  final PatchHandler patchHandler = new PatchHandler(mockTrellisRequest, insert, mockBundler, null, null);
  final Response res = assertThrows(BadRequestException.class, () ->
      patchHandler.initialize(mockParent, mockResource),
      "No exception for an unsupported IXN model!").getResponse();
  assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!");
  assertTrue(res.getLinks().stream().anyMatch(link ->
      link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) &&
      link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing Link header with constraint!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testDeletePersistenceSupport() {
  when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
  final DeleteHandler handler = new DeleteHandler(mockTrellisRequest, mockBundler, baseUrl);
  final Response res = assertThrows(WebApplicationException.class, () ->
      handler.initialize(mockParent, mockResource)).getResponse();
  assertTrue(res.getLinks().stream().anyMatch(link ->
    link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) &&
    link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing Link headers");
  assertEquals(TEXT_PLAIN_TYPE, res.getMediaType(), "Incorrect media type");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testUnsupportedType() throws IOException {
  when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
  when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Container.getIRIString()).rel("type").build());
  final PostHandler handler = buildPostHandler("/emptyData.txt", "newresource", null);
  final Response res = assertThrows(BadRequestException.class, () ->
      handler.createResource(handler.initialize(mockParent, MISSING_RESOURCE))
      .toCompletableFuture().join(), "No exception thrown when the IXN model isn't supported!").getResponse();
  assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!");
  assertTrue(res.getLinks().stream().anyMatch(link ->
      link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) &&
      link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint Link header!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testUnsupportedType() {
  when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet());
  when(mockTrellisRequest.getContentType()).thenReturn(TEXT_TURTLE);
  when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Resource.getIRIString()).rel("type").build());
  final PutHandler handler = buildPutHandler("/simpleTriple.ttl", null);
  final Response res = assertThrows(BadRequestException.class, () ->
      handler.setResource(handler.initialize(mockParent, mockResource)).toCompletableFuture().join(),
      "No exception when the interaction model isn't supported!").getResponse();
  assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!");
  assertTrue(res.getLinks().stream().anyMatch(link ->
      link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) &&
      link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint header!");
}

代码示例来源:origin: trellis-ldp/trellis

@Test
public void testGetBinary() throws IOException {
  when(mockResource.getBinaryMetadata()).thenReturn(of(testBinary));
  when(mockResource.getInteractionModel()).thenReturn(LDP.NonRDFSource);
  when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE));
  final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, false, true, true, null, baseUrl);
  final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource)))
    .toCompletableFuture().join().build();
  assertEquals(OK, res.getStatusInfo(), "Incorrect response code!");
  assertEquals(-1, res.getLength(), "Incorrect response length!");
  assertEquals(from(time), res.getLastModified(), "Incorrect content-type header!");
  assertTrue(res.getMediaType().isCompatible(TEXT_PLAIN_TYPE), "Incorrect content-type header!");
  assertTrue(res.getLinks().stream()
      .anyMatch(link -> link.getRel().equals("describedby") &&
        link.getUri().toString().endsWith("?ext=description")), "Missing rel=describedby header!");
  assertTrue(res.getLinks().stream()
      .anyMatch(link -> link.getRel().equals("canonical") &&
        !link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!");
  assertAll("Check LDP type link headers", checkLdpType(res, LDP.NonRDFSource));
}

代码示例来源:origin: trellis-ldp/trellis

assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()), "Incompatible content-type header!");
assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE), "Incompatible content-type header!");
assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("describes")),
    "Unexpected rel=describes");
assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("describedby")),
    "Unexpected rel=describedby");
assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("canonical")),
    "Unexpected rel=canonical");
assertNull(res.getHeaderString(PREFERENCE_APPLIED), "Unexpected Preference-Applied header!");

相关文章