Package opendap.dts

Class DTSServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
opendap.servlet.AbstractServlet
opendap.dts.DTSServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable

public class DTSServlet extends opendap.servlet.AbstractServlet
Purpose:
This is the OPeNDAP Test servlet (dts). It allows the owner of the server to deliver data in ANY valid DDS to a client. This DDS will be filled with invented data if the client requests a DataDDS. This kind of test fixture is useful for evaluating a clients ability to handle the various complexities of the OPeNDAP data types.

Configuration:
The AbstractServlet relies on the jakarta.servlet.ServletConfig interface (in particular the getInitParameter() method) to retrieve configuration information used by the servlet. InitParameters:

  • DebugOn - This controls ouput to the terminal from which the servlet engine was launched. The value is a list of flags that turn on debugging instrumentation in different parts of the code. Values are:
    • showRequest - Show information about the clients request.
    • showResponse - Show information about the servlets response.
    • probeRequest - Show an exhaustive amount of information about the clients request object.

  • INFOcache - This is should be set to the directory containing the files used by the ".info" service for the servlet. This directory should contain any dataset specific "over-ride" files (see below), any dataset specific additional information files (see below), and any servlet specific information files(see below).

  • DDScache - This is should be set to the directory containing the DDS files for the datasets used by the servlet. Some servlets have been developed that do not use DDS's that are cached on the disk, however the default behaviour is for the servlet to load DDS images from disk.

  • DAScache - This is should be set to the directory containing the DAS files for the datasets used by the servlet. Some servlets have been developed that do not use DAS's that are cached on the disk, however the default behaviour is for the servlet to load DAS images from disk.

Here is an example entry from the web.xml file (for tomcat3.3a) for the OPeNDAP Test Server (DTS):

         <servlet>
            <servlet-name>
                dts
            </servlet-name>

            <servlet-class>
                opendap.servers.dts
            </servlet-class>

            <init-param>
                <param-name>DebugOn</param-name>
                <param-value>showRequest showResponse </param-value>
            </init-param>

            <init-param>
                <param-name>INFOcache</param-name>
                <param-value>/usr/Java-OPeNDAP/sdds-testsuite/info/</param-value>
            </init-param>

            <init-param>
                <param-name>DDScache</param-name>
                <param-value>/usr/Java-OPeNDAP/sdds-testsuite/dds/</param-value>
            </init-param>

            <init-param>
                <param-name>DAScache</param-name>
                <param-value>/usr/Java-OPeNDAP/sdds-testsuite/das/</param-value>
            </init-param>
        </servlet>
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static org.slf4j.Logger
     

    Fields inherited from class opendap.servlet.AbstractServlet

    allowDeflate
  • Constructor Summary

    Constructors
    Constructor
    Description
    ************************************************************************ Intitializes the servlet.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    anyExceptionHandler(Throwable e, opendap.servlet.ReqState rs)
    Sends an error to the client.
    void
    badURL(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Sends an html document to the client explaining that they have used a poorly formed URL and then the help page...
    void
    dap2ExceptionHandler(opendap.dap.DAP2Exception de, jakarta.servlet.http.HttpServletResponse response)
    Sends a OPeNDAP DAP2 error to the client.
    void
    doDebug(opendap.servlet.ReqState rs)
    Handler for debug requests;
    protected boolean
     
    void
    doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
    Handles incoming requests from clients.
    void
    doGetASC(opendap.servlet.ReqState rs)
    Handler for OPeNDAP ascii data requests.
    void
    doGetBLOB(opendap.servlet.ReqState rs)
    Handler for the client's data request.
    void
    doGetCatalog(opendap.servlet.ReqState rs)
    Handler for OPeNDAP catalog.xml requests.
    void
    doGetDAP2Data(opendap.servlet.ReqState rs)
    Handler for the client's data request.
    void
    doGetDAS(opendap.servlet.ReqState rs)
    Handler for the client's DAS request.
    void
    doGetDDS(opendap.servlet.ReqState rs)
    Handler for the client's DDS request.
    void
    doGetDDX(opendap.servlet.ReqState rs)
    Handler for the client's DDX request.
    void
    doGetDIR(opendap.servlet.ReqState rs)
    Handler for the client's directory request.
    void
    doGetHELP(opendap.servlet.ReqState rs)
    Handler for the client's help request.
    void
    doGetHTML(opendap.servlet.ReqState rs)
    Handler for OPeNDAP .html requests.
    void
    doGetINFO(opendap.servlet.ReqState rs)
    Handler for OPeNDAP info requests.
    void
    doGetStatus(opendap.servlet.ReqState rs)
    Handler for OPeNDAP status requests; not publically available, used only for debugging
    void
    doGetSystemProps(opendap.servlet.ReqState rs)
    Handler for OPeNDAP status requests; not publically available, used only for debugging
    void
    doGetVER(opendap.servlet.ReqState rs)
    Handler for the client's version request.
    protected opendap.servlet.GuardedDataset
    getDataset(opendap.servlet.ReqState rs)
    ************************************************************************ This method must be implemented locally for each OPeNDAP server.
    protected opendap.servlet.ReqState
    getRequestState(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
     
    Getter function for rootpath
    In this (default) implementation of the getServerName() method we just get the name of the servlet and pass it back.
    This method returns a String containing the OPeNDAP Server Version...
    void
     
    void
    IOExceptionHandler(IOException e, opendap.servlet.ReqState rs)
    Sends an error to the client.
    void
    parseExceptionHandler(opendap.dap.parsers.ParseException pe, jakarta.servlet.http.HttpServletResponse response)
    Turns a ParseException into a OPeNDAP DAP2 error and sends it to the client.
    protected void
    printCatalog(opendap.servlet.ReqState rs, PrintWriter os)
     
    protected void
     
    void
    probeRequest(PrintStream ps, opendap.servlet.ReqState rs)
    This is a bit of instrumentation that I kept around to let me look at the state of the incoming HttpServletRequest from the client.
    void
    sendDODSError(opendap.servlet.ReqState rs, String clientMsg, String serverMsg)
    Sends a OPeNDAP DAP2 error (type UNKNOWN ERROR) to the client and displays a message on the server console.

    Methods inherited from class opendap.servlet.AbstractServlet

    badURL, doDebugCmd, printDODSException, printThrowable, probeRequest, sendDODSError, setLog, setRootpath

    Methods inherited from class jakarta.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service

    Methods inherited from class jakarta.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • log

      public static org.slf4j.Logger log
  • Constructor Details

    • DTSServlet

      public DTSServlet()
      ************************************************************************ Intitializes the servlet. Init (at this time) basically sets up the object opendap.util.util.Debug from the debuggery flags in the servlet InitParameters. The Debug object can be referenced (with impunity) from anywhere in the VM.
  • Method Details

    • getRootPath

      public String getRootPath()
      Getter function for rootpath
      Returns:
      rootpath
    • getServerVersion

      public String getServerVersion()
      This method returns a String containing the OPeNDAP Server Version...
      Specified by:
      getServerVersion in class opendap.servlet.AbstractServlet
    • getDataset

      protected opendap.servlet.GuardedDataset getDataset(opendap.servlet.ReqState rs) throws opendap.dap.DAP2Exception, IOException, opendap.dap.parsers.ParseException
      ************************************************************************ This method must be implemented locally for each OPeNDAP server. The local implementation of this method is the key piece for connecting any localized data types that are derived from the opendap.Server types back into the running servlet.

      This method should do the following:

      • Make a new ServerFactory (aka BaseTypeFactory) for the dataset requested.
      • Instantiate a ServerDDS using the ServerFactory and populate it (this could be accomplished by just opening a (cached?) DDS in a file and parsing it)
      • Return this freshly minted ServerDDS object (to the servlet code where it is used.)
      Specified by:
      getDataset in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState object for this particular client request.
      Returns:
      The ServerDDS object all parsed and ready to roll.
      Throws:
      opendap.dap.DAP2Exception
      IOException
      opendap.dap.parsers.ParseException
    • init

      public void init() throws jakarta.servlet.ServletException
      Overrides:
      init in class jakarta.servlet.GenericServlet
      Throws:
      jakarta.servlet.ServletException
    • parseExceptionHandler

      public void parseExceptionHandler(opendap.dap.parsers.ParseException pe, jakarta.servlet.http.HttpServletResponse response)
      Turns a ParseException into a OPeNDAP DAP2 error and sends it to the client.
      Overrides:
      parseExceptionHandler in class opendap.servlet.AbstractServlet
      Parameters:
      pe - The ParseException that caused the problem.
      response - The HttpServletResponse for the client.
    • dap2ExceptionHandler

      public void dap2ExceptionHandler(opendap.dap.DAP2Exception de, jakarta.servlet.http.HttpServletResponse response)
      Sends a OPeNDAP DAP2 error to the client.
      Overrides:
      dap2ExceptionHandler in class opendap.servlet.AbstractServlet
      Parameters:
      de - The OPeNDAP DAP2 exception that caused the problem.
      response - The HttpServletResponse for the client.
    • IOExceptionHandler

      public void IOExceptionHandler(IOException e, opendap.servlet.ReqState rs)
      Sends an error to the client. fix: The problem is that if the message is already committed when the IOException occurs, the headers dont get set.
      Overrides:
      IOExceptionHandler in class opendap.servlet.AbstractServlet
      Parameters:
      e - The exception that caused the problem.
      rs - The ReqState for the client.
    • anyExceptionHandler

      public void anyExceptionHandler(Throwable e, opendap.servlet.ReqState rs)
      Sends an error to the client.
      Overrides:
      anyExceptionHandler in class opendap.servlet.AbstractServlet
      Parameters:
      e - The exception that caused the problem.
      rs - The ReqState for the client.
    • sendDODSError

      public void sendDODSError(opendap.servlet.ReqState rs, String clientMsg, String serverMsg) throws Exception
      Sends a OPeNDAP DAP2 error (type UNKNOWN ERROR) to the client and displays a message on the server console.
      Parameters:
      rs - The client's ReqState object.
      clientMsg - Error message String to send to the client.
      serverMsg - Error message String to display on the server console.
      Throws:
      Exception
    • doGetDAS

      public void doGetDAS(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's DAS request. Operates on the assumption that the DAS information is cached on a disk local to the server. If you don't like that, then you better override it in your server :)

      Once the DAS has been parsed it is sent to the requesting client.

      Overrides:
      doGetDAS in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState of this client request. Contains all kinds of important stuff.
      Throws:
      Exception
      See Also:
      • ReqState
    • doGetDDS

      public void doGetDDS(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's DDS request. Requires the getDDS() method implemented by each server localization effort.

      Once the DDS has been parsed and constrained it is sent to the requesting client.

      Overrides:
      doGetDDS in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState of this client request. Contains all kinds of important stuff.
      Throws:
      Exception
      See Also:
      • ReqState
    • doGetDDX

      public void doGetDDX(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's DDX request. Requires the getDDX() method implemented by each server localization effort.

      Once the DDX has been parsed and constrained it is sent to the requesting client.

      Overrides:
      doGetDDX in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState of this client request. Contains all kinds of important stuff.
      Throws:
      Exception
      See Also:
      • ReqState
    • doGetBLOB

      public void doGetBLOB(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's data request. Requires the getDDS() method implemented by each server localization effort.

      Once the DDS has been parsed, the data is read (using the class in the localized server factory etc.), compared to the constraint expression, and then sent to the client.

      Overrides:
      doGetBLOB in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState of this client request. Contains all kinds of important stuff.
      Throws:
      Exception
      See Also:
      • ReqState
    • doGetDAP2Data

      public void doGetDAP2Data(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's data request. Requires the getDDS() method implemented by each server localization effort.

      Once the DDS has been parsed, the data is read (using the class in the localized server factory etc.), compared to the constraint expression, and then sent to the client.

      Overrides:
      doGetDAP2Data in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The ReqState of this client request. Contains all kinds of important stuff.
      Throws:
      IOException
      jakarta.servlet.ServletException
      Exception
      See Also:
      • ReqState
    • doGetDIR

      public void doGetDIR(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's directory request.

      Returns an html document to the client showing (a possibly pseudo) listing of the datasets available on the server in a directory listing format.

      The bulk of this code resides in the class opendap.servlet.GetDirHandler and documentation may be found there.

      Overrides:
      doGetDIR in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetDirHandler
    • doGetVER

      public void doGetVER(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's version request.

      Returns a plain text document with server version and OPeNDAP core version #'s

      Overrides:
      doGetVER in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
    • doGetHELP

      public void doGetHELP(opendap.servlet.ReqState rs) throws Exception
      Handler for the client's help request.

      Returns an html page of help info for the server

      Overrides:
      doGetHELP in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
    • badURL

      public void badURL(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception
      Sends an html document to the client explaining that they have used a poorly formed URL and then the help page...
      Parameters:
      request - The client's request
      response - The client response
      Throws:
      Exception
    • doGetASC

      public void doGetASC(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP ascii data requests. Returns the request data as a comma delimited ascii file. Note that this means that the more complex OPeNDAP structures such as Grids get flattened...

      Modified 2/8/07 jcaron to not make a DConnect2 call to itself

      Overrides:
      doGetASC in class opendap.servlet.AbstractServlet
      Parameters:
      rs - the decoded Request State
      Throws:
      Exception
    • doGetINFO

      public void doGetINFO(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP info requests. Returns an HTML document describing the contents of the servers datasets.

      The bulk of this code resides in the class opendap.servlet.GetInfoHandler and documentation may be found there.

      Overrides:
      doGetINFO in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetInfoHandler
    • doGetHTML

      public void doGetHTML(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP .html requests. Returns the OPeNDAP Web Interface (aka The Interface From Hell) to the client.

      The bulk of this code resides in the class opendap.servlet.GetHTMLInterfaceHandler and documentation may be found there.

      Overrides:
      doGetHTML in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetHTMLInterfaceHandler
    • doGetCatalog

      public void doGetCatalog(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP catalog.xml requests.
      Overrides:
      doGetCatalog in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetHTMLInterfaceHandler
    • printCatalog

      protected void printCatalog(opendap.servlet.ReqState rs, PrintWriter os) throws IOException
      Overrides:
      printCatalog in class opendap.servlet.AbstractServlet
      Throws:
      IOException
    • doDebug

      public void doDebug(opendap.servlet.ReqState rs)
      Handler for debug requests;
      Overrides:
      doDebug in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState object.
    • doDebugCmd

      protected boolean doDebugCmd(String cmd, StringTokenizer tz, PrintStream pw)
    • doGetSystemProps

      public void doGetSystemProps(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP status requests; not publically available, used only for debugging
      Overrides:
      doGetSystemProps in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetHTMLInterfaceHandler
    • doGetStatus

      public void doGetStatus(opendap.servlet.ReqState rs) throws Exception
      Handler for OPeNDAP status requests; not publically available, used only for debugging
      Overrides:
      doGetStatus in class opendap.servlet.AbstractServlet
      Parameters:
      rs - The client's ReqState
      Throws:
      Exception
      See Also:
      • GetHTMLInterfaceHandler
    • printStatus

      protected void printStatus(PrintWriter os)
      Overrides:
      printStatus in class opendap.servlet.AbstractServlet
    • probeRequest

      public void probeRequest(PrintStream ps, opendap.servlet.ReqState rs)
      This is a bit of instrumentation that I kept around to let me look at the state of the incoming HttpServletRequest from the client. This method calls the get* methods of the request and prints the results to standard out.
      Parameters:
      ps - The PrintStream to send output.
      rs - The ReqState object to probe.
    • getServerName

      public String getServerName()

      In this (default) implementation of the getServerName() method we just get the name of the servlet and pass it back. If something different is required, override this method when implementing the getDDS() and getServerVersion() methods.

      This is typically used by the getINFO() method to figure out if there is information specific to this server residing in the info directory that needs to be returned to the client as part of the .info rs.getResponse().

      Overrides:
      getServerName in class opendap.servlet.AbstractServlet
      Returns:
      A string containing the name of the servlet class that is running.
    • doGet

      public void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response)
      Handles incoming requests from clients. Parses the request and determines what kind of OPeNDAP response the client is requesting. If the request is understood, then the appropriate handler method is called, otherwise an error is returned to the client.

      This method is the entry point for DTSServlet.

      Overrides:
      doGet in class opendap.servlet.AbstractServlet
      Parameters:
      request - The client's HttpServletRequest request object.
      response - The server's HttpServletResponse response object.
      See Also:
      • ReqState
    • getRequestState

      @Nonnull protected opendap.servlet.ReqState getRequestState(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws opendap.dap.DAP2Exception
      Overrides:
      getRequestState in class opendap.servlet.AbstractServlet
      Parameters:
      request -
      Returns:
      the request state
      Throws:
      opendap.dap.DAP2Exception