use of javax.ws.rs.core.HttpHeaders.LINK in project fcrepo by fcrepo.
the class LDPContainerIT method listMementoIds.
private List<String> listMementoIds(final String rescId) throws IOException {
final HttpGet httpGet = getObjMethod(rescId + "/" + FCR_VERSIONS);
httpGet.setHeader("Accept", APPLICATION_LINK_FORMAT);
final String responseBody;
try (final CloseableHttpResponse response = execute(httpGet)) {
assertEquals("Didn't get a OK response!", OK.getStatusCode(), getStatus(response));
responseBody = EntityUtils.toString(response.getEntity());
}
final List<String> bodyList = Arrays.asList(responseBody.split("," + System.lineSeparator()));
return bodyList.stream().map(String::trim).filter(t -> !t.isEmpty()).map(Link::valueOf).filter(l -> "memento".equals(l.getRel())).map(l -> l.getUri().toString()).map(this::toId).sorted().collect(Collectors.toList());
}
use of javax.ws.rs.core.HttpHeaders.LINK in project fcrepo by fcrepo.
the class FedoraVersioningIT method verifyTimemapResponse.
/**
* Verify an application/link-format TimeMap response.
*
* @param uri The full URI of the Original Resource.
* @param id The path of the Original Resource.
* @param mementoDateTime Array of all the RFC-1123 datetimes for all the mementos.
* @param rangeStart RFC-1123 datetime of the first memento.
* @param rangeEnd RFC-1123 datetime of the last memento.
* @throws Exception on HTTP request error
*/
private void verifyTimemapResponse(final String uri, final String id, final String[] mementoDateTime, final String rangeStart, final String rangeEnd) throws Exception {
final String ldpcvUri = uri + "/" + FCR_VERSIONS;
final var expectedLinksOther = new ArrayList<Link>();
final var expectedLinksMemento = new ArrayList<Link>();
expectedLinksOther.add(Link.fromUri(uri).rel("original").build());
expectedLinksOther.add(Link.fromUri(uri).rel("timegate").build());
expectedLinksOther.sort(Comparator.comparing(Link::toString));
final var expectedSelfLinkBuilder = Link.fromUri(ldpcvUri).rel("self").type(APPLICATION_LINK_FORMAT);
if (rangeStart != null && rangeEnd != null) {
expectedSelfLinkBuilder.param("from", rangeStart).param("until", rangeEnd);
}
final var expectedSelfLink = expectedSelfLinkBuilder.build();
if (mementoDateTime != null) {
for (final String memento : mementoDateTime) {
final TemporalAccessor instant = MEMENTO_RFC_1123_FORMATTER.parse(memento);
expectedLinksMemento.add(Link.fromUri(ldpcvUri + "/" + MEMENTO_LABEL_FORMATTER.format(instant)).rel("memento").param("datetime", memento).build());
}
}
expectedLinksMemento.sort(Comparator.comparing(Link::toString));
final HttpGet httpGet = getObjMethod(id + "/" + FCR_VERSIONS);
httpGet.setHeader("Accept", APPLICATION_LINK_FORMAT);
try (final CloseableHttpResponse response = execute(httpGet)) {
assertEquals("Didn't get a OK response!", OK.getStatusCode(), getStatus(response));
// verify headers in link format.
verifyTimeMapHeaders(response, uri);
final var responseBody = EntityUtils.toString(response.getEntity());
final List<String> bodyList = asList(responseBody.split("," + System.lineSeparator()));
// the links from the body are not
Link selfLink = null;
final var mementoLinks = new ArrayList<Link>();
final var otherLinks = new ArrayList<Link>();
final var allLinks = bodyList.stream().map(String::trim).filter(t -> !t.isEmpty()).sorted(Comparator.naturalOrder()).map(Link::valueOf).collect(Collectors.toList());
for (final var link : allLinks) {
if ("memento".equals(link.getRel())) {
mementoLinks.add(link);
} else if ("self".equals(link.getRel())) {
selfLink = link;
} else {
otherLinks.add(link);
}
}
assertSelfLink(expectedSelfLink, selfLink);
assertEquals(expectedLinksOther, otherLinks);
assertEquals(expectedLinksMemento.size(), mementoLinks.size());
for (var i = 0; i < expectedLinksMemento.size(); i++) {
assertMementoLink(expectedLinksMemento.get(i), mementoLinks.get(i));
}
}
}
use of javax.ws.rs.core.HttpHeaders.LINK in project fcrepo by fcrepo.
the class ContentExposingResource method getResourceTriples.
/**
* This method returns a stream of RDF triples associated with this target resource
*
* @param limit is the number of child resources returned in the response, -1 for all
* @param resource the fedora resource
* @return {@link RdfStream}
*/
private RdfStream getResourceTriples(final int limit, final FedoraResource resource) {
final LdpPreferTag ldpPreferences = getLdpPreferTag();
final List<Stream<Triple>> embedStreams = new ArrayList<>();
embedStreams.add(resourceTripleService.getResourceTriples(transaction(), resource, ldpPreferences, limit));
// Embed the children of this object
if (ldpPreferences.displayEmbed()) {
final var containedResources = resourceFactory.getChildren(transaction(), resource.getFedoraId());
embedStreams.add(containedResources.flatMap(child -> resourceTripleService.getResourceTriples(transaction(), child, ldpPreferences, limit)));
}
final var rdfStream = new DefaultRdfStream(asNode(resource), embedStreams.stream().reduce(empty(), Stream::concat));
if (httpTripleUtil != null && ldpPreferences.displayServerManaged()) {
// Adds fixity service triple to all resources and transaction triple to repo root.
return httpTripleUtil.addHttpComponentModelsForResourceToStream(rdfStream, resource, uriInfo);
}
return rdfStream;
}
use of javax.ws.rs.core.HttpHeaders.LINK in project trellis by trellis-ldp.
the class TrellisWebDAVRequestFilter method filter.
@Override
public void filter(final ContainerRequestContext ctx) {
final IRI identifier = services.getResourceService().getResourceIdentifier(getBaseUrl(baseUrl, ctx.getUriInfo()), ctx.getUriInfo().getPath());
if (PUT.equals(ctx.getMethod()) && createUncontained) {
final Resource res = services.getResourceService().get(identifier).toCompletableFuture().join();
final List<PathSegment> segments = ctx.getUriInfo().getPathSegments();
if ((MISSING_RESOURCE.equals(res) || DELETED_RESOURCE.equals(res)) && segments.stream().map(PathSegment::getPath).anyMatch(s -> !s.isEmpty())) {
ctx.setMethod(POST);
ctx.setRequestUri(ctx.getUriInfo().getBaseUriBuilder().path(getAllButLastSegment(segments)).build());
ctx.getHeaders().putSingle(SLUG, getLastSegment(segments));
}
} else if ("MKCOL".equals(ctx.getMethod())) {
// Note: MKCOL is just a POST with Link: <ldp:BasicContainer>; rel=type and appropriate Slug header
final List<PathSegment> segments = ctx.getUriInfo().getPathSegments();
final String slug = getLastSegment(segments);
if (slug.isEmpty()) {
// cannot POST a new root resource
ctx.abortWith(status(CONFLICT).build());
} else {
ctx.setRequestUri(ctx.getUriInfo().getBaseUriBuilder().path(getAllButLastSegment(segments)).build());
ctx.setMethod(POST);
ctx.getHeaders().putSingle(SLUG, getLastSegment(segments));
ctx.getHeaders().putSingle(LINK, Link.fromUri(LDP.BasicContainer.getIRIString()).rel(TYPE).build().toString());
}
} else if (DELETE.equals(ctx.getMethod())) {
recursiveDelete(services, HttpSession.from(ctx.getSecurityContext()), identifier, getBaseUrl(baseUrl, ctx.getUriInfo()));
}
}
use of javax.ws.rs.core.HttpHeaders.LINK in project trellis by trellis-ldp.
the class GetHandlerTest method testGetBinary.
@Test
void testGetBinary() {
when(mockResource.getBinaryMetadata()).thenReturn(of(testBinary));
when(mockResource.getInteractionModel()).thenReturn(LDP.NonRDFSource);
when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE));
final GetConfiguration config = new GetConfiguration(false, true, true, null, baseUrl);
final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, extensions, config);
try (final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource))).toCompletableFuture().join().build()) {
assertEquals(OK, res.getStatusInfo(), ERR_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_LINK_TYPES, checkLdpType(res, LDP.NonRDFSource));
}
}
Aggregations