@Controller
@RequestMapping(value={"/download","/restrictedAccess/download"})
public class DownloadController
extends LoadCommon
The 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 "
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:
LoadCommon.SendError| Modifier and Type | Field and Description |
|---|---|
protected ucar.nc2.write.Nc4Chunking |
chunking |
protected static boolean |
DEBUG |
protected static java.lang.String |
DEFAULTDOWNLOADDIR |
protected static java.lang.String |
DEFAULTREQUESTNAME |
protected java.lang.String |
downloadform |
protected static java.lang.String |
FILESERVERSERVLET |
protected thredds.server.reify.DownloadParameters |
params |
protected ucar.nc2.write.Nc4Chunking.Strategy |
strategy |
DEFAULTDOWNLOADFORM, DEFAULTSERVLETNAME, DEFAULTUPLOADFORM, downloaddir, downloaddirname, HTMLLEN, initialized, once, req, requestname, res, server, tdsContext, threddsname, uploaddir| Constructor and Description |
|---|
DownloadController() |
| Modifier and Type | Method and Description |
|---|---|
protected java.lang.String |
buildForm(java.lang.String msg) |
protected boolean |
canCopy(java.lang.String truepath,
thredds.server.reify.LoadCommon.FileFormat targetformat) |
protected java.lang.String |
directAccess(java.lang.String relpath,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res) |
void |
doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res) |
void |
doonce(javax.servlet.http.HttpServletRequest req)
Invoked once on first request so that everything is available,
especially Spring stuff.
|
protected java.lang.String |
download() |
protected static java.lang.String |
escapeString(java.lang.String s)
Given a typical string, insert backslashes
before '"' and '\\' characters and control characters.
|
protected void |
makeNetcdf3(ucar.nc2.NetcdfFile ncfile,
java.lang.String target) |
protected void |
makeNetcdf4(ucar.nc2.NetcdfFile ncfile,
java.lang.String target) |
void |
setup(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp) |
getStackTrace, init, initOnce, inquire, mapToString, parseList, parseMap, reportRequest, sendError, sendError, sendError, sendErrorForm, sendForm, sendOK, sendReply, urlDecode, urlEncodeprotected static final boolean DEBUG
protected static final java.lang.String DEFAULTREQUESTNAME
protected static final java.lang.String DEFAULTDOWNLOADDIR
protected static final java.lang.String FILESERVERSERVLET
protected ucar.nc2.write.Nc4Chunking.Strategy strategy
protected ucar.nc2.write.Nc4Chunking chunking
protected thredds.server.reify.DownloadParameters params
protected java.lang.String downloadform
public DownloadController()
throws javax.servlet.ServletException
javax.servlet.ServletExceptionpublic void doonce(javax.servlet.http.HttpServletRequest req)
throws LoadCommon.SendError
LoadCommon.SendErrorpublic void setup(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp)
throws LoadCommon.SendError
LoadCommon.SendError@RequestMapping(value="**",
method=GET)
public void doGet(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
throws javax.servlet.ServletException
javax.servlet.ServletExceptionprotected java.lang.String download()
SendError - if bad requestprotected void makeNetcdf4(ucar.nc2.NetcdfFile ncfile,
java.lang.String target)
throws java.io.IOException
java.io.IOExceptionprotected void makeNetcdf3(ucar.nc2.NetcdfFile ncfile,
java.lang.String target)
throws java.io.IOException
java.io.IOExceptionprotected static java.lang.String escapeString(java.lang.String s)
protected java.lang.String directAccess(java.lang.String relpath,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res)
protected boolean canCopy(java.lang.String truepath,
thredds.server.reify.LoadCommon.FileFormat targetformat)
protected java.lang.String buildForm(java.lang.String msg)
buildForm in class LoadCommon