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


Java Link類代碼示例

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


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

示例1: filter

import javax.ws.rs.core.Link; //導入依賴的package包/類
@Override
public void filter(final ContainerRequestContext req, final ContainerResponseContext res) throws IOException {
    if (READ_METHODS.contains(req.getMethod())) {

        if (res.getLinks().stream().filter(l -> l.getRel().equals(TYPE)).map(Link::getUri).map(URI::toString)
            .anyMatch(uri -> uri.equals(Container.getIRIString()) || uri.equals(NonRDFSource.getIRIString()))) {

            final String urlBase = nonNull(baseUrl) ? baseUrl : req.getUriInfo().getBaseUri().toString();
            final String identifier = urlBase + req.getUriInfo().getPath();

            res.getHeaders().add("Link", fromUri(identifier + "?ext=" + UPLOADS)
                        .rel(multipartUploadService.getIRIString()).build());
        }

        final List<String> exts = req.getUriInfo().getQueryParameters().getOrDefault("ext", emptyList());
        if (exts.contains(UPLOADS)) {
            res.getHeaders().putSingle(ALLOW, join(",", POST, OPTIONS));
        }
    }
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:21,代碼來源:MultipartUploader.java

示例2: extractCompensator

import javax.ws.rs.core.Link; //導入依賴的package包/類
static String extractCompensator(String linkStr) {
    for (String lnk : linkStr.split(",")) {
        Link link;

        try {
            link = Link.valueOf(lnk);
        } catch (Exception e) {
            LRALogger.logger.infof(e, "Cannot extract compensator from link'%s'", linkStr);
            return linkStr;
        }

        if ("compensate".equals(link.getRel()))
            return link.getUri().toString();
    }

    return linkStr;
}
 
開發者ID:xstefank,項目名稱:lra-service,代碼行數:18,代碼來源:LRARecord.java

示例3: patchServer

import javax.ws.rs.core.Link; //導入依賴的package包/類
private ServerResponse patchServer(Server serverPatch, Link serverLink, Optional<Integer> mergeDepth) {

    final Response response = RestHelper.queryParam(client.target(serverLink), mergeDepth, "mergedepth")
      .request(MediaType.APPLICATION_JSON)
      .build("PATCH", Entity.json(serverPatch))
      .invoke();
    TestHelper.assertSuccessful(response);

    final ServerLink link = response.readEntity(ServerLink.class);
    final Document db = servers.find(
      Filters.and(
        Filters.eq("hostname", link.hostname),
        Filters.eq("environment", link.environment)
      )).first();
    return new ServerResponse(link, db);
  }
 
開發者ID:atgse,項目名稱:sam,代碼行數:17,代碼來源:ServerIntegrationTest.java

示例4: getOrder

import javax.ws.rs.core.Link; //導入依賴的package包/類
public Response getOrder(int id, UriInfo uriInfo)
{
   OrderEntity entity = em.getReference(OrderEntity.class, id);
   Order order = entity2domain(entity);
   URI self = uriInfo.getAbsolutePathBuilder().build();
   Link selfLink = Link.fromUri(self).rel("self").type("application/xml").build();
   order.addLink(selfLink);
    if (!order.isCancelled())
   {
      URI cancel = uriInfo.getAbsolutePathBuilder().path("cancel").build();
      Link cancelLink = Link.fromUri(cancel).rel("cancel").type("application/xml").build();
      order.addLink(cancelLink);
   }

   Response.ResponseBuilder builder = Response.ok(order);
   if (!order.isCancelled()) addCancelHeader(uriInfo, builder);
   return builder.build();
}
 
開發者ID:resteasy,項目名稱:resteasy-examples,代碼行數:19,代碼來源:OrderResourceBean.java

示例5: getTimeMapBuilder

import javax.ws.rs.core.Link; //導入依賴的package包/類
/**
 * Create a response builder for a TimeMap response.
 *
 * @param baseUrl the base URL
 * @param req the LDP request
 * @param serializer the serializer to use
 * @return a response builder object
 */
public Response.ResponseBuilder getTimeMapBuilder(final LdpRequest req,
        final IOService serializer, final String baseUrl) {

    final List<MediaType> acceptableTypes = req.getHeaders().getAcceptableMediaTypes();
    final String identifier = getBaseUrl(baseUrl, req) + req.getPath();
    final List<Link> links = getMementoLinks(identifier, resource.getMementos()).collect(toList());

    final Response.ResponseBuilder builder = Response.ok().link(identifier, ORIGINAL + " " + TIMEGATE);
    builder.links(links.toArray(new Link[0])).link(Resource.getIRIString(), "type")
        .link(RDFSource.getIRIString(), "type").header(ALLOW, join(",", GET, HEAD, OPTIONS));

    final RDFSyntax syntax = getSyntax(acceptableTypes, of(APPLICATION_LINK_FORMAT)).orElse(null);
    if (nonNull(syntax)) {
        final IRI profile = ofNullable(getProfile(acceptableTypes, syntax)).orElse(expanded);

        final List<Triple> extraData = getExtraTriples(identifier);
        for (final Link l : links) {
            if (l.getRels().contains(MEMENTO)) {
                extraData.add(rdf.createTriple(rdf.createIRI(identifier), Memento.memento,
                                rdf.createIRI(l.getUri().toString())));
            }
        }

        final StreamingOutput stream = new StreamingOutput() {
            @Override
            public void write(final OutputStream out) throws IOException {
                serializer.write(concat(links.stream().flatMap(linkToTriples), extraData.stream()), out, syntax,
                        profile);
            }
        };

        return builder.type(syntax.mediaType()).entity(stream);
    }

    return builder.type(APPLICATION_LINK_FORMAT)
        .entity(links.stream().map(Link::toString).collect(joining(",\n")) + "\n");
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:46,代碼來源:MementoResource.java

示例6: getTimeGateBuilder

import javax.ws.rs.core.Link; //導入依賴的package包/類
/**
 * Create a response builder for a TimeGate response.
 *
 * @param req the LDP request
 * @param baseUrl the base URL
 * @return a response builder object
 */
public Response.ResponseBuilder getTimeGateBuilder(final LdpRequest req, final String baseUrl) {
    final String identifier = getBaseUrl(baseUrl, req) + req.getPath();
    return Response.status(FOUND)
        .location(fromUri(identifier + "?version=" + req.getDatetime().getInstant().toEpochMilli()).build())
        .link(identifier, ORIGINAL + " " + TIMEGATE)
        .links(getMementoLinks(identifier, resource.getMementos()).toArray(Link[]::new))
        .header(VARY, ACCEPT_DATETIME);
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:16,代碼來源:MementoResource.java

示例7: getTimeMap

import javax.ws.rs.core.Link; //導入依賴的package包/類
private static Stream<Link> getTimeMap(final String identifier, final Stream<Range<Instant>> mementos) {
    return mementos.reduce((acc, x) -> between(acc.getMinimum(), x.getMaximum()))
        .map(x -> Link.fromUri(identifier + TIMEMAP_PARAM).rel(TIMEMAP).type(APPLICATION_LINK_FORMAT)
            .param(FROM, ofInstant(x.getMinimum().minusNanos(1L).plusSeconds(1L), UTC).format(RFC_1123_DATE_TIME))
            .param(UNTIL, ofInstant(x.getMaximum(), UTC).format(RFC_1123_DATE_TIME)).build())
        // TODO use Optional::stream with JDK9
        .map(Stream::of).orElseGet(Stream::empty);
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:9,代碼來源:MementoResource.java

示例8: checkDeleted

import javax.ws.rs.core.Link; //導入依賴的package包/類
/**
 * Check if this is a deleted resource, and if so return an appropriate response.
 *
 * @param res the resource
 * @param identifier the identifier
 * @throws WebApplicationException a 410 Gone exception
 */
protected static void checkDeleted(final Resource res, final String identifier) {
    if (res.isDeleted()) {
        throw new WebApplicationException(status(GONE)
                .links(MementoResource.getMementoLinks(identifier, res.getMementos())
                .toArray(Link[]::new)).build());
    }
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:15,代碼來源:BaseLdpHandler.java

示例9: testGetDatetime

import javax.ws.rs.core.Link; //導入依賴的package包/類
@Test
public void testGetDatetime() {
    final Response res = target(RESOURCE_PATH).request()
        .header(ACCEPT_DATETIME, RFC_1123_DATE_TIME.withZone(UTC).format(time)).get();

    assertEquals(OK, res.getStatusInfo());
    assertNotNull(res.getHeaderString(MEMENTO_DATETIME));
    assertEquals(time, parse(res.getHeaderString(MEMENTO_DATETIME), RFC_1123_DATE_TIME).toInstant());

    // Jersey's client doesn't parse complex link headers correctly
    final List<Link> links = res.getStringHeaders().get(LINK).stream().map(Link::valueOf).collect(toList());
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 2000))
                    .equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496260729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 1000))
                    .equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496261729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(time).equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496262729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("timemap") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 2000))
                    .equals(l.getParams().get("from")) &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp + 1000))
                    .equals(l.getParams().get("until")) &&
                APPLICATION_LINK_FORMAT.equals(l.getType()) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?ext=timemap")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("timegate") &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH)));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("original") &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH)));
    assertFalse(links.stream().anyMatch(hasLink(rdf.createIRI(BASE_URL + RESOURCE_PATH + "?ext=upload"),
                    Trellis.multipartUploadService.getIRIString())));
    assertTrue(links.stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(links.stream().anyMatch(hasType(LDP.RDFSource)));
    assertFalse(links.stream().anyMatch(hasType(LDP.Container)));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:40,代碼來源:AbstractLdpResourceTest.java

示例10: testGetTimeMapJsonCompact

import javax.ws.rs.core.Link; //導入依賴的package包/類
@Test
public void testGetTimeMapJsonCompact() throws IOException {
    when(mockResource.getMementos()).thenReturn(asList(
            between(ofEpochSecond(timestamp - 2000), ofEpochSecond(timestamp - 1000)),
            between(ofEpochSecond(timestamp - 1000), time),
            between(time, ofEpochSecond(timestamp + 1000))));

    final Response res = target(RESOURCE_PATH).queryParam("ext", "timemap").request()
        .accept("application/ld+json; profile=\"http://www.w3.org/ns/json-ld#compacted\"").get();

    assertEquals(OK, res.getStatusInfo());
    assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()));
    assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE));
    assertNull(res.getHeaderString(ACCEPT_POST));
    assertNull(res.getHeaderString(ACCEPT_PATCH));
    assertNull(res.getHeaderString(ACCEPT_RANGES));
    assertNull(res.getLastModified());

    // Jersey's client doesn't parse complex link headers correctly, so res.getLinks() is not used here
    final List<Link> links = res.getStringHeaders().get(LINK).stream().map(Link::valueOf).collect(toList());

    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 2000))
                    .equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496260729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 1000))
                    .equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496261729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("memento") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(time).equals(l.getParams().get("datetime")) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?version=1496262729000")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("timemap") &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp - 2000))
                    .equals(l.getParams().get("from")) &&
                RFC_1123_DATE_TIME.withZone(UTC).format(ofEpochSecond(timestamp + 1000))
                    .equals(l.getParams().get("until")) &&
                APPLICATION_LINK_FORMAT.equals(l.getType()) &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH + "?ext=timemap")));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("timegate") &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH)));
    assertTrue(links.stream().anyMatch(l -> l.getRels().contains("original") &&
                l.getUri().toString().equals(BASE_URL + RESOURCE_PATH)));
    assertTrue(links.stream().anyMatch(hasType(LDP.Resource)));
    assertTrue(links.stream().anyMatch(hasType(LDP.RDFSource)));
    assertFalse(links.stream().anyMatch(hasType(LDP.Container)));

    assertFalse(res.getAllowedMethods().contains("PATCH"));
    assertFalse(res.getAllowedMethods().contains("PUT"));
    assertFalse(res.getAllowedMethods().contains("DELETE"));
    assertTrue(res.getAllowedMethods().contains("GET"));
    assertTrue(res.getAllowedMethods().contains("HEAD"));
    assertTrue(res.getAllowedMethods().contains("OPTIONS"));
    assertFalse(res.getAllowedMethods().contains("POST"));
    assertNull(res.getHeaderString(MEMENTO_DATETIME));

    final String entity = IOUtils.toString((InputStream) res.getEntity(), UTF_8);
    final Map<String, Object> obj = MAPPER.readValue(entity,
            new TypeReference<Map<String, Object>>(){});

    @SuppressWarnings("unchecked")
    final List<Map<String, Object>> graph = (List<Map<String, Object>>) obj.get("@graph");

    assertEquals(5L, graph.size());
    assertTrue(graph.stream().anyMatch(x -> x.containsKey("@id") &&
                x.get("@id").equals(BASE_URL + RESOURCE_PATH) &&
                x.containsKey("timegate") && x.containsKey("timemap") && x.containsKey("memento")));
    assertTrue(graph.stream().anyMatch(x -> x.containsKey("@id") &&
                x.get("@id").equals(BASE_URL + RESOURCE_PATH + "?ext=timemap") &&
                x.containsKey("hasBeginning") &&
                x.containsKey("hasEnd")));
    assertTrue(graph.stream().anyMatch(x -> x.containsKey("@id") &&
                x.get("@id").equals(BASE_URL + RESOURCE_PATH + "?version=1496260729000") &&
                x.containsKey("hasTime")));
    assertTrue(graph.stream().anyMatch(x -> x.containsKey("@id") &&
                x.get("@id").equals(BASE_URL + RESOURCE_PATH + "?version=1496261729000") &&
                x.containsKey("hasTime")));
    assertTrue(graph.stream().anyMatch(x -> x.containsKey("@id") &&
                x.get("@id").equals(BASE_URL + RESOURCE_PATH + "?version=1496262729000") &&
                x.containsKey("hasTime")));
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:82,代碼來源:AbstractLdpResourceTest.java

示例11: getBatchToken

import javax.ws.rs.core.Link; //導入依賴的package包/類
public String getBatchToken() {
    Link link = this.response.getLink("'next'");

    if (link != null) {
        MultivaluedMap<String, String> parameters = UriComponent.decodeQuery(link.getUri(), true);
        return parameters.getFirst("batch_token");
    }

    return null;
}
 
開發者ID:square,項目名稱:connect-java-sdk,代碼行數:11,代碼來源:CompleteResponse.java

示例12: followPageable

import javax.ws.rs.core.Link; //導入依賴的package包/類
private <T, LT extends ObjectList<T, LT>> LT followPageable(Link next, LT responseBody, Class<LT> responseType) {
    while (next != null) {
        Response nextResponse = client.target(next).request(APPLICATION_JSON_TYPE).get();
        LT nextResponseBody = nextResponse.readEntity(responseType);
        responseBody = responseBody.merge(nextResponseBody);
        next = nextResponse.getLink("next");
    }
    return responseBody;
}
 
開發者ID:ocadotechnology,項目名稱:newrelic-alerts-configurator,代碼行數:10,代碼來源:ApiBase.java

示例13: isLink

import javax.ws.rs.core.Link; //導入依賴的package包/類
private boolean isLink(String linkString) {
    try {
        Link.valueOf(linkString);

        return true;
    } catch (IllegalArgumentException e) {
        return false;
    }
}
 
開發者ID:xstefank,項目名稱:lra-service,代碼行數:10,代碼來源:Coordinator.java

示例14: cannonicalForm

import javax.ws.rs.core.Link; //導入依賴的package包/類
private static String cannonicalForm(String linkStr) {
    if (linkStr.indexOf(',') == -1)
        return linkStr;

    SortedMap<String, String> lm = new TreeMap<>();
    Arrays.stream(linkStr.split(",")).forEach(link -> lm.put(Link.valueOf(link).getRel(), link));
    StringBuilder sb = new StringBuilder();

    lm.forEach((k, v) -> appendLink(sb, v));

    return sb.toString();
}
 
開發者ID:xstefank,項目名稱:lra-service,代碼行數:13,代碼來源:LRARecord.java

示例15: unmarshal

import javax.ws.rs.core.Link; //導入依賴的package包/類
public Link unmarshal(CustomJaxbLink p1) {

        Link.Builder builder = Link.fromUri(p1.getUri());
        for (Map.Entry<QName, Object> entry : p1.getParams().entrySet()) {
            builder.param(entry.getKey().getLocalPart(), entry.getValue().toString());
        }
        return builder.build();
    }
 
開發者ID:aruld,項目名稱:dropwizard-pagination,代碼行數:9,代碼來源:CustomJaxbAdapter.java


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