Search in sources :

Example 1 with LINK

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());
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) HttpPost(org.apache.http.client.methods.HttpPost) Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) RDF(org.apache.jena.vocabulary.RDF) HttpPatch(org.apache.http.client.methods.HttpPatch) APPLICATION_LINK_FORMAT(org.fcrepo.http.commons.domain.RDFMediaType.APPLICATION_LINK_FORMAT) EntityUtils(org.apache.http.util.EntityUtils) Model(org.apache.jena.rdf.model.Model) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) CommitType(org.fcrepo.storage.ocfl.CommitType) After(org.junit.After) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) RdfLexicon(org.fcrepo.kernel.api.RdfLexicon) Awaitility.await(org.awaitility.Awaitility.await) ATOMIC_ID_HEADER(org.fcrepo.http.commons.session.TransactionConstants.ATOMIC_ID_HEADER) OK(javax.ws.rs.core.Response.Status.OK) MEMBER_SUBJECT(org.fcrepo.kernel.api.RdfLexicon.MEMBER_SUBJECT) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) LDP_MEMBER(org.fcrepo.kernel.api.RdfLexicon.LDP_MEMBER) StringEntity(org.apache.http.entity.StringEntity) Collectors(java.util.stream.Collectors) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) HttpGet(org.apache.http.client.methods.HttpGet) Assert.assertFalse(org.junit.Assert.assertFalse) ModelFactory(org.apache.jena.rdf.model.ModelFactory) CREATED(javax.ws.rs.core.Response.Status.CREATED) Link(javax.ws.rs.core.Link) LINK(javax.ws.rs.core.HttpHeaders.LINK) DIRECT_CONTAINER(org.fcrepo.kernel.api.RdfLexicon.DIRECT_CONTAINER) HttpHead(org.apache.http.client.methods.HttpHead) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) HAS_MEMBER_RELATION(org.fcrepo.kernel.api.RdfLexicon.HAS_MEMBER_RELATION) HttpDelete(org.apache.http.client.methods.HttpDelete) GONE(javax.ws.rs.core.Response.Status.GONE) MEMBERSHIP_RESOURCE(org.fcrepo.kernel.api.RdfLexicon.MEMBERSHIP_RESOURCE) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Resource(org.apache.jena.rdf.model.Resource) DC(org.apache.jena.vocabulary.DC) Status(javax.ws.rs.core.Response.Status) ResourceFactory.createResource(org.apache.jena.rdf.model.ResourceFactory.createResource) INSERTED_CONTENT_RELATION(org.fcrepo.kernel.api.RdfLexicon.INSERTED_CONTENT_RELATION) Before(org.junit.Before) PREFER_MEMBERSHIP(org.fcrepo.kernel.api.RdfLexicon.PREFER_MEMBERSHIP) Assert.assertNotNull(org.junit.Assert.assertNotNull) StringWriter(java.io.StringWriter) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) TimeUnit(java.util.concurrent.TimeUnit) ResourceFactory.createProperty(org.apache.jena.rdf.model.ResourceFactory.createProperty) INDIRECT_CONTAINER(org.fcrepo.kernel.api.RdfLexicon.INDIRECT_CONTAINER) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) HttpPut(org.apache.http.client.methods.HttpPut) DefaultOcflObjectSessionFactory(org.fcrepo.storage.ocfl.DefaultOcflObjectSessionFactory) FCR_VERSIONS(org.fcrepo.kernel.api.FedoraTypes.FCR_VERSIONS) OcflPropsConfig(org.fcrepo.config.OcflPropsConfig) Property(org.apache.jena.rdf.model.Property) Assert.assertEquals(org.junit.Assert.assertEquals) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 2 with LINK

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));
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpPatch(org.apache.http.client.methods.HttpPatch) VERSIONING_TIMEMAP_TYPE(org.fcrepo.kernel.api.RdfLexicon.VERSIONING_TIMEMAP_TYPE) Model(org.apache.jena.rdf.model.Model) CommitType(org.fcrepo.storage.ocfl.CommitType) NodeFactory.createLiteral(org.apache.jena.graph.NodeFactory.createLiteral) Arrays.asList(java.util.Arrays.asList) RDF_SOURCE(org.fcrepo.kernel.api.RdfLexicon.RDF_SOURCE) Duration(java.time.Duration) ZoneOffset(java.time.ZoneOffset) Dataset(org.apache.jena.query.Dataset) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) POSSIBLE_RDF_RESPONSE_VARIANTS_STRING(org.fcrepo.http.commons.domain.RDFMediaType.POSSIBLE_RDF_RESPONSE_VARIANTS_STRING) OK(javax.ws.rs.core.Response.Status.OK) HttpOptions(org.apache.http.client.methods.HttpOptions) IOUtils(org.apache.commons.io.IOUtils) Assert.assertFalse(org.junit.Assert.assertFalse) Link(javax.ws.rs.core.Link) SC_BAD_REQUEST(org.apache.http.HttpStatus.SC_BAD_REQUEST) NodeFactory.createURI(org.apache.jena.graph.NodeFactory.createURI) HttpHead(org.apache.http.client.methods.HttpHead) CONTAINS(org.fcrepo.kernel.api.RdfLexicon.CONTAINS) MEMENTO_RFC_1123_FORMATTER(org.fcrepo.kernel.api.services.VersionService.MEMENTO_RFC_1123_FORMATTER) METHOD_NOT_ALLOWED(javax.ws.rs.core.Response.Status.METHOD_NOT_ALLOWED) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) TemporalAccessor(java.time.temporal.TemporalAccessor) ArrayList(java.util.ArrayList) GONE(javax.ws.rs.core.Response.Status.GONE) Quad(org.apache.jena.sparql.core.Quad) Resource(org.apache.jena.rdf.model.Resource) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) DC(org.apache.jena.vocabulary.DC) ACCEPT_DATETIME(org.fcrepo.http.api.FedoraLdp.ACCEPT_DATETIME) ResourceFactory.createResource(org.apache.jena.rdf.model.ResourceFactory.createResource) Before(org.junit.Before) StringWriter(java.io.StringWriter) FCR_ACL(org.fcrepo.kernel.api.FedoraTypes.FCR_ACL) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) FOUND(javax.ws.rs.core.Response.Status.FOUND) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ResourceFactory.createProperty(org.apache.jena.rdf.model.ResourceFactory.createProperty) Assert.assertNull(org.junit.Assert.assertNull) ChronoUnit(java.time.temporal.ChronoUnit) RDFDataMgr(org.apache.jena.riot.RDFDataMgr) ACCEPT(javax.ws.rs.core.HttpHeaders.ACCEPT) FCR_VERSIONS(org.fcrepo.kernel.api.FedoraTypes.FCR_VERSIONS) HttpResponse(org.apache.http.HttpResponse) RDFFormat(org.apache.jena.riot.RDFFormat) RDFLanguages(org.apache.jena.riot.RDFLanguages) Property(org.apache.jena.rdf.model.Property) Assert.assertEquals(org.junit.Assert.assertEquals) N3(org.fcrepo.http.commons.domain.RDFMediaType.N3) CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) RDF(org.apache.jena.vocabulary.RDF) NON_RDF_SOURCE(org.fcrepo.kernel.api.RdfLexicon.NON_RDF_SOURCE) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) APPLICATION_LINK_FORMAT(org.fcrepo.http.commons.domain.RDFMediaType.APPLICATION_LINK_FORMAT) Arrays.sort(java.util.Arrays.sort) MEMENTO_DATETIME_HEADER(org.fcrepo.http.api.FedoraVersioning.MEMENTO_DATETIME_HEADER) EntityUtils(org.apache.http.util.EntityUtils) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) After(org.junit.After) CONTENT_LENGTH(javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH) CloseableDataset(org.fcrepo.http.commons.test.util.CloseableDataset) MEMENTO_TYPE(org.fcrepo.kernel.api.RdfLexicon.MEMENTO_TYPE) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) StringEntity(org.apache.http.entity.StringEntity) ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) VERSIONED_RESOURCE(org.fcrepo.kernel.api.RdfLexicon.VERSIONED_RESOURCE) OffsetDateTime(java.time.OffsetDateTime) HttpGet(org.apache.http.client.methods.HttpGet) ANY(org.apache.jena.graph.Node.ANY) CREATED(javax.ws.rs.core.Response.Status.CREATED) LINK(javax.ws.rs.core.HttpHeaders.LINK) BASIC_CONTAINER(org.fcrepo.kernel.api.RdfLexicon.BASIC_CONTAINER) EMBED_CONTAINED(org.fcrepo.kernel.api.RdfLexicon.EMBED_CONTAINED) MEMENTO_LABEL_FORMATTER(org.fcrepo.kernel.api.services.VersionService.MEMENTO_LABEL_FORMATTER) FEDORA_BINARY(org.fcrepo.kernel.api.RdfLexicon.FEDORA_BINARY) HttpDelete(org.apache.http.client.methods.HttpDelete) NOT_ACCEPTABLE(javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE) ImmutableList(com.google.common.collect.ImmutableList) RESOURCE(org.fcrepo.kernel.api.RdfLexicon.RESOURCE) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) DC_11.title(org.apache.jena.vocabulary.DC_11.title) ARCHIVAL_GROUP(org.fcrepo.kernel.api.RdfLexicon.ARCHIVAL_GROUP) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) Lang(org.apache.jena.riot.Lang) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) CONTAINER(org.fcrepo.kernel.api.RdfLexicon.CONTAINER) Assert.assertNotNull(org.junit.Assert.assertNotNull) TimeUnit(java.util.concurrent.TimeUnit) ModelFactory.createDefaultModel(org.apache.jena.rdf.model.ModelFactory.createDefaultModel) HttpPut(org.apache.http.client.methods.HttpPut) Rule(org.junit.Rule) DefaultOcflObjectSessionFactory(org.fcrepo.storage.ocfl.DefaultOcflObjectSessionFactory) Node(org.apache.jena.graph.Node) TURTLE(org.fcrepo.http.commons.domain.RDFMediaType.TURTLE) RDF.type(org.apache.jena.vocabulary.RDF.type) Comparator(java.util.Comparator) TemporaryFolder(org.junit.rules.TemporaryFolder) TemporalAccessor(java.time.temporal.TemporalAccessor) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Link(javax.ws.rs.core.Link)

Example 3 with LINK

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;
}
Also used : CACHE_CONTROL(javax.ws.rs.core.HttpHeaders.CACHE_CONTROL) Arrays(java.util.Arrays) HttpPatch(org.apache.http.client.methods.HttpPatch) ServerManagedTypeException(org.fcrepo.kernel.api.exception.ServerManagedTypeException) Transaction(org.fcrepo.kernel.api.Transaction) StringUtils(org.apache.commons.lang3.StringUtils) MediaType(javax.ws.rs.core.MediaType) WebContent.ctTextPlain(org.apache.jena.riot.WebContent.ctTextPlain) PreferTag(org.fcrepo.http.commons.domain.PreferTag) Binary(org.fcrepo.kernel.api.models.Binary) InvalidChecksumException(org.fcrepo.kernel.api.exception.InvalidChecksumException) NonRdfSourceDescription(org.fcrepo.kernel.api.models.NonRdfSourceDescription) Response.status(javax.ws.rs.core.Response.status) ZoneOffset(java.time.ZoneOffset) Variant.mediaTypes(javax.ws.rs.core.Variant.mediaTypes) BAD_REQUEST(javax.ws.rs.core.Response.Status.BAD_REQUEST) ContentDigest(org.fcrepo.kernel.api.utils.ContentDigest) RdfStream(org.fcrepo.kernel.api.RdfStream) Set(java.util.Set) TombstoneException(org.fcrepo.kernel.api.exception.TombstoneException) DefaultRdfStream(org.fcrepo.kernel.api.rdf.DefaultRdfStream) StandardCharsets(java.nio.charset.StandardCharsets) BeanParam(javax.ws.rs.BeanParam) HttpRdfService(org.fcrepo.http.api.services.HttpRdfService) Container(org.fcrepo.kernel.api.models.Container) Stream(java.util.stream.Stream) Link(javax.ws.rs.core.Link) Stream.empty(java.util.stream.Stream.empty) SC_BAD_REQUEST(org.apache.http.HttpStatus.SC_BAD_REQUEST) FEDORA_ID_PREFIX(org.fcrepo.kernel.api.FedoraTypes.FEDORA_ID_PREFIX) NodeFactory.createURI(org.apache.jena.graph.NodeFactory.createURI) PathNotFoundRuntimeException(org.fcrepo.kernel.api.exception.PathNotFoundRuntimeException) RdfNamespaceRegistry(org.fcrepo.kernel.api.rdf.RdfNamespaceRegistry) MEMENTO_RFC_1123_FORMATTER(org.fcrepo.kernel.api.services.VersionService.MEMENTO_RFC_1123_FORMATTER) RDFLanguages.contentTypeToLang(org.apache.jena.riot.RDFLanguages.contentTypeToLang) ArrayList(java.util.ArrayList) MessageFormat.format(java.text.MessageFormat.format) ResourceTripleService(org.fcrepo.kernel.api.services.ResourceTripleService) JSON_LD(org.fcrepo.http.commons.domain.RDFMediaType.JSON_LD) CONTENT_LOCATION(javax.ws.rs.core.HttpHeaders.CONTENT_LOCATION) RangeRequestInputStream(org.fcrepo.http.commons.responses.RangeRequestInputStream) WebContent.ctSPARQLUpdate(org.apache.jena.riot.WebContent.ctSPARQLUpdate) FCR_METADATA(org.fcrepo.kernel.api.FedoraTypes.FCR_METADATA) FCR_ACL(org.fcrepo.kernel.api.FedoraTypes.FCR_ACL) IOException(java.io.IOException) DigestAlgorithm(org.fcrepo.config.DigestAlgorithm) WebContent.contentTypeSPARQLUpdate(org.apache.jena.riot.WebContent.contentTypeSPARQLUpdate) HttpTripleUtil(org.fcrepo.http.commons.api.rdf.HttpTripleUtil) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) CreateResourceService(org.fcrepo.kernel.api.services.CreateResourceService) TX_PREFIX(org.fcrepo.http.commons.session.TransactionConstants.TX_PREFIX) EtagService(org.fcrepo.http.api.services.EtagService) ACCEPT(javax.ws.rs.core.HttpHeaders.ACCEPT) RepositoryRuntimeException(org.fcrepo.kernel.api.exception.RepositoryRuntimeException) COPY(org.fcrepo.kernel.api.models.ExternalContent.COPY) ServletContext(javax.servlet.ServletContext) TEXT_HTML(javax.ws.rs.core.MediaType.TEXT_HTML) NTRIPLES(org.fcrepo.http.commons.domain.RDFMediaType.NTRIPLES) N3(org.fcrepo.http.commons.domain.RDFMediaType.N3) CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) InsufficientStorageException(org.fcrepo.kernel.api.exception.InsufficientStorageException) Tombstone(org.fcrepo.kernel.api.models.Tombstone) ClientErrorException(javax.ws.rs.ClientErrorException) MEMENTO_DATETIME_HEADER(org.fcrepo.http.api.FedoraVersioning.MEMENTO_DATETIME_HEADER) RDF_XML(org.fcrepo.http.commons.domain.RDFMediaType.RDF_XML) Response.notAcceptable(javax.ws.rs.core.Response.notAcceptable) PARTIAL_CONTENT(javax.ws.rs.core.Response.Status.PARTIAL_CONTENT) Response.noContent(javax.ws.rs.core.Response.noContent) WebContent.ctTextCSV(org.apache.jena.riot.WebContent.ctTextCSV) BadRequestException(javax.ws.rs.BadRequestException) URI(java.net.URI) RdfNamespacedStream(org.fcrepo.http.commons.responses.RdfNamespacedStream) CONTENT_LENGTH(javax.ws.rs.core.HttpHeaders.CONTENT_LENGTH) Splitter(com.google.common.base.Splitter) Collectors.toSet(java.util.stream.Collectors.toSet) FedoraResource(org.fcrepo.kernel.api.models.FedoraResource) PathNotFoundException(org.fcrepo.kernel.api.exception.PathNotFoundException) ATOMIC_ID_HEADER(org.fcrepo.http.commons.session.TransactionConstants.ATOMIC_ID_HEADER) Context(javax.ws.rs.core.Context) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Triple(org.apache.jena.graph.Triple) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) DeleteResourceService(org.fcrepo.kernel.api.services.DeleteResourceService) N3_ALT2(org.fcrepo.http.commons.domain.RDFMediaType.N3_ALT2) List(java.util.List) URI.create(java.net.URI.create) Response(javax.ws.rs.core.Response) CharsetEncoder(java.nio.charset.CharsetEncoder) Optional(org.jvnet.hk2.annotations.Optional) TimeMap(org.fcrepo.kernel.api.models.TimeMap) Response.ok(javax.ws.rs.core.Response.ok) Request(javax.ws.rs.core.Request) CacheControl(javax.ws.rs.core.CacheControl) Response.created(javax.ws.rs.core.Response.created) WebacAcl(org.fcrepo.kernel.api.models.WebacAcl) LINK(javax.ws.rs.core.HttpHeaders.LINK) Range(org.fcrepo.http.commons.domain.Range) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) PROXY(org.fcrepo.kernel.api.models.ExternalContent.PROXY) MultiPrefer(org.fcrepo.http.commons.domain.MultiPrefer) WebContent.matchContentType(org.apache.jena.riot.WebContent.matchContentType) Inject(javax.inject.Inject) ContentDisposition(org.springframework.http.ContentDisposition) TX_ENDPOINT_REL(org.fcrepo.http.commons.session.TransactionConstants.TX_ENDPOINT_REL) FedoraId(org.fcrepo.kernel.api.identifiers.FedoraId) CONTENT_DISPOSITION(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) REQUESTED_RANGE_NOT_SATISFIABLE(javax.ws.rs.core.Response.Status.REQUESTED_RANGE_NOT_SATISFIABLE) UpdatePropertiesService(org.fcrepo.kernel.api.services.UpdatePropertiesService) Logger(org.slf4j.Logger) LdpPreferTag(org.fcrepo.http.commons.domain.ldp.LdpPreferTag) HttpServletResponse(javax.servlet.http.HttpServletResponse) EntityTag(javax.ws.rs.core.EntityTag) PreconditionException(org.fcrepo.kernel.api.exception.PreconditionException) HttpPut(org.apache.http.client.methods.HttpPut) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Node(org.apache.jena.graph.Node) TURTLE(org.fcrepo.http.commons.domain.RDFMediaType.TURTLE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) VisibleForTesting(com.google.common.annotations.VisibleForTesting) REDIRECT(org.fcrepo.kernel.api.models.ExternalContent.REDIRECT) UnsupportedAlgorithmException(org.fcrepo.kernel.api.exception.UnsupportedAlgorithmException) ContentType(org.apache.jena.atlas.web.ContentType) InputStream(java.io.InputStream) ReplacePropertiesService(org.fcrepo.kernel.api.services.ReplacePropertiesService) LdpPreferTag(org.fcrepo.http.commons.domain.ldp.LdpPreferTag) ArrayList(java.util.ArrayList) RdfStream(org.fcrepo.kernel.api.RdfStream) DefaultRdfStream(org.fcrepo.kernel.api.rdf.DefaultRdfStream) Stream(java.util.stream.Stream) RangeRequestInputStream(org.fcrepo.http.commons.responses.RangeRequestInputStream) RdfNamespacedStream(org.fcrepo.http.commons.responses.RdfNamespacedStream) InputStream(java.io.InputStream) DefaultRdfStream(org.fcrepo.kernel.api.rdf.DefaultRdfStream)

Example 4 with LINK

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()));
    }
}
Also used : DELETE(javax.ws.rs.HttpMethod.DELETE) LINK(javax.ws.rs.core.HttpHeaders.LINK) Provider(javax.ws.rs.ext.Provider) ServiceBundler(org.trellisldp.common.ServiceBundler) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) Resource(org.trellisldp.api.Resource) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) SLUG(org.trellisldp.common.HttpConstants.SLUG) Inject(javax.inject.Inject) WebDAVUtils.getAllButLastSegment(org.trellisldp.webdav.impl.WebDAVUtils.getAllButLastSegment) CONFIG_HTTP_PUT_UNCONTAINED(org.trellisldp.common.HttpConstants.CONFIG_HTTP_PUT_UNCONTAINED) Response.status(javax.ws.rs.core.Response.status) LDP(org.trellisldp.vocabulary.LDP) TYPE(javax.ws.rs.core.Link.TYPE) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) PathSegment(javax.ws.rs.core.PathSegment) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) CONFIG_HTTP_BASE_URL(org.trellisldp.common.HttpConstants.CONFIG_HTTP_BASE_URL) ConfigProvider.getConfig(org.eclipse.microprofile.config.ConfigProvider.getConfig) Config(org.eclipse.microprofile.config.Config) PreMatching(javax.ws.rs.container.PreMatching) List(java.util.List) IRI(org.apache.commons.rdf.api.IRI) POST(javax.ws.rs.HttpMethod.POST) HttpSession(org.trellisldp.common.HttpSession) WebDAVUtils.getLastSegment(org.trellisldp.webdav.impl.WebDAVUtils.getLastSegment) UriInfo(javax.ws.rs.core.UriInfo) PUT(javax.ws.rs.HttpMethod.PUT) WebDAVUtils.recursiveDelete(org.trellisldp.webdav.impl.WebDAVUtils.recursiveDelete) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) Link(javax.ws.rs.core.Link) IRI(org.apache.commons.rdf.api.IRI) Resource(org.trellisldp.api.Resource) List(java.util.List) PathSegment(javax.ws.rs.core.PathSegment)

Example 5 with LINK

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));
    }
}
Also used : Response(javax.ws.rs.core.Response) DELETE(javax.ws.rs.HttpMethod.DELETE) SortedSet(java.util.SortedSet) GET(javax.ws.rs.HttpMethod.GET) Optional.of(java.util.Optional.of) ACCEPT_POST(org.trellisldp.common.HttpConstants.ACCEPT_POST) Prefer(org.trellisldp.common.Prefer) ACCEPT_DATETIME(org.trellisldp.common.HttpConstants.ACCEPT_DATETIME) Collections.singletonList(java.util.Collections.singletonList) SKOS(org.trellisldp.vocabulary.SKOS) WILDCARD_TYPE(javax.ws.rs.core.MediaType.WILDCARD_TYPE) MediaType(javax.ws.rs.core.MediaType) Arrays.asList(java.util.Arrays.asList) JSONLD.compacted(org.trellisldp.vocabulary.JSONLD.compacted) PREFER(org.trellisldp.common.HttpConstants.PREFER) RANGE(org.trellisldp.common.HttpConstants.RANGE) OK(javax.ws.rs.core.Response.Status.OK) PATCH(javax.ws.rs.HttpMethod.PATCH) Instant(java.time.Instant) ACCEPT_RANGES(org.trellisldp.common.HttpConstants.ACCEPT_RANGES) Test(org.junit.jupiter.api.Test) VARY(javax.ws.rs.core.HttpHeaders.VARY) List(java.util.List) Stream(java.util.stream.Stream) APPLICATION_LD_JSON(org.trellisldp.common.RdfMediaType.APPLICATION_LD_JSON) Response(javax.ws.rs.core.Response) POST(javax.ws.rs.HttpMethod.POST) UTC(java.time.ZoneOffset.UTC) PUT(javax.ws.rs.HttpMethod.PUT) Arrays.stream(java.util.Arrays.stream) Link(javax.ws.rs.core.Link) LINK(javax.ws.rs.core.HttpHeaders.LINK) Instant.now(java.time.Instant.now) LD_PATCH(org.trellisldp.api.Syntax.LD_PATCH) APPLICATION_N_TRIPLES(org.trellisldp.common.RdfMediaType.APPLICATION_N_TRIPLES) TEXT_HTML_TYPE(javax.ws.rs.core.MediaType.TEXT_HTML_TYPE) ACL(org.trellisldp.vocabulary.ACL) TreeSet(java.util.TreeSet) PREFERENCE_APPLIED(org.trellisldp.common.HttpConstants.PREFERENCE_APPLIED) MEMENTO_DATETIME(org.trellisldp.common.HttpConstants.MEMENTO_DATETIME) APPLICATION_SPARQL_UPDATE(org.trellisldp.common.RdfMediaType.APPLICATION_SPARQL_UPDATE) RDFA(org.apache.commons.rdf.api.RDFSyntax.RDFA) NOT_ACCEPTABLE(javax.ws.rs.core.Response.Status.NOT_ACCEPTABLE) TURTLE(org.apache.commons.rdf.api.RDFSyntax.TURTLE) Date.from(java.util.Date.from) OPTIONS(javax.ws.rs.HttpMethod.OPTIONS) ACCEPT_PATCH(org.trellisldp.common.HttpConstants.ACCEPT_PATCH) LDP(org.trellisldp.vocabulary.LDP) JSONLD(org.apache.commons.rdf.api.RDFSyntax.JSONLD) SimpleEntry(java.util.AbstractMap.SimpleEntry) Trellis(org.trellisldp.vocabulary.Trellis) BinaryMetadata(org.trellisldp.api.BinaryMetadata) APPLICATION_LD_JSON_TYPE(org.trellisldp.common.RdfMediaType.APPLICATION_LD_JSON_TYPE) ZonedDateTime.ofInstant(java.time.ZonedDateTime.ofInstant) NotAcceptableException(javax.ws.rs.NotAcceptableException) TEXT_TURTLE_TYPE(org.trellisldp.common.RdfMediaType.TEXT_TURTLE_TYPE) DESCRIPTION(org.trellisldp.common.HttpConstants.DESCRIPTION) Predicate.isEqual(java.util.function.Predicate.isEqual) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) Mockito.when(org.mockito.Mockito.when) EntityTag(javax.ws.rs.core.EntityTag) TEXT_PLAIN_TYPE(javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE) Collectors.toList(java.util.stream.Collectors.toList) HEAD(javax.ws.rs.HttpMethod.HEAD) OA(org.trellisldp.vocabulary.OA) DigestUtils.sha256Hex(org.apache.commons.codec.digest.DigestUtils.sha256Hex) Executable(org.junit.jupiter.api.function.Executable) Assertions(org.junit.jupiter.api.Assertions) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) NTRIPLES(org.apache.commons.rdf.api.RDFSyntax.NTRIPLES) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)5 LINK (javax.ws.rs.core.HttpHeaders.LINK)5 Link (javax.ws.rs.core.Link)5 IOException (java.io.IOException)3 Instant (java.time.Instant)3 Collectors (java.util.stream.Collectors)3 CONTENT_TYPE (javax.ws.rs.core.HttpHeaders.CONTENT_TYPE)3 BAD_REQUEST (javax.ws.rs.core.Response.Status.BAD_REQUEST)3 NO_CONTENT (javax.ws.rs.core.Response.Status.NO_CONTENT)3 OK (javax.ws.rs.core.Response.Status.OK)3 HttpPatch (org.apache.http.client.methods.HttpPatch)3 HttpPut (org.apache.http.client.methods.HttpPut)3 ZoneOffset (java.time.ZoneOffset)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Stream (java.util.stream.Stream)2 Inject (javax.inject.Inject)2 DELETE (javax.ws.rs.HttpMethod.DELETE)2 POST (javax.ws.rs.HttpMethod.POST)2 PUT (javax.ws.rs.HttpMethod.PUT)2