Acme.Serve
Class Serve

java.lang.Object
  extended by Acme.Serve.Serve
All Implemented Interfaces:
java.io.Serializable, javax.servlet.ServletContext
Direct Known Subclasses:
TJWSServletServer.FileMappingServe

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

See Also:
Serialized Form

Nested Class Summary
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
protected  Serve.Acceptor acceptor
           
static java.lang.String ARG_ACCEPTOR_CLASS
           
static java.lang.String ARG_ACCESS_LOG_FMT
           
static java.lang.String ARG_ALIASES
           
static java.lang.String ARG_BACKLOG
           
static java.lang.String ARG_BINDADDRESS
           
static java.lang.String ARG_CGI_PATH
           
static java.lang.String ARG_ERR
           
static java.lang.String ARG_JSP
           
static java.lang.String ARG_KEEPALIVE
           
static java.lang.String ARG_KEEPALIVE_TIMEOUT
           
static java.lang.String ARG_LOG_DIR
           
static java.lang.String ARG_LOG_OPTIONS
           
static java.lang.String ARG_MAX_ACTIVE_SESSIONS
           
static java.lang.String ARG_MAX_CONN_USE
           
static java.lang.String ARG_NOHUP
           
static java.lang.String ARG_OUT
           
static java.lang.String ARG_PORT
           
static java.lang.String ARG_REALMS
           
static java.lang.String ARG_SERVLETS
           
static java.lang.String ARG_SESSION_PERSIST
           
static java.lang.String ARG_SESSION_SEED
           
static java.lang.String ARG_SESSION_TIMEOUT
           
static java.lang.String ARG_THREAD_POOL_SIZE
           
static java.lang.String ARG_THROTTLES
           
static java.lang.String ARG_WAR
           
static java.lang.String ARG_WORK_DIRECTORY
           
 java.util.Map arguments
           
protected  java.lang.Thread backgroundThread
           
static java.lang.String BGCOLOR
           
protected  java.util.List<Serve.ServeConnection> connections
           
static java.lang.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  java.lang.reflect.Constructor gzipInStreamConstr
           
protected  java.lang.String hostName
           
protected static int HTTP_MAX_HDR_LEN
           
protected  boolean initialized
           
protected  Acme.Serve.Serve.KeepAliveCleaner keepAliveCleaner
           
protected  java.lang.String keepAliveHdrParams
           
protected  Serve.PathTreeDictionary mappingtable
           
 java.util.Properties mime
           
protected  Serve.PathTreeDictionary realms
           
protected  Serve.PathTreeDictionary registry
           
protected  java.lang.ThreadGroup serverThreads
           
protected  Serve.HttpSessionContextImpl sessions
           
protected  java.util.concurrent.CountDownLatch shutdownLatch
           
protected  java.lang.Thread ssclThread
           
protected  Utils.ThreadPool threadPool
           
static java.lang.String UTF8
           
 
Constructor Summary
Serve()
          Default constructor to create TJWS as a bean
Serve(java.util.Map arguments, java.io.PrintStream logStream)
           
 
Method Summary
 void addDefaultServlets(java.lang.String cgi)
           
 void addDefaultServlets(java.lang.String cgi, java.lang.String throttles)
          Register a standard set of Servlets, with optional throttles.
 void addServlet(java.lang.String urlPat, javax.servlet.Servlet servlet)
          Register a Servlet.
 void addServlet(java.lang.String urlPat, javax.servlet.Servlet servlet, java.util.Hashtable initParams)
          Register a Servlet
 void addServlet(java.lang.String urlPat, java.lang.String className)
           
 void addServlet(java.lang.String urlPat, java.lang.String className, java.util.Hashtable initParams)
          Adds a servlet to run
protected  void addWarDeployer(java.lang.String deployerFactory, java.lang.String throttles)
           
protected  Serve.Acceptor createAcceptor()
           
 void destroyAllServlets()
           
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration getAttributeNames()
           
 javax.servlet.ServletContext getContext(java.lang.String uripath)
           
 java.lang.String getContextPath()
           
 java.lang.String getInitParameter(java.lang.String param)
           
 java.util.Enumeration getInitParameterNames()
           
protected  int getKeepAliveDuration()
           
protected  java.lang.String getKeepAliveParamStr()
           
 int getMajorVersion()
           
protected  int getMaxTimesConnectionUse()
           
 java.lang.String getMimeType(java.lang.String file)
           
 int getMinorVersion()
           
 javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
           
protected  java.io.File getPersistentFile()
           
 java.lang.String getRealPath(java.lang.String path)
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String urlpath)
           
 java.net.URL getResource(java.lang.String path)
          Returns a URL to the resource that is mapped to a specified path.
 java.io.InputStream getResourceAsStream(java.lang.String path)
          Returns the resource located at the named path as an InputStream object.
 java.util.Set getResourcePaths(java.lang.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.
 java.lang.String getServerInfo()
           
 javax.servlet.Servlet getServlet(java.lang.String name)
           
 java.lang.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.
 java.util.Enumeration getServletNames()
           
 java.util.Enumeration getServlets()
           
 void init()
           
protected  void initMime()
           
protected  boolean isAccessLogged()
           
protected  boolean isKeepAlive()
           
protected  boolean isShowReferer()
           
protected  boolean isShowUserAgent()
           
 void log(java.lang.Exception exception, java.lang.String message)
           
 void log(java.lang.String message)
           
 void log(java.lang.String message, java.lang.Throwable throwable)
           
 void notifyStop()
          Tells the server to stop
 void removeAttribute(java.lang.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(java.lang.String name, java.lang.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(java.lang.String urlPat)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARG_PORT

public static final java.lang.String ARG_PORT
See Also:
Constant Field Values

ARG_THROTTLES

public static final java.lang.String ARG_THROTTLES
See Also:
Constant Field Values

ARG_SERVLETS

public static final java.lang.String ARG_SERVLETS
See Also:
Constant Field Values

ARG_REALMS

public static final java.lang.String ARG_REALMS
See Also:
Constant Field Values

ARG_ALIASES

public static final java.lang.String ARG_ALIASES
See Also:
Constant Field Values

ARG_BINDADDRESS

public static final java.lang.String ARG_BINDADDRESS
See Also:
Constant Field Values

ARG_BACKLOG

public static final java.lang.String ARG_BACKLOG
See Also:
Constant Field Values

ARG_CGI_PATH

public static final java.lang.String ARG_CGI_PATH
See Also:
Constant Field Values

ARG_ERR

public static final java.lang.String ARG_ERR
See Also:
Constant Field Values

ARG_OUT

public static final java.lang.String ARG_OUT
See Also:
Constant Field Values

ARG_SESSION_TIMEOUT

public static final java.lang.String ARG_SESSION_TIMEOUT
See Also:
Constant Field Values

ARG_LOG_DIR

public static final java.lang.String ARG_LOG_DIR
See Also:
Constant Field Values

ARG_LOG_OPTIONS

public static final java.lang.String ARG_LOG_OPTIONS
See Also:
Constant Field Values

ARG_NOHUP

public static final java.lang.String ARG_NOHUP
See Also:
Constant Field Values

ARG_JSP

public static final java.lang.String ARG_JSP
See Also:
Constant Field Values

ARG_WAR

public static final java.lang.String ARG_WAR
See Also:
Constant Field Values

ARG_KEEPALIVE

public static final java.lang.String ARG_KEEPALIVE
See Also:
Constant Field Values

DEF_LOGENCODING

public static final java.lang.String DEF_LOGENCODING
See Also:
Constant Field Values

ARG_KEEPALIVE_TIMEOUT

public static final java.lang.String ARG_KEEPALIVE_TIMEOUT
See Also:
Constant Field Values

ARG_MAX_CONN_USE

public static final java.lang.String ARG_MAX_CONN_USE
See Also:
Constant Field Values

ARG_SESSION_PERSIST

public static final java.lang.String ARG_SESSION_PERSIST
See Also:
Constant Field Values

ARG_MAX_ACTIVE_SESSIONS

public static final java.lang.String ARG_MAX_ACTIVE_SESSIONS
See Also:
Constant Field Values

ARG_ACCESS_LOG_FMT

public static final java.lang.String ARG_ACCESS_LOG_FMT
See Also:
Constant Field Values

ARG_ACCEPTOR_CLASS

public static final java.lang.String ARG_ACCEPTOR_CLASS
See Also:
Constant Field Values

ARG_WORK_DIRECTORY

public static final java.lang.String ARG_WORK_DIRECTORY
See Also:
Constant Field Values

ARG_SESSION_SEED

public static final java.lang.String ARG_SESSION_SEED
See Also:
Constant Field Values

ARG_THREAD_POOL_SIZE

public static final java.lang.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 java.lang.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 java.lang.String UTF8
See Also:
Constant Field Values

hostName

protected java.lang.String hostName

keepAliveHdrParams

protected java.lang.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 java.lang.ThreadGroup serverThreads

threadPool

protected transient Utils.ThreadPool threadPool

gzipInStreamConstr

protected transient java.lang.reflect.Constructor gzipInStreamConstr

sessions

protected Serve.HttpSessionContextImpl sessions

expiredIn

protected int expiredIn

arguments

public java.util.Map arguments

mime

public java.util.Properties mime

connections

protected java.util.List<Serve.ServeConnection> connections

acceptor

protected transient Serve.Acceptor acceptor

ssclThread

protected transient java.lang.Thread ssclThread

initialized

protected transient boolean initialized

shutdownLatch

protected java.util.concurrent.CountDownLatch shutdownLatch

backgroundThread

protected java.lang.Thread backgroundThread
Constructor Detail

Serve

public Serve(java.util.Map arguments,
             java.io.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 java.lang.String getKeepAliveParamStr()

getMaxTimesConnectionUse

protected int getMaxTimesConnectionUse()

initMime

protected void initMime()

addServlet

public void addServlet(java.lang.String urlPat,
                       java.lang.String className)

addServlet

public void addServlet(java.lang.String urlPat,
                       java.lang.String className,
                       java.util.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(java.lang.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.

Parameters:
urlPat - servlet invoker URL pattern
servlet - already instantiated servlet but init

addServlet

public void addServlet(java.lang.String urlPat,
                       javax.servlet.Servlet servlet,
                       java.util.Hashtable initParams)
Register a Servlet

Parameters:
urlPat -
servlet -
initParams -

unloadServlet

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

unloadServlet

public void unloadServlet(java.lang.String urlPat)

addDefaultServlets

public void addDefaultServlets(java.lang.String cgi)

addDefaultServlets

public void addDefaultServlets(java.lang.String cgi,
                               java.lang.String throttles)
                        throws java.io.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:

Parameters:
cgi - whether to run CGI programs
throttles - filename to read FileServlet throttle settings from, can be null
Throws:
java.io.IOException

addWarDeployer

protected void addWarDeployer(java.lang.String deployerFactory,
                              java.lang.String throttles)

getPersistentFile

protected java.io.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 java.io.IOException
Throws:
java.io.IOException

notifyStop

public void notifyStop()
                throws java.io.IOException
Tells the server to stop

Throws:
java.io.IOException

createAcceptor

protected Serve.Acceptor createAcceptor()
                                 throws java.io.IOException
Throws:
java.io.IOException

getServlet

public javax.servlet.Servlet getServlet(java.lang.String name)
Specified by:
getServlet in interface javax.servlet.ServletContext

getServlets

public java.util.Enumeration getServlets()
Specified by:
getServlets in interface javax.servlet.ServletContext

getServletNames

public java.util.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(java.lang.String message)
Specified by:
log in interface javax.servlet.ServletContext

log

public void log(java.lang.String message,
                java.lang.Throwable throwable)
Specified by:
log in interface javax.servlet.ServletContext

log

public void log(java.lang.Exception exception,
                java.lang.String message)
Specified by:
log in interface javax.servlet.ServletContext

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Specified by:
getRealPath in interface javax.servlet.ServletContext

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface javax.servlet.ServletContext
Returns:

getMimeType

public java.lang.String getMimeType(java.lang.String file)
Specified by:
getMimeType in interface javax.servlet.ServletContext

getServerInfo

public java.lang.String getServerInfo()
Specified by:
getServerInfo in interface javax.servlet.ServletContext

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface javax.servlet.ServletContext

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface javax.servlet.ServletContext

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object object)
Specified by:
setAttribute in interface javax.servlet.ServletContext

getAttributeNames

public java.util.Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletContext

getContext

public javax.servlet.ServletContext getContext(java.lang.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 java.util.Set getResourcePaths(java.lang.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 java.lang.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 java.net.URL getResource(java.lang.String path)
                         throws java.net.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:
java.net.MalformedURLException - if the pathname is not given in the correct form

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.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(java.lang.String urlpath)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletContext

getInitParameter

public java.lang.String getInitParameter(java.lang.String param)
Specified by:
getInitParameter in interface javax.servlet.ServletContext

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Specified by:
getInitParameterNames in interface javax.servlet.ServletContext

getNamedDispatcher

public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String name)
Specified by:
getNamedDispatcher in interface javax.servlet.ServletContext


Copyright © 2010. All Rights Reserved.