Package org.fcrepo.http.api
Class ContentExposingResource
- java.lang.Object
-
- org.fcrepo.http.commons.AbstractResource
-
- org.fcrepo.http.api.FedoraBaseResource
-
- org.fcrepo.http.api.ContentExposingResource
-
- Direct Known Subclasses:
FedoraAcl
,FedoraFixity
,FedoraLdp
,FedoraTombstones
,FedoraVersioning
public abstract class ContentExposingResource extends FedoraBaseResource
An abstract class that sits between AbstractResource and any resource that wishes to share the routines for building responses containing binary content.- Author:
- Mike Durbin, ajs6f
-
-
Field Summary
Fields Modifier and Type Field Description static String
ACCEPT_DATETIME
protected javax.servlet.ServletContext
context
protected CreateResourceService
createResourceService
protected DeleteResourceService
deleteResourceService
protected EtagService
etagService
protected ExternalContentHandlerFactory
extContentHandlerFactory
protected HttpRdfService
httpRdfService
protected RdfNamespaceRegistry
namespaceRegistry
protected MultiPrefer
prefer
protected ReplacePropertiesService
replacePropertiesService
protected javax.ws.rs.core.Request
request
protected ResourceTripleService
resourceTripleService
protected static com.google.common.base.Splitter.MapSplitter
RFC3230_SPLITTER
protected javax.servlet.http.HttpServletResponse
servletResponse
protected UpdatePropertiesService
updatePropertiesService
-
Fields inherited from class org.fcrepo.http.api.FedoraBaseResource
dbTransactionExecutor, identifierConverter, resourceFactory, resourceHelper, securityContext, servletRequest, txManager
-
Fields inherited from class org.fcrepo.http.commons.AbstractResource
defaultPidMinter, fedoraPropsConfig, headers, pidMinter, uriInfo, versionService
-
-
Constructor Summary
Constructors Constructor Description ContentExposingResource()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addCacheControlHeaders(javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Add ETag and Last-Modified cache control headers to the responseprotected void
addExternalContentHeaders(FedoraResource resource)
protected void
addLinkAndOptionsHttpHeaders(FedoraResource resource)
Add Link and Option headersprotected void
addResourceHttpHeaders(FedoraResource resource)
Add any resource-specific headers to the responseprotected void
addTransactionHeaders(FedoraResource resource)
protected org.apache.jena.graph.Node
asNode(FedoraResource resource)
This is a helper method for using the idTranslator to convert this resource into an associated Jena Node.protected static String
buildLink(String linkUri, String relation)
Utility function for building a Link.protected void
checkCacheControlHeaders(javax.ws.rs.core.Request request, javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Evaluate the cache control headers for the request to see if it can be served from the cache.protected void
checkForInsufficientStorageException(Throwable rootThrowable, Throwable throwable)
protected static URI
checksumURI(String checksum)
Create a checksum URI object.protected javax.ws.rs.core.Response
createUpdateResponse(FedoraResource resource, boolean created)
Create the appropriate response after a create or update request is processed.protected void
evaluateRequestPreconditions(javax.ws.rs.core.Request request, javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Evaluate request preconditions to ensure the resource is the expected stateprotected abstract String
externalPath()
protected javax.ws.rs.core.Response
getBinaryContent(String rangeValue, FedoraResource resource)
Get the binary content of a datastreamprotected javax.ws.rs.core.MediaType
getBinaryResourceMediaType(FedoraResource resource)
This method returns a MediaType for a binary resource.protected int
getChildrenLimit()
Calculate the max number of children to display at once.protected javax.ws.rs.core.Response
getContent(int limit, FedoraResource resource)
This method returns an HTTP response with content body appropriate to the following arguments.protected RdfStream
getResourceTriples(FedoraResource resource)
protected static String
getSimpleContentType(javax.ws.rs.core.MediaType requestContentType)
protected URI
getUri(FedoraResource resource)
protected boolean
hasLenientPreferHeader()
Utility to check if the Prefer header contains handling="lenient"protected static void
hasRestrictedPath(String externalPath)
Check if a path has a segment prefixed with fcr: that is not fcr:metadata or fcr:aclprotected static boolean
isRdfContentType(String contentTypeString)
protected static Collection<URI>
parseDigestHeader(String digest)
Parse the RFC-3230 Digest response header value.protected void
patchResourcewithSparql(FedoraResource resource, String requestBody)
protected FedoraResource
reloadResource()
protected FedoraResource
resource()
protected void
setVaryAndPreferenceAppliedHeaders(javax.servlet.http.HttpServletResponse servletResponse, MultiPrefer prefer, FedoraResource resource)
protected List<String>
unpackLinks(List<String> rawLinks)
Multi-value Link header values parsed by the javax.ws.rs.core are not split out by the framework Therefore we must do this ourselves.-
Methods inherited from class org.fcrepo.http.api.FedoraBaseResource
doesResourceExist, doInDbTx, doInDbTxWithRetry, getFedoraResource, getUserPrincipal, identifierConverter, isGhostNode, transaction
-
-
-
-
Field Detail
-
ACCEPT_DATETIME
public static final String ACCEPT_DATETIME
- See Also:
- Constant Field Values
-
request
@Context protected javax.ws.rs.core.Request request
-
servletResponse
@Context protected javax.servlet.http.HttpServletResponse servletResponse
-
context
@Context protected javax.servlet.ServletContext context
-
prefer
@BeanParam protected MultiPrefer prefer
-
extContentHandlerFactory
@Inject protected ExternalContentHandlerFactory extContentHandlerFactory
-
namespaceRegistry
@Inject protected RdfNamespaceRegistry namespaceRegistry
-
createResourceService
@Inject protected CreateResourceService createResourceService
-
deleteResourceService
@Inject protected DeleteResourceService deleteResourceService
-
replacePropertiesService
@Inject protected ReplacePropertiesService replacePropertiesService
-
updatePropertiesService
@Inject protected UpdatePropertiesService updatePropertiesService
-
etagService
@Inject protected EtagService etagService
-
httpRdfService
@Inject protected HttpRdfService httpRdfService
-
resourceTripleService
@Inject protected ResourceTripleService resourceTripleService
-
RFC3230_SPLITTER
protected static final com.google.common.base.Splitter.MapSplitter RFC3230_SPLITTER
-
-
Constructor Detail
-
ContentExposingResource
public ContentExposingResource()
-
-
Method Detail
-
externalPath
protected abstract String externalPath()
-
getContent
protected javax.ws.rs.core.Response getContent(int limit, FedoraResource resource) throws IOException
This method returns an HTTP response with content body appropriate to the following arguments.- Parameters:
limit
- is the number of child resources returned in the response, -1 for allresource
- the fedora resource- Returns:
- HTTP response
- Throws:
IOException
- in case of error extracting content
-
setVaryAndPreferenceAppliedHeaders
protected void setVaryAndPreferenceAppliedHeaders(javax.servlet.http.HttpServletResponse servletResponse, MultiPrefer prefer, FedoraResource resource)
-
hasLenientPreferHeader
protected boolean hasLenientPreferHeader()
Utility to check if the Prefer header contains handling="lenient"- Returns:
- True if handling="lenient" was sent.
-
getResourceTriples
protected RdfStream getResourceTriples(FedoraResource resource)
-
getBinaryContent
protected javax.ws.rs.core.Response getBinaryContent(String rangeValue, FedoraResource resource) throws IOException
Get the binary content of a datastream- Parameters:
rangeValue
- the range valueresource
- the fedora resource- Returns:
- Binary blob
- Throws:
IOException
- if io exception occurred
-
getUri
protected URI getUri(FedoraResource resource)
-
resource
protected FedoraResource resource()
-
reloadResource
protected FedoraResource reloadResource()
-
addExternalContentHeaders
protected void addExternalContentHeaders(FedoraResource resource)
-
addLinkAndOptionsHttpHeaders
protected void addLinkAndOptionsHttpHeaders(FedoraResource resource)
Add Link and Option headers- Parameters:
resource
- the resource to generate headers for
-
addTransactionHeaders
protected void addTransactionHeaders(FedoraResource resource)
-
buildLink
protected static String buildLink(String linkUri, String relation)
Utility function for building a Link.- Parameters:
linkUri
- String of URI for the link.relation
- the relation string.- Returns:
- the string version of the link.
-
unpackLinks
protected List<String> unpackLinks(List<String> rawLinks)
Multi-value Link header values parsed by the javax.ws.rs.core are not split out by the framework Therefore we must do this ourselves.- Parameters:
rawLinks
- the list of unprocessed links- Returns:
- List of strings containing one link value per string.
-
addResourceHttpHeaders
protected void addResourceHttpHeaders(FedoraResource resource)
Add any resource-specific headers to the response- Parameters:
resource
- the resource
-
checkCacheControlHeaders
protected void checkCacheControlHeaders(javax.ws.rs.core.Request request, javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Evaluate the cache control headers for the request to see if it can be served from the cache.- Parameters:
request
- the requestservletResponse
- the servlet responseresource
- the fedora resourcetransaction
- the transaction
-
addCacheControlHeaders
protected void addCacheControlHeaders(javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Add ETag and Last-Modified cache control headers to the responseNote: In this implementation, the HTTP headers for ETags and Last-Modified dates are swapped for fedora:Binary resources and their descriptions. Here, we are drawing a distinction between the HTTP resource and the LDP resource. As an HTTP resource, the last-modified header should reflect when the resource at the given URL was last changed. With fedora:Binary resources and their descriptions, this is a little complicated, for the descriptions have, as their subjects, the binary itself. And the fedora:lastModified property produced by that NonRdfSourceDescription refers to the last-modified date of the binary -- not the last-modified date of the NonRdfSourceDescription.
- Parameters:
servletResponse
- the servlet responseresource
- the fedora resourcetransaction
- the transaction
-
evaluateRequestPreconditions
protected void evaluateRequestPreconditions(javax.ws.rs.core.Request request, javax.servlet.http.HttpServletResponse servletResponse, FedoraResource resource, Transaction transaction)
Evaluate request preconditions to ensure the resource is the expected state- Parameters:
request
- the requestservletResponse
- the servlet responseresource
- the resourcetransaction
- the transaction
-
createUpdateResponse
protected javax.ws.rs.core.Response createUpdateResponse(FedoraResource resource, boolean created)
Create the appropriate response after a create or update request is processed. When a resource is created, examine the Prefer and Accept headers to determine whether to include a representation. By default, the URI for the created resource is return as plain text. If a minimal response is requested, then no body is returned. If a non-minimal return is requested, return the RDF for the created resource in the appropriate RDF serialization.- Parameters:
resource
- The created or updated Fedora resource.created
- True for a newly-created resource, false for an updated resource.- Returns:
- 204 No Content (for updated resources), 201 Created (for created resources) including the resource URI or content depending on Prefer headers.
-
getSimpleContentType
protected static String getSimpleContentType(javax.ws.rs.core.MediaType requestContentType)
-
isRdfContentType
protected static boolean isRdfContentType(String contentTypeString)
-
patchResourcewithSparql
protected void patchResourcewithSparql(FedoraResource resource, String requestBody)
-
getBinaryResourceMediaType
protected javax.ws.rs.core.MediaType getBinaryResourceMediaType(FedoraResource resource)
This method returns a MediaType for a binary resource. If the resource's media type is syntactically incorrect, it will return 'application/octet-stream' as the media type.- Parameters:
resource
- the fedora resource- Returns:
- the media type of of a binary resource
-
checksumURI
protected static URI checksumURI(String checksum)
Create a checksum URI object.- Parameters:
checksum
- the checksum- Returns:
- the new URI, or null
-
getChildrenLimit
protected int getChildrenLimit()
Calculate the max number of children to display at once.- Returns:
- the limit of children to display.
-
hasRestrictedPath
protected static void hasRestrictedPath(String externalPath)
Check if a path has a segment prefixed with fcr: that is not fcr:metadata or fcr:acl- Parameters:
externalPath
- the path.
-
parseDigestHeader
protected static Collection<URI> parseDigestHeader(String digest) throws UnsupportedAlgorithmException
Parse the RFC-3230 Digest response header value. Look for a sha1 checksum and return it as a urn, if missing or malformed an empty string is returned.- Parameters:
digest
- The Digest header value- Returns:
- the sha1 checksum value
- Throws:
UnsupportedAlgorithmException
- if an unsupported digest is used
-
checkForInsufficientStorageException
protected void checkForInsufficientStorageException(Throwable rootThrowable, Throwable throwable) throws InvalidChecksumException
- Parameters:
rootThrowable
- The original throwablethrowable
- The throwable under direct scrutiny.- Throws:
InvalidChecksumException
- in case there was a checksum mismatch
-
asNode
protected org.apache.jena.graph.Node asNode(FedoraResource resource)
This is a helper method for using the idTranslator to convert this resource into an associated Jena Node.- Parameters:
resource
- to be converted into a Jena Node- Returns:
- the Jena node
-
-