org.apache.cocoon.servlet
Class CocoonServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.apache.cocoon.servlet.CocoonServlet
All Implemented Interfaces:
Serializable, Servlet, ServletConfig

public class CocoonServlet
extends HttpServlet

This is the entry point for Cocoon execution as an HTTP Servlet.

Version:
$Id: CocoonServlet.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Pierpaolo Fumagalli (Apache Software Foundation), Stefano Mazzocchi, Nicola Ken Barozzi, Berin Loritsch, Carsten Ziegeler, Leo Sutic
See Also:
Serialized Form

Field Summary
protected static boolean ALLOW_RELOAD
          Default value for allowReload parameter (false)
protected  boolean allowReload
          Allow reloading of cocoon by specifying the cocoon-reload=true parameter with a request
protected  DefaultContext appContext
          Avalon application context
protected  ClassLoader classLoader
          The classloader that will be set as the context classloader if init-classloader is true
protected  Cocoon cocoon
          The Cocoon instance
static String CONTEXT_SERVLET_CONFIG
          Application Context Key for the servlet configuration
protected  long creationTime
          The time the cocoon instance was created
protected  Exception exception
          Holds exception happened during initialization (if any)
protected  String forceLoadParameter
           
protected  String forceSystemProperty
           
protected  boolean hiddenShowTime
          If true, processing time will be added as an HTML comment
protected  boolean initClassLoader
           
protected static String PROCESSED_BY
           
protected  RequestFactory requestFactory
          The RequestFactory is responsible for wrapping multipart-encoded forms and for handing the file payload of incoming requests
protected  ServletContext servletContext
           
protected  String servletContextPath
          This is the path to the servlet context (or the result of calling getRealPath('/') on the ServletContext.
protected  String servletContextURL
          This is the url to the servlet context directory
protected  boolean showTime
          Allow adding processing time to the response
 
Constructor Summary
CocoonServlet()
           
 
Method Summary
protected  void addClassLoaderDirectory(String dir)
          Adds a directory to the classloader.
protected  void addClassLoaderURL(URL URL)
          Adds an URL to the classloader.
protected  void createCocoon()
          Creates the Cocoon object and handles exception handling.
 void destroy()
          Dispose Cocoon when servlet is destroyed
protected  void disposeCocoon()
          Destroy Cocoon
protected  String getClassPath()
          This builds the important ClassPath used by this Servlet.
protected  Environment getEnvironment(String uri, HttpServletRequest req, HttpServletResponse res)
          Create the environment for the request
protected  String getExtraClassPath()
          Retreives the "extra-classpath" attribute, that needs to be added to the class path.
 String getInitParameter(String name)
          Get an initialisation parameter.
protected  String getInitParameter(String name, String defaultValue)
          Convenience method to access servlet parameters
protected  boolean getInitParameterAsBoolean(String name, boolean defaultValue)
          Convenience method to access boolean servlet parameters
protected  int getInitParameterAsInteger(String name, int defaultValue)
           
protected  Logger getLogger()
           
protected  LoggerManager getLoggerManager()
           
protected  ComponentManager getParentComponentManager()
          Instatiates the parent component manager, as specified in the parent-component-manager init parameter.
 void init(ServletConfig conf)
          Initialize this CocoonServlet instance.
protected  void initLogger()
          Set up the log level and path.
protected  void manageException(HttpServletRequest req, HttpServletResponse res, Environment env, String uri, int errorStatus, String title, String message, String description, Exception e)
           
 void service(HttpServletRequest req, HttpServletResponse res)
          Process the specified HttpServletRequest producing output on the specified HttpServletResponse.
protected  void updateEnvironment()
          Method to update the environment before Cocoon instances are created.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
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

CONTEXT_SERVLET_CONFIG

public static final String CONTEXT_SERVLET_CONFIG
Application Context Key for the servlet configuration

Since:
2.1.3
See Also:
Constant Field Values

PROCESSED_BY

protected static final String PROCESSED_BY

creationTime

protected long creationTime
The time the cocoon instance was created


cocoon

protected Cocoon cocoon
The Cocoon instance


exception

protected Exception exception
Holds exception happened during initialization (if any)


appContext

protected DefaultContext appContext
Avalon application context


ALLOW_RELOAD

protected static final boolean ALLOW_RELOAD
Default value for allowReload parameter (false)

See Also:
Constant Field Values

allowReload

protected boolean allowReload
Allow reloading of cocoon by specifying the cocoon-reload=true parameter with a request


showTime

protected boolean showTime
Allow adding processing time to the response


hiddenShowTime

protected boolean hiddenShowTime
If true, processing time will be added as an HTML comment


servletContext

protected ServletContext servletContext

classLoader

protected ClassLoader classLoader
The classloader that will be set as the context classloader if init-classloader is true


initClassLoader

protected boolean initClassLoader

forceLoadParameter

protected String forceLoadParameter

forceSystemProperty

protected String forceSystemProperty

servletContextPath

protected String servletContextPath
This is the path to the servlet context (or the result of calling getRealPath('/') on the ServletContext. Note, that this can be null.


servletContextURL

protected String servletContextURL
This is the url to the servlet context directory


requestFactory

protected RequestFactory requestFactory
The RequestFactory is responsible for wrapping multipart-encoded forms and for handing the file payload of incoming requests

Constructor Detail

CocoonServlet

public CocoonServlet()
Method Detail

init

public void init(ServletConfig conf)
          throws ServletException
Initialize this CocoonServlet instance. You will notice that I have broken the init into sub methods to make it easier to maintain (BL). The context is passed to a couple of the subroutines. This is also because it is better to explicitly pass variables than implicitely. It is both more maintainable, and more elegant.

Specified by:
init in interface Servlet
Overrides:
init in class GenericServlet
Parameters:
conf - The ServletConfig object from the servlet engine.
Throws:
ServletException

destroy

public void destroy()
Dispose Cocoon when servlet is destroyed

Specified by:
destroy in interface Servlet
Overrides:
destroy in class GenericServlet

addClassLoaderURL

protected void addClassLoaderURL(URL URL)
Adds an URL to the classloader. Does nothing here, but is overriden in ParanoidCocoonServlet.


addClassLoaderDirectory

protected void addClassLoaderDirectory(String dir)
Adds a directory to the classloader. Does nothing here, but is overriden in ParanoidCocoonServlet.


getClassPath

protected String getClassPath()
                       throws ServletException
This builds the important ClassPath used by this Servlet. It does so in a Servlet Engine neutral way. It uses the ServletContext's getRealPath method to get the Servlet 2.2 identified classes and lib directories. It iterates in alphabetical order through every file in the lib directory and adds it to the classpath. Also, we add the files to the ClassLoader for the Cocoon system. In order to protect ourselves from skitzofrantic classloaders, we need to work with a known one. We need to get this to work properly when Cocoon is in a war.

Throws:
ServletException

getExtraClassPath

protected String getExtraClassPath()
                            throws ServletException
Retreives the "extra-classpath" attribute, that needs to be added to the class path.

Throws:
ServletException

initLogger

protected void initLogger()
Set up the log level and path. The default log level is Priority.ERROR, although it can be overwritten by the parameter "log-level". The log system goes to both a file and the Servlet container's log system. Only messages that are Priority.ERROR and above go to the servlet context. The log messages can be as restrictive (Priority.FATAL_ERROR and above) or as liberal (Priority.DEBUG and above) as you want that get routed to the file.


service

public void service(HttpServletRequest req,
                    HttpServletResponse res)
             throws ServletException,
                    IOException
Process the specified HttpServletRequest producing output on the specified HttpServletResponse.

Overrides:
service in class HttpServlet
Throws:
ServletException
IOException

manageException

protected void manageException(HttpServletRequest req,
                               HttpServletResponse res,
                               Environment env,
                               String uri,
                               int errorStatus,
                               String title,
                               String message,
                               String description,
                               Exception e)
                        throws IOException
Throws:
IOException

getEnvironment

protected Environment getEnvironment(String uri,
                                     HttpServletRequest req,
                                     HttpServletResponse res)
                              throws Exception
Create the environment for the request

Throws:
Exception

getParentComponentManager

protected ComponentManager getParentComponentManager()
Instatiates the parent component manager, as specified in the parent-component-manager init parameter. If none is specified, the method returns null.

Returns:
the parent component manager, or null.

createCocoon

protected void createCocoon()
                     throws ServletException
Creates the Cocoon object and handles exception handling.

Throws:
ServletException

updateEnvironment

protected void updateEnvironment()
                          throws ServletException
Method to update the environment before Cocoon instances are created. This is also useful if you wish to customize any of the 'protected' variables from this class before a Cocoon instance is built in a derivative of this class (eg. Cocoon Context).

Throws:
ServletException

disposeCocoon

protected final void disposeCocoon()
Destroy Cocoon


getInitParameter

public String getInitParameter(String name)
Get an initialisation parameter. The value is trimmed, and null is returned if the trimmed value is empty.

Specified by:
getInitParameter in interface ServletConfig
Overrides:
getInitParameter in class GenericServlet

getInitParameter

protected String getInitParameter(String name,
                                  String defaultValue)
Convenience method to access servlet parameters


getInitParameterAsBoolean

protected boolean getInitParameterAsBoolean(String name,
                                            boolean defaultValue)
Convenience method to access boolean servlet parameters


getInitParameterAsInteger

protected int getInitParameterAsInteger(String name,
                                        int defaultValue)

getLogger

protected Logger getLogger()

getLoggerManager

protected LoggerManager getLoggerManager()


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.