Class DownloadController


  • @Controller
    @RequestMapping({"/download","/restrictedAccess/download"})
    public class DownloadController
    extends LoadCommon
    Local File Materialization for server-side computing. The tag for this controller is .../download/* or .../restrictedAccess/download

    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 "+/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.

    • Field Detail

      • 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
    • Constructor Detail

      • DownloadController

        public DownloadController()
                           throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
    • Method Detail

      • doonce

        public void doonce​(javax.servlet.http.HttpServletRequest req)
                    throws LoadCommon.SendError
        Invoked once on first request so that everything is available, especially Spring stuff.
        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
      • 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)