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();
}
Aggregations