Search in sources :

Example 1 with GONE

use of javax.ws.rs.core.Response.Status.GONE in project trellis by trellis-ldp.

the class GetHandler method initialize.

/**
 * Initialize the get handler.
 * @param resource the Trellis resource
 * @return the response builder
 */
public ResponseBuilder initialize(final Resource resource) {
    if (MISSING_RESOURCE.equals(resource)) {
        throw new NotFoundException();
    } else if (DELETED_RESOURCE.equals(resource)) {
        throw new ClientErrorException(GONE);
    }
    // Redirect for certain trailing slash conditions
    handleTrailingSlashRedirection(resource);
    LOGGER.debug("Acceptable media types: {}", getRequest().getAcceptableMediaTypes());
    // Get the requested syntax
    this.syntax = getSyntax(getServices().getIOService(), getRequest().getAcceptableMediaTypes(), resource.getBinaryMetadata().filter(b -> !DESCRIPTION.equals(getRequest().getExt())).map(b -> b.getMimeType().orElse(APPLICATION_OCTET_STREAM)).orElse(null));
    // For LDP-NRs, if there is a negotiated RDF syntax, throw a 406 error
    if (LDP.NonRDFSource.equals(resource.getInteractionModel()) && getRequest().getExt() == null && this.syntax != null) {
        throw new NotAcceptableException();
    }
    final IRI ext = getExtensionGraphName();
    if (ext != null && !resource.stream(ext).findAny().isPresent()) {
        LOGGER.trace("No stream for extention: {}", ext);
        throw new NotFoundException();
    }
    setResource(resource);
    return ok();
}
Also used : DELETE(javax.ws.rs.HttpMethod.DELETE) HttpUtils.getProfile(org.trellisldp.http.impl.HttpUtils.getProfile) RedirectionException(javax.ws.rs.RedirectionException) HttpUtils.getDefaultProfile(org.trellisldp.http.impl.HttpUtils.getDefaultProfile) SortedSet(java.util.SortedSet) GET(javax.ws.rs.HttpMethod.GET) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ACCEPT_POST(org.trellisldp.common.HttpConstants.ACCEPT_POST) HttpUtils.unskolemizeTriples(org.trellisldp.http.impl.HttpUtils.unskolemizeTriples) WILDCARD(javax.ws.rs.core.MediaType.WILDCARD) ALLOW(javax.ws.rs.core.HttpHeaders.ALLOW) HttpUtils.ldpResourceTypes(org.trellisldp.http.impl.HttpUtils.ldpResourceTypes) Prefer(org.trellisldp.common.Prefer) ACCEPT_DATETIME(org.trellisldp.common.HttpConstants.ACCEPT_DATETIME) ClientErrorException(javax.ws.rs.ClientErrorException) Resource(org.trellisldp.api.Resource) HttpUtils.getSyntax(org.trellisldp.http.impl.HttpUtils.getSyntax) Collectors.toMap(java.util.stream.Collectors.toMap) APPLICATION_OCTET_STREAM(javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) DELETED_RESOURCE(org.trellisldp.api.Resource.SpecialResources.DELETED_RESOURCE) PREFER(org.trellisldp.common.HttpConstants.PREFER) RANGE(org.trellisldp.common.HttpConstants.RANGE) PATCH(javax.ws.rs.HttpMethod.PATCH) Set(java.util.Set) StreamingOutput(javax.ws.rs.core.StreamingOutput) HttpUtils.isContainer(org.trellisldp.http.impl.HttpUtils.isContainer) Instant(java.time.Instant) Collectors.joining(java.util.stream.Collectors.joining) NotFoundException(javax.ws.rs.NotFoundException) ACCEPT_RANGES(org.trellisldp.common.HttpConstants.ACCEPT_RANGES) VARY(javax.ws.rs.core.HttpHeaders.VARY) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Stream(java.util.stream.Stream) ORIGIN(org.trellisldp.common.HttpConstants.ORIGIN) POST(javax.ws.rs.HttpMethod.POST) Response.ok(javax.ws.rs.core.Response.ok) PUT(javax.ws.rs.HttpMethod.PUT) Link(javax.ws.rs.core.Link) PREFER_RETURN(org.trellisldp.common.Prefer.PREFER_RETURN) ServiceBundler(org.trellisldp.common.ServiceBundler) Binary(org.trellisldp.api.Binary) TrellisUtils.normalizePath(org.trellisldp.api.TrellisUtils.normalizePath) ArrayList(java.util.ArrayList) PREFERENCE_APPLIED(org.trellisldp.common.HttpConstants.PREFERENCE_APPLIED) MEMENTO_DATETIME(org.trellisldp.common.HttpConstants.MEMENTO_DATETIME) String.join(java.lang.String.join) PREFER_MINIMAL(org.trellisldp.common.Prefer.PREFER_MINIMAL) GONE(javax.ws.rs.core.Response.Status.GONE) Date.from(java.util.Date.from) OPTIONS(javax.ws.rs.HttpMethod.OPTIONS) ACCEPT_PATCH(org.trellisldp.common.HttpConstants.ACCEPT_PATCH) Stream.concat(java.util.stream.Stream.concat) LDP(org.trellisldp.vocabulary.LDP) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) PREFER_REPRESENTATION(org.trellisldp.common.Prefer.PREFER_REPRESENTATION) OutputStream(java.io.OutputStream) BinaryMetadata(org.trellisldp.api.BinaryMetadata) TrellisRequest(org.trellisldp.common.TrellisRequest) NotAcceptableException(javax.ws.rs.NotAcceptableException) Logger(org.slf4j.Logger) DESCRIPTION(org.trellisldp.common.HttpConstants.DESCRIPTION) Stream.of(java.util.stream.Stream.of) NO_CONTENT(javax.ws.rs.core.Response.Status.NO_CONTENT) IOException(java.io.IOException) EntityTag(javax.ws.rs.core.EntityTag) HEAD(javax.ws.rs.HttpMethod.HEAD) IRI(org.apache.commons.rdf.api.IRI) Quad(org.apache.commons.rdf.api.Quad) RDFSyntax(org.apache.commons.rdf.api.RDFSyntax) Version(org.trellisldp.common.Version) ACCEPT(javax.ws.rs.core.HttpHeaders.ACCEPT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) HttpUtils.triplePreferences(org.trellisldp.http.impl.HttpUtils.triplePreferences) MISSING_RESOURCE(org.trellisldp.api.Resource.SpecialResources.MISSING_RESOURCE) InputStream(java.io.InputStream) IRI(org.apache.commons.rdf.api.IRI) NotAcceptableException(javax.ws.rs.NotAcceptableException) NotFoundException(javax.ws.rs.NotFoundException) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 String.join (java.lang.String.join)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Date.from (java.util.Date.from)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Stream (java.util.stream.Stream)1 Stream.concat (java.util.stream.Stream.concat)1 Stream.of (java.util.stream.Stream.of)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 DELETE (javax.ws.rs.HttpMethod.DELETE)1