com.interface21.web.servlet
Class FrameworkServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.interface21.web.servlet.HttpServletBean
                    |
                    +--com.interface21.web.servlet.FrameworkServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
DispatcherServlet

public abstract class FrameworkServlet
extends HttpServletBean

Base servlet for servlets within the Interface21 framework. Allows integration with bean factory and application context, in a JavaBean-based overall solution.

This class offers the following functionality:

Subclasses must implement doService() to handle requests. Because this extends HttpServletBean rather than HttpServlet directly, bean properties are mapped onto it. Subclasses can override initFrameworkServlet() for custom initialization.

Version:
$Revision: 1.11 $
Author:
Rod Johnson
See Also:
doService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), initFrameworkServlet(), Serialized Form

Field Summary
static java.lang.String DEFAULT_NAMESPACE_SUFFIX
          Suffix for namespace bean factory names.
static java.lang.String SERVLET_CONTEXT_PREFIX
          Prefix for the ServletContext attribute for the web application context.
 
Fields inherited from class com.interface21.web.servlet.HttpServletBean
logger
 
Constructor Summary
FrameworkServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          It's up to each subclass to decide whether or not it supports a request method.
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          It's up to each subclass to decide whether or not it supports a request method.
protected abstract  void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to do the work of request handling.
 java.lang.String getNamespace()
          Return the namespace for this servlet, falling back to default scheme if no custom namespace was set: e.g.
 java.lang.String getServletContextAttributeName()
          Return the ServletContext attribute name for this servlet's WebApplicationContext.
 WebApplicationContext getWebApplicationContext()
          Return this servlet's WebApplicationContext.
protected abstract  void initFrameworkServlet()
          Subclasses must implement this method to perform any initialization they require.
protected  void initServletBean()
          Overridden method of HttpServletBean, invoked after any bean properties have been set.
 void setContextClass(java.lang.String className)
          Set a custom context class name.
 void setNamespace(java.lang.String namespace)
          Set a custom namespace for this servlet.
 void setPublishContext(boolean publishContext)
          Set whether to publish this servlet's context as a ServletContext attribute.
 
Methods inherited from class com.interface21.web.servlet.HttpServletBean
addRequiredProperty, getIdentifier, init
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.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 Detail

DEFAULT_NAMESPACE_SUFFIX

public static final java.lang.String DEFAULT_NAMESPACE_SUFFIX
Suffix for namespace bean factory names. If a servlet of this class is given the name 'test' in a context, the namespace used by the servlet will resolve to 'test-servlet'.

SERVLET_CONTEXT_PREFIX

public static final java.lang.String SERVLET_CONTEXT_PREFIX
Prefix for the ServletContext attribute for the web application context. The completion is the servlet name.
Constructor Detail

FrameworkServlet

public FrameworkServlet()
Method Detail

setNamespace

public void setNamespace(java.lang.String namespace)
Set a custom namespace for this servlet.

getNamespace

public java.lang.String getNamespace()
Return the namespace for this servlet, falling back to default scheme if no custom namespace was set: e.g. "test-servlet" for a servlet named "test".

setContextClass

public final void setContextClass(java.lang.String className)
Set a custom context class name. This class must be of type WebApplicationContext, and must implement a constructor taking two arguments: a parent WebApplicationContext (the root), and the current namespace as String.
Parameters:
className - name of custom context class to use

setPublishContext

public final void setPublishContext(boolean publishContext)
Set whether to publish this servlet's context as a ServletContext attribute. Default is true.
Parameters:
publishContext - whether we should publish this servlet's WebApplicationContext as a ServletContext attribute, available to all objects in this web container. Default is true. This is especially handy during testing, although it is debatable whether it's good practice to let other application objects access the context this way.

getWebApplicationContext

public final WebApplicationContext getWebApplicationContext()
Return this servlet's WebApplicationContext.

getServletContextAttributeName

public java.lang.String getServletContextAttributeName()
Return the ServletContext attribute name for this servlet's WebApplicationContext.

initServletBean

protected final void initServletBean()
                              throws javax.servlet.ServletException
Overridden method of HttpServletBean, invoked after any bean properties have been set. Creates this servlet's WebApplicationContext.
Overrides:
initServletBean in class HttpServletBean
Following copied from class: com.interface21.web.servlet.HttpServletBean
Throws:
javax.servlet.ServletException - if subclass initialization fails

doGet

protected final void doGet(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response)
                    throws javax.servlet.ServletException,
                           java.io.IOException
It's up to each subclass to decide whether or not it supports a request method. It should throw a Servlet exception if it doesn't support a particular request type. This might commonly be done with GET for forms, for example
Overrides:
doGet in class javax.servlet.http.HttpServlet

doPost

protected final void doPost(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws javax.servlet.ServletException,
                            java.io.IOException
It's up to each subclass to decide whether or not it supports a request method. It should throw a Servlet exception if it doesn't support a particular request type. This might commonly be done with GET for forms, for example
Overrides:
doPost in class javax.servlet.http.HttpServlet

initFrameworkServlet

protected abstract void initFrameworkServlet()
                                      throws javax.servlet.ServletException
Subclasses must implement this method to perform any initialization they require. The implementation may be empty. This method will be invoked after any bean properties have been set and WebApplicationContext and BeanFactory have been loaded.
Throws:
javax.servlet.ServletException - in case of an initialization exception

doService

protected abstract void doService(javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response)
                           throws javax.servlet.ServletException,
                                  java.io.IOException
Subclasses must implement this method to do the work of request handling. The contract is the same as that for the doGet() or doPost() method of HttpServlet. This class intercepts calls to ensure that event publication takes place.
See Also:
HttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)


Rod Johnson and Spring contributors 2001-2003.