Acme.Serve

## Class Serve

- java.lang.Object
- - Acme.Serve.Serve

- All Implemented Interfaces:
    Serializable, javax.servlet.ServletContext
  Direct Known Subclasses:
    TJWSServletServer.FileMappingServe

      public class Serve
      extends Object
      implements javax.servlet.ServletContext, Serializable

  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `Serve.AcceptLocaleEnumeration`
    `static interface` | `Serve.Acceptor`
    `static class` | `Serve.AcmeSession` Http session support TODO: provide lazy session restoring, it should allow to load classes from wars 1st step it read serialization data and store under session attribute 2nd when the session requested, it tries to deserialize all session attributes considered that all classes available
    `protected static class` | `Serve.BasicAuthRealm`
    `protected static class` | `Serve.HttpSessionContextImpl`
    `protected static class` | `Serve.LocaleWithWeight`
    `static class` | `Serve.PathTreeDictionary` Class PathTreeDictionary - this class allows to put path elements in format n1/n2/n2[/*.ext] and get match to a pattern and a unmatched tail
    `protected static class` | `Serve.ServeConfig`
    `static class` | `Serve.ServeConnection` provides request/response
    `static class` | `Serve.ServeInputStream`
    `static class` | `Serve.ServeOutputStream`
    `protected class` | `Serve.SimpleRequestDispatcher`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Serve.Acceptor` | `acceptor`
    `static String` | `ARG_ACCEPTOR_CLASS`
    `static String` | `ARG_ACCESS_LOG_FMT`
    `static String` | `ARG_ALIASES`
    `static String` | `ARG_BACKLOG`
    `static String` | `ARG_BINDADDRESS`
    `static String` | `ARG_CGI_PATH`
    `static String` | `ARG_ERR`
    `static String` | `ARG_JSP`
    `static String` | `ARG_KEEPALIVE`
    `static String` | `ARG_KEEPALIVE_TIMEOUT`
    `static String` | `ARG_LOG_DIR`
    `static String` | `ARG_LOG_OPTIONS`
    `static String` | `ARG_MAX_ACTIVE_SESSIONS`
    `static String` | `ARG_MAX_CONN_USE`
    `static String` | `ARG_NOHUP`
    `static String` | `ARG_OUT`
    `static String` | `ARG_PORT`
    `static String` | `ARG_REALMS`
    `static String` | `ARG_SERVLETS`
    `static String` | `ARG_SESSION_PERSIST`
    `static String` | `ARG_SESSION_SEED`
    `static String` | `ARG_SESSION_TIMEOUT`
    `static String` | `ARG_THREAD_POOL_SIZE`
    `static String` | `ARG_THROTTLES`
    `static String` | `ARG_WAR`
    `static String` | `ARG_WORK_DIRECTORY`
    `Map` | `arguments`
    `protected Thread` | `backgroundThread`
    `static String` | `BGCOLOR`
    `protected List<Serve.ServeConnection>` | `connections`
    `static String` | `DEF_LOGENCODING`
    `protected static int` | `DEF_MAX_CONN_USE` max number of alive connections default value
    `protected static int` | `DEF_MIN_ACT_SESS`
    `static int` | `DEF_PORT`
    `protected static int` | `DEF_SESSION_TIMEOUT`
    `protected static int` | `DESTROY_TIME_SEC`
    `protected int` | `expiredIn`
    `protected Constructor` | `gzipInStreamConstr`
    `protected String` | `hostName`
    `protected static int` | `HTTP_MAX_HDR_LEN`
    `protected boolean` | `initialized`
    `protected Acme.Serve.Serve.KeepAliveCleaner` | `keepAliveCleaner`
    `protected String` | `keepAliveHdrParams`
    `protected Serve.PathTreeDictionary` | `mappingtable`
    `Properties` | `mime`
    `protected Serve.PathTreeDictionary` | `realms`
    `protected Serve.PathTreeDictionary` | `registry`
    `protected ThreadGroup` | `serverThreads`
    `protected Serve.HttpSessionContextImpl` | `sessions`
    `protected CountDownLatch` | `shutdownLatch`
    `protected Thread` | `ssclThread`
    `protected Utils.ThreadPool` | `threadPool`
    `static String` | `UTF8`

    - ### Fields inherited from interface javax.servlet.ServletContext

      `ORDERED_LIBS, TEMPDIR`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Serve()` Default constructor to create TJWS as a bean
    `Serve(Map arguments, PrintStream logStream)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDefaultServlets(String cgi)`
    `void` | `addDefaultServlets(String cgi, String throttles)` Register a standard set of Servlets, with optional throttles.
    `void` | `addServlet(String urlPat, javax.servlet.Servlet servlet)` Register a Servlet.
    `void` | `addServlet(String urlPat, javax.servlet.Servlet servlet, Hashtable initParams)` Register a Servlet
    `void` | `addServlet(String urlPat, String className)`
    `void` | `addServlet(String urlPat, String className, Hashtable initParams)` Adds a servlet to run
    `protected void` | `addWarDeployer(String deployerFactory, String throttles)`
    `protected Serve.Acceptor` | `createAcceptor()`
    `void` | `destroyAllServlets()`
    `Object` | `getAttribute(String name)`
    `Enumeration` | `getAttributeNames()`
    `javax.servlet.ServletContext` | `getContext(String uripath)`
    `String` | `getContextPath()`
    `String` | `getInitParameter(String param)`
    `Enumeration` | `getInitParameterNames()`
    `protected int` | `getKeepAliveDuration()`
    `protected String` | `getKeepAliveParamStr()`
    `int` | `getMajorVersion()`
    `protected int` | `getMaxTimesConnectionUse()`
    `String` | `getMimeType(String file)`
    `int` | `getMinorVersion()`
    `javax.servlet.RequestDispatcher` | `getNamedDispatcher(String name)`
    `protected File` | `getPersistentFile()`
    `String` | `getRealPath(String path)`
    `javax.servlet.RequestDispatcher` | `getRequestDispatcher(String urlpath)`
    `URL` | `getResource(String path)` Returns a URL to the resource that is mapped to a specified path.
    `InputStream` | `getResourceAsStream(String path)` Returns the resource located at the named path as an `InputStream` object.
    `Set` | `getResourcePaths(String path)` Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.
    `String` | `getServerInfo()`
    `javax.servlet.Servlet` | `getServlet(String name)`
    `String` | `getServletContextName()` Returns the name of this web application correponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.
    `Enumeration` | `getServletNames()`
    `Enumeration` | `getServlets()`
    `void` | `init()`
    `protected void` | `initMime()`
    `protected boolean` | `isAccessLogged()`
    `protected boolean` | `isKeepAlive()`
    `protected boolean` | `isShowReferer()`
    `protected boolean` | `isShowUserAgent()`
    `void` | `log(Exception exception, String message)`
    `void` | `log(String message)`
    `void` | `log(String message, Throwable throwable)`
    `void` | `notifyStop()` Tells the server to stop
    `void` | `removeAttribute(String name)`
    `void` | `runInBackground()`
    `int` | `serve()` Launches the server It doesn't exist until server runs, so start it in a dedicated thread.
    `protected void` | `setAccessLogged()`
    `void` | `setAttribute(String name, Object object)`
    `protected void` | `setMappingTable(Serve.PathTreeDictionary mappingtable)`
    `protected void` | `setRealms(Serve.PathTreeDictionary realms)`
    `void` | `stopBackground()`
    `javax.servlet.Servlet` | `unloadServlet(javax.servlet.Servlet servlet)`
    `void` | `unloadServlet(String urlPat)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface javax.servlet.ServletContext

      `addFilter, addFilter, addFilter, addListener, addListener, addListener, addServlet, createFilter, createListener, createServlet, declareRoles, getClassLoader, getDefaultSessionTrackingModes, getEffectiveMajorVersion, getEffectiveMinorVersion, getEffectiveSessionTrackingModes, getFilterRegistration, getFilterRegistrations, getJspConfigDescriptor, getServletRegistration, getServletRegistrations, getSessionCookieConfig, getVirtualServerName, setInitParameter, setSessionTrackingModes`

- - ### Field Detail

    - #### ARG_PORT

          public static final String ARG_PORT

      See Also:
        Constant Field Values

    - #### ARG_THROTTLES

          public static final String ARG_THROTTLES

      See Also:
        Constant Field Values

    - #### ARG_SERVLETS

          public static final String ARG_SERVLETS

      See Also:
        Constant Field Values

    - #### ARG_REALMS

          public static final String ARG_REALMS

      See Also:
        Constant Field Values

    - #### ARG_ALIASES

          public static final String ARG_ALIASES

      See Also:
        Constant Field Values

    - #### ARG_BINDADDRESS

          public static final String ARG_BINDADDRESS

      See Also:
        Constant Field Values

    - #### ARG_BACKLOG

          public static final String ARG_BACKLOG

      See Also:
        Constant Field Values

    - #### ARG_CGI_PATH

          public static final String ARG_CGI_PATH

      See Also:
        Constant Field Values

    - #### ARG_ERR

          public static final String ARG_ERR

      See Also:
        Constant Field Values

    - #### ARG_OUT

          public static final String ARG_OUT

      See Also:
        Constant Field Values

    - #### ARG_SESSION_TIMEOUT

          public static final String ARG_SESSION_TIMEOUT

      See Also:
        Constant Field Values

    - #### ARG_LOG_DIR

          public static final String ARG_LOG_DIR

      See Also:
        Constant Field Values

    - #### ARG_LOG_OPTIONS

          public static final String ARG_LOG_OPTIONS

      See Also:
        Constant Field Values

    - #### ARG_NOHUP

          public static final String ARG_NOHUP

      See Also:
        Constant Field Values

    - #### ARG_JSP

          public static final String ARG_JSP

      See Also:
        Constant Field Values

    - #### ARG_WAR

          public static final String ARG_WAR

      See Also:
        Constant Field Values

    - #### ARG_KEEPALIVE

          public static final String ARG_KEEPALIVE

      See Also:
        Constant Field Values

    - #### DEF_LOGENCODING

          public static final String DEF_LOGENCODING

      See Also:
        Constant Field Values

    - #### ARG_KEEPALIVE_TIMEOUT

          public static final String ARG_KEEPALIVE_TIMEOUT

      See Also:
        Constant Field Values

    - #### ARG_MAX_CONN_USE

          public static final String ARG_MAX_CONN_USE

      See Also:
        Constant Field Values

    - #### ARG_SESSION_PERSIST

          public static final String ARG_SESSION_PERSIST

      See Also:
        Constant Field Values

    - #### ARG_MAX_ACTIVE_SESSIONS

          public static final String ARG_MAX_ACTIVE_SESSIONS

      See Also:
        Constant Field Values

    - #### ARG_ACCESS_LOG_FMT

          public static final String ARG_ACCESS_LOG_FMT

      See Also:
        Constant Field Values

    - #### ARG_ACCEPTOR_CLASS

          public static final String ARG_ACCEPTOR_CLASS

      See Also:
        Constant Field Values

    - #### ARG_WORK_DIRECTORY

          public static final String ARG_WORK_DIRECTORY

      See Also:
        Constant Field Values

    - #### ARG_SESSION_SEED

          public static final String ARG_SESSION_SEED

      See Also:
        Constant Field Values

    - #### ARG_THREAD_POOL_SIZE

          public static final String ARG_THREAD_POOL_SIZE

      See Also:
        Constant Field Values

    - #### DEF_SESSION_TIMEOUT

          protected static final int DEF_SESSION_TIMEOUT

      See Also:
        Constant Field Values

    - #### DEF_MIN_ACT_SESS

          protected static final int DEF_MIN_ACT_SESS

      See Also:
        Constant Field Values

    - #### DESTROY_TIME_SEC

          protected static final int DESTROY_TIME_SEC

      See Also:
        Constant Field Values

    - #### HTTP_MAX_HDR_LEN

          protected static final int HTTP_MAX_HDR_LEN

      See Also:
        Constant Field Values

    - #### DEF_PORT

          public static final int DEF_PORT

      See Also:
        Constant Field Values

    - #### BGCOLOR

          public static final String BGCOLOR

      See Also:
        Constant Field Values

    - #### DEF_MAX_CONN_USE

          protected static final int DEF_MAX_CONN_USE

      max number of alive connections default value
      See Also:
        Constant Field Values

    - #### UTF8

          public static final String UTF8

      See Also:
        Constant Field Values

    - #### hostName

          protected String hostName

    - #### keepAliveHdrParams

          protected String keepAliveHdrParams

    - #### registry

          protected transient Serve.PathTreeDictionary registry

    - #### realms

          protected transient Serve.PathTreeDictionary realms

    - #### mappingtable

          protected transient Serve.PathTreeDictionary mappingtable

    - #### keepAliveCleaner

          protected transient Acme.Serve.Serve.KeepAliveCleaner keepAliveCleaner

    - #### serverThreads

          protected transient ThreadGroup serverThreads

    - #### threadPool

          protected transient Utils.ThreadPool threadPool

    - #### gzipInStreamConstr

          protected transient Constructor gzipInStreamConstr

    - #### sessions

          protected Serve.HttpSessionContextImpl sessions

    - #### expiredIn

          protected int expiredIn

    - #### arguments

          public Map arguments

    - #### mime

          public Properties mime

    - #### connections

          protected List<Serve.ServeConnection> connections

    - #### acceptor

          protected transient Serve.Acceptor acceptor

    - #### ssclThread

          protected transient Thread ssclThread

    - #### initialized

          protected transient boolean initialized

    - #### shutdownLatch

          protected CountDownLatch shutdownLatch

    - #### backgroundThread

          protected Thread backgroundThread

  - ### Constructor Detail

    - #### Serve

          public Serve(Map arguments,
               PrintStream logStream)

    - #### Serve

          public Serve()

      Default constructor to create TJWS as a bean

  - ### Method Detail

    - #### setAccessLogged

          protected void setAccessLogged()

    - #### isAccessLogged

          protected boolean isAccessLogged()

    - #### isShowReferer

          protected boolean isShowReferer()

    - #### isShowUserAgent

          protected boolean isShowUserAgent()

    - #### isKeepAlive

          protected boolean isKeepAlive()

    - #### getKeepAliveDuration

          protected int getKeepAliveDuration()

    - #### getKeepAliveParamStr

          protected String getKeepAliveParamStr()

    - #### getMaxTimesConnectionUse

          protected int getMaxTimesConnectionUse()

    - #### initMime

          protected void initMime()

    - #### addServlet

          public void addServlet(String urlPat,
                        String className)

      Specified by:
        `addServlet` in interface `javax.servlet.ServletContext`

    - #### addServlet

          public void addServlet(String urlPat,
                        String className,
                        Hashtable initParams)

      Adds a servlet to run
      Parameters:
        `urlPat` - servlet invoker URL pattern
        `className` - servlet class name
        `initParams` - servlet init parameters

    - #### addServlet

          public void addServlet(String urlPat,
                        javax.servlet.Servlet servlet)

      Register a Servlet. Registration consists of a URL pattern, which can contain wildcards, and the Servlet to launch when a matching URL comes in. Patterns are checked for matches in the order they were added, and only the first match is run.
      Specified by:
        `addServlet` in interface `javax.servlet.ServletContext`
      Parameters:
        `urlPat` - servlet invoker URL pattern
        `servlet` - already instantiated servlet but init

    - #### addServlet

          public void addServlet(String urlPat,
                        javax.servlet.Servlet servlet,
                        Hashtable initParams)

      Register a Servlet
      Parameters:
        `urlPat` -
        `servlet` -
        `initParams` -

    - #### unloadServlet

          public javax.servlet.Servlet unloadServlet(javax.servlet.Servlet servlet)

    - #### unloadServlet

          public void unloadServlet(String urlPat)

    - #### addDefaultServlets

          public void addDefaultServlets(String cgi)

    - #### addDefaultServlets

          public void addDefaultServlets(String cgi,
                                String throttles)
                                  throws IOException

      Register a standard set of Servlets, with optional throttles. These will return files or directory listings, and run CGI programs, much like a standard HTTP server.

      Because of the pattern checking order, this should be called after you've added any custom Servlets.

      The current set of default servlet mappings:
      - If enabled, *.cgi goes to CgiServlet, and gets run as a CGI program.
      - * goes to FileServlet, and gets served up as a file or directory.
      Parameters:
        `cgi` - whether to run CGI programs
        `throttles` - filename to read FileServlet throttle settings from, can be null
      Throws:
        `IOException`

    - #### addWarDeployer

          protected void addWarDeployer(String deployerFactory,
                            String throttles)

    - #### getPersistentFile

          protected File getPersistentFile()

    - #### runInBackground

          public void runInBackground()

    - #### stopBackground

          public void stopBackground()

    - #### serve

          public int serve()

      Launches the server It doesn't exist until server runs, so start it in a dedicated thread.
      Returns:
        0 if the server successfully terminated, 1 if it can't be started and -1 if it was terminated during some errors

    - #### init

          public void init()
                    throws IOException

      Throws:
        `IOException`

    - #### notifyStop

          public void notifyStop()
                          throws IOException

      Tells the server to stop
      Throws:
        `IOException`

    - #### createAcceptor

          protected Serve.Acceptor createAcceptor()
                                           throws IOException

      Throws:
        `IOException`

    - #### getServlet

          public javax.servlet.Servlet getServlet(String name)

      Specified by:
        `getServlet` in interface `javax.servlet.ServletContext`

    - #### getServlets

          public Enumeration getServlets()

      Specified by:
        `getServlets` in interface `javax.servlet.ServletContext`

    - #### getServletNames

          public Enumeration getServletNames()

      Specified by:
        `getServletNames` in interface `javax.servlet.ServletContext`

    - #### destroyAllServlets

          public void destroyAllServlets()

    - #### setMappingTable

          protected void setMappingTable(Serve.PathTreeDictionary mappingtable)

    - #### setRealms

          protected void setRealms(Serve.PathTreeDictionary realms)

    - #### log

          public void log(String message)

      Specified by:
        `log` in interface `javax.servlet.ServletContext`

    - #### log

          public void log(String message,
                 Throwable throwable)

      Specified by:
        `log` in interface `javax.servlet.ServletContext`

    - #### log

          public void log(Exception exception,
                 String message)

      Specified by:
        `log` in interface `javax.servlet.ServletContext`

    - #### getRealPath

          public String getRealPath(String path)

      Specified by:
        `getRealPath` in interface `javax.servlet.ServletContext`

    - #### getContextPath

          public String getContextPath()

      Specified by:
        `getContextPath` in interface `javax.servlet.ServletContext`
      Returns:

    - #### getMimeType

          public String getMimeType(String file)

      Specified by:
        `getMimeType` in interface `javax.servlet.ServletContext`

    - #### getServerInfo

          public String getServerInfo()

      Specified by:
        `getServerInfo` in interface `javax.servlet.ServletContext`

    - #### getAttribute

          public Object getAttribute(String name)

      Specified by:
        `getAttribute` in interface `javax.servlet.ServletContext`

    - #### removeAttribute

          public void removeAttribute(String name)

      Specified by:
        `removeAttribute` in interface `javax.servlet.ServletContext`

    - #### setAttribute

          public void setAttribute(String name,
                          Object object)

      Specified by:
        `setAttribute` in interface `javax.servlet.ServletContext`

    - #### getAttributeNames

          public Enumeration getAttributeNames()

      Specified by:
        `getAttributeNames` in interface `javax.servlet.ServletContext`

    - #### getContext

          public javax.servlet.ServletContext getContext(String uripath)

      Specified by:
        `getContext` in interface `javax.servlet.ServletContext`

    - #### getMajorVersion

          public int getMajorVersion()

      Specified by:
        `getMajorVersion` in interface `javax.servlet.ServletContext`

    - #### getMinorVersion

          public int getMinorVersion()

      Specified by:
        `getMinorVersion` in interface `javax.servlet.ServletContext`

    - #### getResourcePaths

          public Set getResourcePaths(String path)

      Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. Paths indicating subdirectory paths end with a '/'. The returned paths are all relative to the root of the web application and have a leading '/'. For example, for a web application containing

      /welcome.html
      /catalog/index.html
      /catalog/products.html
      /catalog/offers/books.html
      /catalog/offers/music.html
      /customer/login.jsp
      /WEB-INF/web.xml
      /WEB-INF/classes/com.acme.OrderServlet.class,

      getResourcePaths("/") returns {"/welcome.html", "/catalog/", "/customer/", "/WEB-INF/"}
      getResourcePaths("/catalog/") returns {"/catalog/index.html", "/catalog/products.html", "/catalog/offers/"}.

      Specified by:
        `getResourcePaths` in interface `javax.servlet.ServletContext`
      Parameters:
        `the` - - partial path used to match the resources, which must start with a /
      Returns:
        a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.
      Since:
        Servlet 2.3

    - #### getServletContextName

          public String getServletContextName()

      Returns the name of this web application correponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element.
      Specified by:
        `getServletContextName` in interface `javax.servlet.ServletContext`
      Returns:
        The name of the web application or null if no name has been declared in the deployment descriptor.
      Since:
        Servlet 2.3

    - #### getResource

          public URL getResource(String path)
                          throws MalformedURLException

      Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

      This method allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a `.war` file.

      The servlet container must implement the URL handlers and `URLConnection` objects that are necessary to access the resource.

      This method returns `null` if no resource is mapped to the pathname.

      Some containers may allow writing to the URL returned by this method using the methods of the URL class.

      The resource content is returned directly, so be aware that requesting a `.jsp` page returns the JSP source code. Use a `RequestDispatcher` instead to include results of an execution.

      This method has a different purpose than `java.lang.Class.getResource`, which looks up resources based on a class loader. This method does not use class loaders.
      Specified by:
        `getResource` in interface `javax.servlet.ServletContext`
      Parameters:
        `path` - a `String` specifying the path to the resource
      Returns:
        the resource located at the named path, or `null` if there is no resource at that path
      Throws:
        `MalformedURLException` - if the pathname is not given in the correct form

    - #### getResourceAsStream

          public InputStream getResourceAsStream(String path)

      Returns the resource located at the named path as an `InputStream` object.

      The data in the `InputStream` can be of any type or length. The path must be specified according to the rules given in `getResource`. This method returns `null` if no resource exists at the specified path.

      Meta-information such as content length and content type that is available via `getResource` method is lost when using this method.

      The servlet container must implement the URL handlers and `URLConnection` objects necessary to access the resource.

      This method is different from `java.lang.Class.getResourceAsStream`, which uses a class loader. This method allows servlet containers to make a resource available to a servlet from any location, without using a class loader.
      Specified by:
        `getResourceAsStream` in interface `javax.servlet.ServletContext`
      Parameters:
        `path` - a `String` specifying the path to the resource
      Returns:
        the `InputStream` returned to the servlet, or `null` if no resource exists at the specified path

    - #### getRequestDispatcher

          public javax.servlet.RequestDispatcher getRequestDispatcher(String urlpath)

      Specified by:
        `getRequestDispatcher` in interface `javax.servlet.ServletContext`

    - #### getInitParameter

          public String getInitParameter(String param)

      Specified by:
        `getInitParameter` in interface `javax.servlet.ServletContext`

    - #### getInitParameterNames

          public Enumeration getInitParameterNames()

      Specified by:
        `getInitParameterNames` in interface `javax.servlet.ServletContext`

    - #### getNamedDispatcher

          public javax.servlet.RequestDispatcher getNamedDispatcher(String name)

      Specified by:
        `getNamedDispatcher` in interface `javax.servlet.ServletContext`

Copyright © 2014. All Rights Reserved.