Class DownloadServiceImpl
- All Implemented Interfaces:
DownloadService
,Adaptable
,Component
,Extensible
,TimestampedService
- Since:
- 7.3
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.io.download.DownloadService
DownloadService.DownloadContext
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
static final String
protected RedirectResolver
protected ScriptEngineManager
static final String
static final String
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
Fields inherited from interface org.nuxeo.ecm.core.io.download.DownloadService
BLOBHOLDER_0, BLOBHOLDER_PREFIX, EVENT_NAME, EXTENDED_INFO_CLIENT_REASON, EXTENDED_INFO_RENDITION, NXBIGBLOB, NXBLOBSTATUS, NXDOWNLOADINFO, NXFILE, REQUEST_ATTR_DOWNLOAD_REASON, REQUEST_ATTR_DOWNLOAD_RENDITION, REQUEST_HEADER_CLIENT_REASON, REQUEST_QUERY_PARAM_CLIENT_REASON, TRANSIENT_STORE_PARAM_ERROR, TRANSIENT_STORE_PARAM_PROGRESS, TRANSIENT_STORE_STORE_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCacheControlHeaders
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Internet Explorer file downloads over SSL do not work with certain HTTP cache control headersboolean
checkPermission
(DocumentModel doc, String xpath, Blob blob, String reason, Map<String, Serializable> extendedInfos) Checks whether the download of the blob is allowed.void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) Triggers a blobs download.protected void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason, boolean status) void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason) Deprecated.void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos) Deprecated.void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos, Boolean inline) Deprecated.void
downloadBlob
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos, Boolean inline, Consumer<ByteRange> blobTransferer) Deprecated.void
Triggers a blob download.void
downloadBlobStatus
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) Triggers aAsyncBlob
download which gives information about an asynchronous blob.protected String
protected static boolean
protected ByteRange
getByteRange
(javax.servlet.http.HttpServletRequest request, long length) protected org.apache.commons.lang3.tuple.Pair<String,
DownloadServiceImpl.Action> Gets the download path and action of the URL to use to download blobs.getDownloadUrl
(String storeKey) Gets the URL to use to download the blobs identified by a storage key.getDownloadUrl
(String repositoryName, String docId, String xpath, String filename) Gets the URL to use to download the blob at the given xpath in the given document.getDownloadUrl
(String repositoryName, String docId, String xpath, String filename, String changeToken) Gets the URL to use to download the blob at the given xpath in the given document.getDownloadUrl
(DocumentModel doc, String xpath, String filename) Gets the URL to use to download the blob at the given xpath in the given document.getFullDownloadUrl
(DocumentModel doc, String xpath, Blob blob, String baseUrl) Gets the full download URL (after redirects if configured so) for the given blob.protected static NuxeoPrincipal
protected String
getSanitizedFilenameWithoutPath
(String filename) getWantDigests
(javax.servlet.http.HttpServletRequest request) void
handleDownload
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String baseUrl, String path) Handles the download of a document.protected void
handleDownload
(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String downloadPath, String baseUrl, boolean info) protected static String
hexToBase64
(String hexString) protected static boolean
isHead
(javax.servlet.http.HttpServletRequest request) void
logDownload
(javax.servlet.http.HttpServletRequest request, DocumentModel doc, String xpath, String filename, String reason, Map<String, Serializable> extendedInfos) Logs a download.resolveBlob
(DocumentModel doc) Finds a document's blob.resolveBlob
(DocumentModel doc, String xpath) Finds a document's blob given an xpath or blobholder indexresolveBlobFromDownloadUrl
(String downloadURL) Finds a document's blob given the download URL returned byDownloadService.getDownloadUrl(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String)
.void
start
(ComponentContext context) Start the component.void
stop
(ComponentContext context) Stop the component.storeBlobs
(List<Blob> blobs) Stores the blobs for later download.void
transferBlobWithByteRange
(Blob blob, ByteRange byteRange, Supplier<OutputStream> outputStreamSupplier) Copies the blob stream at the given byte range into the suppliedOutputStream
.protected void
transferBlobWithByteRange
(Blob blob, ByteRange byteRange, javax.servlet.http.HttpServletResponse response) Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterContribution, unregisterExtension
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.nuxeo.runtime.model.Component
getApplicationStartedOrder
Methods inherited from interface org.nuxeo.ecm.core.io.download.DownloadService
logDownload
-
Field Details
-
XP_PERMISSIONS
- See Also:
-
XP_REDIRECT_RESOLVER
- See Also:
-
DOWNLOAD_URL_FOLLOW_REDIRECT
- Since:
- 11.1
- See Also:
-
scriptEngineManager
-
redirectResolver
-
CHEMISTRY_HEAD_REQUEST_CLASS
- See Also:
-
-
Constructor Details
-
DownloadServiceImpl
public DownloadServiceImpl()
-
-
Method Details
-
start
Description copied from interface:Component
Start the component. This method is called after all the components were resolved and activated- Specified by:
start
in interfaceComponent
- Overrides:
start
in classDefaultComponent
-
stop
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
- Throws:
InterruptedException
-
storeBlobs
Stores the blobs for later download. Multipart download are not yet supported. You can only provide a blob singleton at this time.- Specified by:
storeBlobs
in interfaceDownloadService
- Parameters:
blobs
- the list of blobs to store- Returns:
- the store key used for retrieving the blobs (@see
DownloadService.getDownloadUrl(String)
-
getFullDownloadUrl
Description copied from interface:DownloadService
Gets the full download URL (after redirects if configured so) for the given blob.- Specified by:
getFullDownloadUrl
in interfaceDownloadService
- Parameters:
doc
- the documentxpath
- the blob's xpath or blobholder index, ornull
for defaultblob
- the blobbaseUrl
- the base URL to use for Nuxeo downloads (if there is no redirect)- Returns:
- the full URL (which may be to a redirected server)
-
getDownloadUrl
Description copied from interface:DownloadService
Gets the URL to use to download the blob at the given xpath in the given document.The URL is relative to the Nuxeo Web Application context.
Returns something like
nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1
- Specified by:
getDownloadUrl
in interfaceDownloadService
- Parameters:
doc
- the documentxpath
- the blob's xpath or blobholder index, ornull
for defaultfilename
- the blob's filename, ornull
for default- Returns:
- the download URL with changeToken as query param for optimized http caching
-
getDownloadUrl
Description copied from interface:DownloadService
Gets the URL to use to download the blob at the given xpath in the given document.The URL is relative to the Nuxeo Web Application context.
Returns something like
nxfile/reponame/docuuid/blobholder:0/foo.jpg
- Specified by:
getDownloadUrl
in interfaceDownloadService
- Parameters:
repositoryName
- the document repositorydocId
- the document idxpath
- the blob's xpath or blobholder index, ornull
for defaultfilename
- the blob's filename, ornull
for default- Returns:
- the download URL
-
getDownloadUrl
public String getDownloadUrl(String repositoryName, String docId, String xpath, String filename, String changeToken) Description copied from interface:DownloadService
Gets the URL to use to download the blob at the given xpath in the given document.The URL is relative to the Nuxeo Web Application context.
Returns something like
nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1
- Specified by:
getDownloadUrl
in interfaceDownloadService
- Parameters:
repositoryName
- the document repositorydocId
- the document idxpath
- the blob's xpath or blobholder index, ornull
for defaultfilename
- the blob's filename, ornull
for defaultchangeToken
- the doc changeToken which will be appended as a query parameter for optimized http caching.- Returns:
- the download URL
-
getSanitizedFilenameWithoutPath
-
getDownloadUrl
Description copied from interface:DownloadService
Gets the URL to use to download the blobs identified by a storage key.The URL is relative to the Nuxeo Web Application context.
Returns something like
nxbigblob/key
- Specified by:
getDownloadUrl
in interfaceDownloadService
- Parameters:
storeKey
- The key of stored blobs to download- Returns:
- the download URL
-
getDownloadPathAndAction
protected org.apache.commons.lang3.tuple.Pair<String,DownloadServiceImpl.Action> getDownloadPathAndAction(String path) Gets the download path and action of the URL to use to download blobs. For instance, from the path "nxfile/default/3727ef6b-cf8c-4f27-ab2c-79de0171a2c8/files:files/0/file/image.png", the pair ("default/3727ef6b-cf8c-4f27-ab2c-79de0171a2c8/files:files/0/file/image.png", Action.DOWNLOAD_FROM_DOC) is returned.- Parameters:
path
- the path of the URL to use to download blobs- Returns:
- the pair download path and action
- Since:
- 9.1
-
resolveBlobFromDownloadUrl
Description copied from interface:DownloadService
Finds a document's blob given the download URL returned byDownloadService.getDownloadUrl(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String)
.The permissions are check whether the user can download the blob or not.
- Specified by:
resolveBlobFromDownloadUrl
in interfaceDownloadService
- Parameters:
downloadURL
- the URL to use to download the blob- Returns:
- the blob, or
null
if not found or if the user has no permission to download it
-
handleDownload
public void handleDownload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String baseUrl, String path) throws IOException Description copied from interface:DownloadService
Handles the download of a document.- Specified by:
handleDownload
in interfaceDownloadService
- Parameters:
req
- the requestresp
- the responsebaseUrl
- the request baseUrlpath
- the request path, without the context- Throws:
IOException
-
isHead
protected static boolean isHead(javax.servlet.http.HttpServletRequest request) -
handleDownload
protected void handleDownload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, String downloadPath, String baseUrl, boolean info) throws IOException - Throws:
IOException
-
downloadBlobStatus
public void downloadBlobStatus(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) throws IOException Description copied from interface:DownloadService
Triggers aAsyncBlob
download which gives information about an asynchronous blob.- Specified by:
downloadBlobStatus
in interfaceDownloadService
key
- the stored blobs keyreason
- the download reason- Throws:
IOException
-
downloadBlob
public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason) throws IOException Description copied from interface:DownloadService
Triggers a blobs download. Once the temporary blobs are transfered from the store, they are automatically deleted. The returned HTTP Status Code is 200 if the blob is ready or 202 if it is still being processed.- Specified by:
downloadBlob
in interfaceDownloadService
key
- the stored blobs keyreason
- the download reason- Throws:
IOException
-
downloadBlob
protected void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String key, String reason, boolean status) throws IOException - Throws:
IOException
-
downloadBlob
@Deprecated public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason) throws IOException Deprecated.Description copied from interface:DownloadService
Triggers a blob download.- Specified by:
downloadBlob
in interfaceDownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reason- Throws:
IOException
-
downloadBlob
@Deprecated public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos) throws IOExceptionDeprecated.Description copied from interface:DownloadService
Triggers a blob download.- Specified by:
downloadBlob
in interfaceDownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to log- Throws:
IOException
-
downloadBlob
@Deprecated public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos, Boolean inline) throws IOExceptionDeprecated.Description copied from interface:DownloadService
Triggers a blob download.- Specified by:
downloadBlob
in interfaceDownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to loginline
- if not null, force the inline flag for content-disposition- Throws:
IOException
-
downloadBlob
@Deprecated public void downloadBlob(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String, Serializable> extendedInfos, Boolean inline, Consumer<ByteRange> blobTransferer) throws IOExceptionDeprecated.Description copied from interface:DownloadService
Triggers a blob download.- Specified by:
downloadBlob
in interfaceDownloadService
doc
- the document, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blob, if already fetchedfilename
- the filename to usereason
- the download reasonextendedInfos
- an optional map of extended informations to loginline
- if not null, force the inline flag for content-dispositionblobTransferer
- the transferer of the actual blob- Throws:
IOException
-
downloadBlob
Description copied from interface:DownloadService
Triggers a blob download.- Specified by:
downloadBlob
in interfaceDownloadService
- Parameters:
context
- the download context- Throws:
IOException
-
getByteRange
-
getWantDigests
-
hexToBase64
-
transferBlobWithByteRange
-
transferBlobWithByteRange
public void transferBlobWithByteRange(Blob blob, ByteRange byteRange, Supplier<OutputStream> outputStreamSupplier) Description copied from interface:DownloadService
Copies the blob stream at the given byte range into the suppliedOutputStream
.- Specified by:
transferBlobWithByteRange
in interfaceDownloadService
- Parameters:
blob
- the blobbyteRange
- the byte rangeoutputStreamSupplier
- theOutputStream
supplier
-
fixXPath
-
resolveBlob
Description copied from interface:DownloadService
Finds a document's blob.- Specified by:
resolveBlob
in interfaceDownloadService
- Parameters:
doc
- the document- Returns:
- the blob, or
null
if not available
-
resolveBlob
Description copied from interface:DownloadService
Finds a document's blob given an xpath or blobholder index- Specified by:
resolveBlob
in interfaceDownloadService
- Parameters:
doc
- the documentxpath
- the xpath or blobholder index- Returns:
- the blob, or
null
if not found
-
checkPermission
public boolean checkPermission(DocumentModel doc, String xpath, Blob blob, String reason, Map<String, Serializable> extendedInfos) Description copied from interface:DownloadService
Checks whether the download of the blob is allowed.- Specified by:
checkPermission
in interfaceDownloadService
- Parameters:
doc
- the doc for which this download occurs, if availablexpath
- the blob's xpath or blobholder index, if availableblob
- the blobreason
- the download reasonextendedInfos
- an optional map of extended informations to log- Returns:
true
if download is allowed
-
addCacheControlHeaders
protected void addCacheControlHeaders(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Internet Explorer file downloads over SSL do not work with certain HTTP cache control headersSee http://support.microsoft.com/kb/323308/
What is not mentioned in the above Knowledge Base is that "Pragma: no-cache" also breaks download in MSIE over SSL
-
forceNoCacheOnMSIE
protected static boolean forceNoCacheOnMSIE() -
logDownload
public void logDownload(javax.servlet.http.HttpServletRequest request, DocumentModel doc, String xpath, String filename, String reason, Map<String, Serializable> extendedInfos) Description copied from interface:DownloadService
Logs a download.- Specified by:
logDownload
in interfaceDownloadService
- Parameters:
request
- the HTTP request, if availabledoc
- the doc for which this download occurs, if availablexpath
- the blob's xpath or blobholder index, if availablefilename
- the filenamereason
- the download reasonextendedInfos
- an optional map of extended informations to log
-
getPrincipal
-