Class DownloadController
- java.lang.Object
-
- thredds.server.reify.LoadCommon
-
- thredds.server.reify.DownloadController
-
@Controller @RequestMapping({"/download","/restrictedAccess/download"}) public class DownloadController extends LoadCommonLocal File Materialization for server-side computing. The tag for this controller is .../download/* or .../restrictedAccess/downloadThe goal for this controller is to allow external code to have the thredds server materialize a dataset into the file system .
Note that this functionality is not strictly necessary since it could all be done on the client side. Since the server is doing all of the work of converting a dataset to a file, the client does not need to have its own code for this. This means: 1. It is lightweight WRT the client 2. It is language independent
Assumptions: 1. The external code has authenticated to the thredds server using some authentication mechanism such as client-side certificates or tomcat roles. This code performs no authentication.
2. The external code is running on the same machine as the thredds server, or at least has a common file system so that file system writes by thredds are visible to the external code.
WARNING: In order to support downloading of non-file datasets (e.g. via DAP2 or DAP4) this controller will re-call the server to obtain the output of the request. Experimentation shows this is not a problem. Circularity is tested to ensure the no download loop occurs.
Issues: 1. What file formats are allowed for materialized datasets? - Currently only netcdf-3 (classic) and netcdf-4 (enhanced).
A set of query parameters control the operation of this servlet. Note that all of the query parameter values (but not keys) are assumed to be url-encoded (%xx), so beware. Also, all return values are url-encoded. Using query parameters means that it is possible to use an Http Form to send them; see TestDownload.
Download Request ---------------- Download parameters: - request=download -- materialize a file into the download directory - format=netcdf3|netcdfd4 -- specify the download format - url={a thredds server dataset access url} -- specify the actual dataset. - target={path of the downloaded file} -- if it already exists, then it will be overwritten. Notes: 1. the host, port and servlet prefix of the url will be ignored and replaced with the "
+ /thredds" of the thredds server. This is to prevent attempts to use the thredds server to access external data sources, which would otherwise provide a security leak. 2. The target path must be a relative path. It is interpreted as relative to the value of a -Dtds.download.dir java flag, which must specify an absolute path to a directory into which the downloads are stored. Assuming the Tomcat server is being used, then the path must be writeable by user tomcat, which means that its owner will end up being user tomcat or at least tomcat must be in the group assigned to this directory. Return value: download=
Misc Parameters: - testinfo={testing info} -- for testing purposes
Inquire Request ---------------- Download parameters: - request=inquire -- Inquire about various parameters - inquire={semicolon separated arguments} -- Inquire about the default download dir
Return value:
={value of the requested key}; one key-value pair per line.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class thredds.server.reify.LoadCommon
LoadCommon.SendError
-
-
Field Summary
Fields Modifier and Type Field Description protected ucar.nc2.write.Nc4Chunkingchunkingprotected static booleanDEBUGprotected static StringDEFAULTDOWNLOADDIRprotected static StringDEFAULTREQUESTNAMEprotected Stringdownloadformprotected static StringFILESERVERSERVLETprotected thredds.server.reify.DownloadParametersparamsprotected ucar.nc2.write.Nc4Chunking.Strategystrategy-
Fields inherited from class thredds.server.reify.LoadCommon
DEFAULTDOWNLOADFORM, DEFAULTSERVLETNAME, DEFAULTUPLOADFORM, downloaddir, downloaddirname, HTMLLEN, initialized, once, req, requestname, res, server, tdsContext, threddsname, uploaddir
-
-
Constructor Summary
Constructors Constructor Description DownloadController()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringbuildForm(String msg)protected booleancanCopy(String truepath, thredds.server.reify.LoadCommon.FileFormat targetformat)protected StringdirectAccess(String relpath, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)voiddoonce(javax.servlet.http.HttpServletRequest req)Invoked once on first request so that everything is available, especially Spring stuff.protected Stringdownload()protected static StringescapeString(String s)Given a typical string, insert backslashes before '"' and '\\' characters and control characters.protected voidmakeNetcdf3(ucar.nc2.NetcdfFile ncfile, String target)protected voidmakeNetcdf4(ucar.nc2.NetcdfFile ncfile, String target)voidsetup(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)-
Methods inherited from class thredds.server.reify.LoadCommon
getStackTrace, init, initOnce, inquire, mapToString, parseList, parseMap, reportRequest, sendError, sendError, sendError, sendErrorForm, sendForm, sendOK, sendReply, urlDecode, urlEncode
-
-
-
-
Field Detail
-
DEBUG
protected static final boolean DEBUG
- See Also:
- Constant Field Values
-
DEFAULTREQUESTNAME
protected static final String DEFAULTREQUESTNAME
- See Also:
- Constant Field Values
-
DEFAULTDOWNLOADDIR
protected static final String DEFAULTDOWNLOADDIR
- See Also:
- Constant Field Values
-
FILESERVERSERVLET
protected static final String FILESERVERSERVLET
- See Also:
- Constant Field Values
-
strategy
protected ucar.nc2.write.Nc4Chunking.Strategy strategy
-
chunking
protected ucar.nc2.write.Nc4Chunking chunking
-
params
protected thredds.server.reify.DownloadParameters params
-
downloadform
protected String downloadform
-
-
Method Detail
-
doonce
public void doonce(javax.servlet.http.HttpServletRequest req) throws LoadCommon.SendErrorInvoked once on first request so that everything is available, especially Spring stuff.- Throws:
LoadCommon.SendError
-
setup
public void setup(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws LoadCommon.SendError- Throws:
LoadCommon.SendError
-
doGet
@RequestMapping(value="**", method=GET) public void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException- Throws:
javax.servlet.ServletException
-
download
protected String download()
- Returns:
- absolute path to the downloaded file
- Throws:
LoadCommon.SendError- if bad request
-
makeNetcdf4
protected void makeNetcdf4(ucar.nc2.NetcdfFile ncfile, String target) throws IOException- Throws:
IOException
-
makeNetcdf3
protected void makeNetcdf3(ucar.nc2.NetcdfFile ncfile, String target) throws IOException- Throws:
IOException
-
escapeString
protected static String escapeString(String s)
Given a typical string, insert backslashes before '"' and '\\' characters and control characters.
-
directAccess
protected String directAccess(String relpath, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
-
canCopy
protected boolean canCopy(String truepath, thredds.server.reify.LoadCommon.FileFormat targetformat)
-
buildForm
protected String buildForm(String msg)
- Specified by:
buildFormin classLoadCommon
-
-