Class AbstractServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public abstract class AbstractServlet
    extends javax.servlet.http.HttpServlet
    AbstractServlet is the base servlet class for an OPeNDAP servers. Default handlers for all of the acceptable OPeNDAP client requests are here.

    Each of the request handlers appears as an adjunct method to the doGet() method of the base servlet class. In order to reduce the bulk of this file, many of these methods have been in wrapper classes in this package (opendap.servlet).

    This is an abstract class because it is left to the individual server development efforts to write the getDDS() and getServerVersion() methods. The getDDS() method is intended to be where the server specific OPeNDAP server data types are used via their associated class factory.

    This code relies on the javax.servlet.ServletConfig interface (in particular the getInitParameter() method) to record detailed configuration information used by the servlet and it's children.

    The servlet should be started in the servlet engine with the following initParameters for the tomcat servlet engine:

        <servlet>
            <servlet-name>
                dts
            </servlet-name>
            <servlet-class>
                opendap.servers.test.dts
            </servlet-class>
            <init-param>
                <param-name>INFOcache</param-name>
                <param-value>/home/Datasets/info</param-value>
            </init-param>
            <init-param>
                <param-name>DDScache</param-name>
                <param-value>/home/Datasets/dds</param-value>
            </init-param>
            <init-param>
                <param-name>DAScache</param-name>
                <param-value>/home/Datasets/das</param-value>
            </init-param>
            <init-param>
                <param-name>DDXcache</param-name>
                <param-value>/home/Datasets/ddx</param-value>
            </init-param>
        </servlet>
    
     

    Obviously the actual values of these parameters will depend on your particular file system.

    See the file SERVLETS in the top level directory of the software distribution for more detailed information about servlet configuration.

    Also, the method processDodsURL() could be overloaded if some kind of special processing of the incoming request is needed to ascertain the OPeNDAP URL information.
    See Also:
    GetAsciiHandler, GetDirHandler, GetHTMLInterfaceHandler, GetInfoHandler, ReqState, ParsedRequest, GuardedDataset, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean allowDeflate
      ************************************************************************ Compression
      static org.slf4j.Logger log  
      protected String rootpath
      path to the root of the servlet in tomcat webapps directory
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractServlet()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void anyExceptionHandler​(Throwable e, ReqState rs)
      ************************************************************************ Sends an error to the client.
      void badURL​(ReqState rs)
      ************************************************************************ 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, javax.servlet.http.HttpServletResponse response)
      ************************************************************************ Sends a OPeNDAP DAP2 error to the client.
      void doDebug​(ReqState rs)
      ************************************************************************ Default handler for debug requests;
      protected boolean doDebugCmd​(String cmd, StringTokenizer tz, PrintWriter pw)  
      void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      *********************************************************************** Handles incoming requests from clients.
      void doGetASC​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP ascii data requests.
      void doGetBLOB​(ReqState rs)
      ************************************************************************ Default handler for the client's data request.
      void doGetCatalog​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP catalog.xml requests.
      void doGetDAP2Data​(ReqState rs)
      ************************************************************************ Default handler for the client's data request.
      void doGetDAS​(ReqState rs)
      ************************************************************************ Default handler for the client's DAS request.
      void doGetDDS​(ReqState rs)
      ************************************************************************ Default handler for the client's DDS request.
      void doGetDDX​(ReqState rs)
      ************************************************************************ Default handler for the client's DDS request.
      void doGetDIR​(ReqState rs)
      ************************************************************************ Default handler for the client's directory request.
      void doGetHELP​(ReqState rs)
      ************************************************************************ Default handler for the client's help request.
      void doGetHTML​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP .html requests.
      void doGetINFO​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP info requests.
      void doGetStatus​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP status requests; not publically available, used only for debugging
      void doGetSystemProps​(ReqState rs)
      ************************************************************************ Default handler for OPeNDAP status requests; not publically available, used only for debugging
      void doGetVER​(ReqState rs)
      ************************************************************************ Default handler for the client's version request.
      protected abstract GuardedDataset getDataset​(ReqState rs)
      ************************************************************************ This method must be implemented locally for each OPeNDAP server.
      protected ReqState getRequestState​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)  
      String getServerName()
      ************************************************************************
      abstract String getServerVersion()
      This function must be implemented locally for each OPeNDAP server.
      void IOExceptionHandler​(IOException e, ReqState rs)
      ************************************************************************ Sends an error to the client.
      void parseExceptionHandler​(opendap.dap.parsers.ParseException pe, javax.servlet.http.HttpServletResponse response)
      ************************************************************************ Turns a ParseException into a OPeNDAP DAP2 error and sends it to the client.
      protected void printCatalog​(ReqState rs, PrintWriter os)  
      static void printDODSException​(opendap.dap.DAP2Exception de)  
      protected void printStatus​(PrintWriter os)  
      static void printThrowable​(Throwable t)  
      void probeRequest​(PrintWriter ps, 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​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, String clientMsg, String serverMsg)
      ************************************************************************ Sends a OPeNDAP DAP2 error (type UNKNOWN ERROR) to the client and displays a message on the server console.
      static void setLog​(Class cl)  
      protected void setRootpath​(String rootPath)  
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
    • Field Detail

      • log

        public static org.slf4j.Logger log
      • allowDeflate

        protected boolean allowDeflate
        ************************************************************************ Compression
      • rootpath

        protected String rootpath
        path to the root of the servlet in tomcat webapps directory
    • Constructor Detail

      • AbstractServlet

        public AbstractServlet()
    • Method Detail

      • setLog

        public static void setLog​(Class cl)
      • printDODSException

        public static void printDODSException​(opendap.dap.DAP2Exception de)
      • printThrowable

        public static void printThrowable​(Throwable t)
      • setRootpath

        protected void setRootpath​(String rootPath)
      • getServerVersion

        public abstract String getServerVersion()
        This function must be implemented locally for each OPeNDAP server. It should return a String containing the OPeNDAP Server Version...
        Returns:
        The Server Version String
      • getDataset

        protected abstract GuardedDataset getDataset​(ReqState rs)
                                              throws Exception
        ************************************************************************ 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.)
        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
        Exception
        See Also:
        ServerDDS
      • parseExceptionHandler

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

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

        public void IOExceptionHandler​(IOException e,
                                       ReqState rs)
        ************************************************************************ Sends an error to the client. LOOK: The problem is that if the message is already committed when the IOException occurs, the headers dont get set.
        Parameters:
        e - The exception that caused the problem.
        rs - The ReqState for the client.
      • anyExceptionHandler

        public void anyExceptionHandler​(Throwable e,
                                        ReqState rs)
        ************************************************************************ Sends an error to the client.
        Parameters:
        e - The exception that caused the problem.
        rs - The ReqState for the client.
      • sendDODSError

        public void sendDODSError​(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response,
                                  String clientMsg,
                                  String serverMsg)
                           throws IOException,
                                  javax.servlet.ServletException
        ************************************************************************ Sends a OPeNDAP DAP2 error (type UNKNOWN ERROR) to the client and displays a message on the server console.
        Parameters:
        request - The client's HttpServletRequest request object.
        response - The server's HttpServletResponse response object.
        clientMsg - Error message String to send to the client.
        serverMsg - Error message String to display on the server console.
        Throws:
        IOException
        javax.servlet.ServletException
      • doGetDAS

        public void doGetDAS​(ReqState rs)
                      throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The ReqState of this client request. Contains all kinds of important stuff.
        Throws:
        Exception
        See Also:
        ReqState
      • doGetDDS

        public void doGetDDS​(ReqState rs)
                      throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The ReqState of this client request. Contains all kinds of important stuff.
        Throws:
        Exception
        See Also:
        ReqState
      • doGetDDX

        public void doGetDDX​(ReqState rs)
                      throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The ReqState of this client request. Contains all kinds of important stuff.
        Throws:
        Exception
        See Also:
        ReqState
      • doGetBLOB

        public void doGetBLOB​(ReqState rs)
                       throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The ReqState of this client request. Contains all kinds of important stuff.
        Throws:
        Exception
        See Also:
        ReqState
      • doGetDAP2Data

        public void doGetDAP2Data​(ReqState rs)
                           throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The ReqState of this client request. Contains all kinds of important stuff.
        Throws:
        IOException
        javax.servlet.ServletException
        Exception
        See Also:
        ReqState
      • doGetDIR

        public void doGetDIR​(ReqState rs)
                      throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetDirHandler
      • doGetVER

        public void doGetVER​(ReqState rs)
                      throws Exception
        ************************************************************************ Default handler for the client's version request.

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

        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
      • doGetHELP

        public void doGetHELP​(ReqState rs)
                       throws Exception
        ************************************************************************ Default handler for the client's help request.

        Returns an html page of help info for the server

        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
      • badURL

        public void badURL​(ReqState rs)
                    throws Exception
        ************************************************************************ Sends an html document to the client explaining that they have used a poorly formed URL and then the help page...
        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
      • doGetASC

        public void doGetASC​(ReqState rs)
                      throws Exception
        ************************************************************************ Default 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

        Parameters:
        rs - the decoded Request State
        Throws:
        Exception
      • doGetINFO

        public void doGetINFO​(ReqState rs)
                       throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetInfoHandler
      • doGetHTML

        public void doGetHTML​(ReqState rs)
                       throws Exception
        ************************************************************************ Default 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.

        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetHTMLInterfaceHandler
      • doGetCatalog

        public void doGetCatalog​(ReqState rs)
                          throws Exception
        ************************************************************************ Default handler for OPeNDAP catalog.xml requests.
        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetHTMLInterfaceHandler
      • doDebug

        public void doDebug​(ReqState rs)
                     throws IOException
        ************************************************************************ Default handler for debug requests;
        Parameters:
        rs - The client's ReqState object.
        Throws:
        IOException
      • doGetSystemProps

        public void doGetSystemProps​(ReqState rs)
                              throws Exception
        ************************************************************************ Default handler for OPeNDAP status requests; not publically available, used only for debugging
        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetHTMLInterfaceHandler
      • doGetStatus

        public void doGetStatus​(ReqState rs)
                         throws Exception
        ************************************************************************ Default handler for OPeNDAP status requests; not publically available, used only for debugging
        Parameters:
        rs - The client's ReqState
        Throws:
        Exception
        See Also:
        GetHTMLInterfaceHandler
      • probeRequest

        public void probeRequest​(PrintWriter ps,
                                 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().

        Returns:
        A string containing the name of the servlet class that is running.
      • doGet

        public void doGet​(javax.servlet.http.HttpServletRequest request,
                          javax.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 AbstractServlet.

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

        protected ReqState getRequestState​(javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response)
                                    throws opendap.dap.DAP2Exception
        Parameters:
        request -
        Returns:
        the request state
        Throws:
        opendap.dap.DAP2Exception