SK.gnome.dwarf.http
Class ServletWrapper

java.lang.Object
  extended bySK.gnome.dwarf.GenericService
      extended bySK.gnome.dwarf.GenericServer
          extended bySK.gnome.dwarf.http.ServletWrapper
All Implemented Interfaces:
SK.gnome.dwarf.Reportable, SK.gnome.dwarf.Server, SK.gnome.dwarf.Service, javax.servlet.ServletConfig

public class ServletWrapper
extends SK.gnome.dwarf.GenericServer
implements javax.servlet.ServletConfig

This class wraps the servlet instances.

This class implements the javax.servlet.ServletConfig interface, which provides a way how to configure the servlet environment. Each servlet object must be wrapped by an instance of this class in order to be added to the Application.


Field Summary
protected  SK.gnome.dwarf.utils.cache.Cache cache
          The cache instance.
protected  SK.gnome.dwarf.utils.Counter counter
          The servlet statistics.
protected  java.lang.String mapping
          The servlet mapping.
protected  javax.servlet.Servlet servlet
          The servlet instance.
protected  java.lang.String servletClass
          The servlet class.
 
Fields inherited from class SK.gnome.dwarf.GenericService
initParameters, parent
 
Fields inherited from interface SK.gnome.dwarf.Service
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED
 
Constructor Summary
ServletWrapper(java.lang.String name)
          Creates a new ServletWrapper.
 
Method Summary
 void addService(SK.gnome.dwarf.Service service)
          Adds a service to the server.
 SK.gnome.dwarf.utils.cache.Cache getCache()
          Returns the cache instance.
 java.lang.String getInitParameter(java.lang.String name)
          Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
 java.util.Enumeration getInitParameterNames()
          Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.
 java.lang.String getMapping()
          Returns the servlet path mapping.
 javax.servlet.ServletContext getServletContext()
          Returns a reference to the ServletContext in which the servlet is executing.
 java.lang.String getServletName()
          Returns the name of this servlet instance.
protected  int getShutdownTimeout()
          Returns the shutdown timeout.
 void init(SK.gnome.dwarf.Server parent)
          Initializes the service.
 java.lang.String report()
          Returns the service report.
 void service(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
          Services the request.
 void setMapping(java.lang.String mapping)
          Sets the servlet mapping.
 void setServletClass(java.lang.String servletClass)
          Sets the servlet class.
 void shutdown()
          Shuts down the service.
 
Methods inherited from class SK.gnome.dwarf.GenericServer
addService, getAuthenticator, getLogger, getParameters, getService, getServices, getServices, removeService, start, stop
 
Methods inherited from class SK.gnome.dwarf.GenericService
getAuthFacility, getFullName, getLogFacility, getName, getPrincipal, getState, log, log, login, logout, setAuthFacility, setInitParameters, setLogFacility, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface SK.gnome.dwarf.Service
getFullName, getName, getState, log, log, login, logout
 

Field Detail

servletClass

protected java.lang.String servletClass
The servlet class.

See Also:
setServletClass(String)

servlet

protected javax.servlet.Servlet servlet
The servlet instance.


mapping

protected java.lang.String mapping
The servlet mapping.

Contains mapping between the URL patterns and servlets. The list of URL patterns separated by commas may be specified instead of a single pattern.

See Also:
setMapping(String)

cache

protected SK.gnome.dwarf.utils.cache.Cache cache
The cache instance.

Contains a reference to the SK.gnome.dwarf.utils.cache.Cache implementation if it is contained by the servlet wrapper. The derived classes should feel free to use it for any purpose.

The field value is initialized in the addService method.


counter

protected SK.gnome.dwarf.utils.Counter counter
The servlet statistics.

Contains the current/peak/total number of requests served by this servlet since it was initialized.

Constructor Detail

ServletWrapper

public ServletWrapper(java.lang.String name)
Creates a new ServletWrapper.

Method Detail

setServletClass

public void setServletClass(java.lang.String servletClass)
Sets the servlet class.

Parameters:
servletClass - the class
See Also:
servletClass

setMapping

public void setMapping(java.lang.String mapping)
Sets the servlet mapping.

Parameters:
mapping - the mapping
See Also:
mapping

getMapping

public java.lang.String getMapping()
Returns the servlet path mapping.

Returns:
the mapping
See Also:
mapping

getCache

public SK.gnome.dwarf.utils.cache.Cache getCache()
Returns the cache instance.

Returns:
the cache
See Also:
cache

addService

public void addService(SK.gnome.dwarf.Service service)
                throws SK.gnome.dwarf.ServiceException
Adds a service to the server.

If the service being added to the ServletWrapper is an implementation of the SK.gnome.dwarf.util.Cache interface, it is stored also in the cache field.

The method does not allow to add a service implementing the Parameters interface since the HTTPParameters must be inherited from the HTTP server object.

Specified by:
addService in interface SK.gnome.dwarf.Server
Throws:
SK.gnome.dwarf.ServiceException

init

public void init(SK.gnome.dwarf.Server parent)
          throws SK.gnome.dwarf.ServiceException
Initializes the service.

It loads and initializes the servlet instance according to the value of the servletClass field. Any exception throwed by the servlet's init method is catched and forwarded as the ServiceException.

Specified by:
init in interface SK.gnome.dwarf.Service
Throws:
SK.gnome.dwarf.ServiceException

shutdown

public void shutdown()
Shuts down the service.

It waits for all requests being currently serviced by the servlet to complete, then destroys the servlet instance by invoking its destroy method.

Specified by:
shutdown in interface SK.gnome.dwarf.Service

getShutdownTimeout

protected int getShutdownTimeout()
Returns the shutdown timeout.

It returns the Constants.DEFAULT_SHUTDOWN_TIMEOUT value if the persistent connections are not enabled, or the value returned from the getKeepAliveTimeout method in the opposit case.


report

public java.lang.String report()
Returns the service report.

Returns the servlet class, init parameters and current/peak/total number of requests serviced by the servlet so far.

Specified by:
report in interface SK.gnome.dwarf.Reportable

service

public void service(javax.servlet.ServletRequest request,
                    javax.servlet.ServletResponse response)
             throws java.io.IOException,
                    javax.servlet.ServletException
Services the request.

Calls the servlets' service method and updates the counter. If the servlet instance implements the SingleThreadModel interface, the calls to the service method are serialized.

Throws:
java.io.IOException
javax.servlet.ServletException

getServletContext

public javax.servlet.ServletContext getServletContext()
Returns a reference to the ServletContext in which the servlet is executing.

Specified by:
getServletContext in interface javax.servlet.ServletConfig
Returns:
a ServletContext object, used by the servlet to interact with its servlet application
See Also:
ServletContext

getInitParameter

public java.lang.String getInitParameter(java.lang.String name)
Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.

Specified by:
getInitParameter in interface javax.servlet.ServletConfig
Parameters:
name - a String specifying the name of the initialization parameter
Returns:
a String containing the value of the initialization parameter

getInitParameterNames

public java.util.Enumeration getInitParameterNames()
Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters.

Specified by:
getInitParameterNames in interface javax.servlet.ServletConfig
Returns:
an Enumeration of String objects containing the names of the servlet's initialization parameters

getServletName

public java.lang.String getServletName()
Returns the name of this servlet instance. The name may be provided via server administration, assigned in the web application deployment descriptor, or for an unregistered (and thus unnamed) servlet instance it will be the servlet's class name.

Specified by:
getServletName in interface javax.servlet.ServletConfig
Returns:
the name of the servlet instance


Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.