org.apache.tapestry
Class ApplicationServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.apache.tapestry.ApplicationServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ApplicationServlet
extends javax.servlet.http.HttpServlet

Links a servlet container with a Tapestry application. The servlet has some responsibilities related to bootstrapping the application (in terms of logging, reading the specification, etc.). It is also responsible for creating or locating the IEngineand delegating incoming requests to it.

The servlet init parameter org.apache.tapestry.specification-path should be set to the complete resource path (within the classpath) to the application specification, i.e., /com/foo/bar/MyApp.application.

In some servlet containers (notably WebLogic ) it is necessary to invoke HttpSession.setAttribute(String,Object)in order to force a persistent value to be replicated to the other servers in the cluster. Tapestry applications usually only have a single persistent value, the engine. For persistence to work in such an environment, the JVM system property org.apache.tapestry.store-engine must be set to true. This will force the application servlet to restore the engine into the HttpSessionat the end of each request cycle.

As of release 1.0.1, it is no longer necessary for a HttpSessionto be created on the first request cycle. Instead, the HttpSession is created as needed by the IEngine... that is, when a visit object is created, or when persistent page state is required. Otherwise, for sessionless requests, an IEnginefrom a Poolis used. Additional work must be done so that the IEnginecan change locale without forcing the creation of a session; this involves the servlet and the engine storing locale information in a Cookie.

As of release 3.1, this servlet will also create a HiveMind Registry and manage it.

Author:
Howard Lewis Ship
See Also:
Serialized Form

Constructor Summary
ApplicationServlet()
           
 
Method Summary
protected  void addModuleIfExists(org.apache.hivemind.impl.RegistryBuilder builder, javax.servlet.ServletContext context, java.lang.String path)
          Looks for a file in the servlet context; if it exists, it is expected to be a HiveMind module descriptor, and is added to the builder.
protected  void close(java.io.InputStream stream)
          Closes the stream, ignoring any exceptions.
protected  org.apache.hivemind.Registry constructRegistry(javax.servlet.ServletConfig config)
          Invoked from init(ServletConfig)to construct the Registry to be used by the application.
protected  org.apache.hivemind.ClassResolver createClassResolver()
          Invoked from init(ServletConfig)to create a resource resolver for the servlet (which will utlimately be shared and used through the application).
 void destroy()
          Shuts down the registry (if it exists).
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Invokes doService(HttpServletRequest, HttpServletResponse).
 void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Invokes doService(HttpServletRequest, HttpServletResponse).
protected  void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handles the GET and POST requests.
 IApplicationSpecification getApplicationSpecification()
          Deprecated. Use RequestContext.getApplicationSpecification()instead.
 org.apache.hivemind.ClassResolver getClassResolver()
          Returns a class resolver that can access classes and resources related to the current web application context.
 org.apache.hivemind.Registry getRegistry()
          Returns the Registry used by the application.
 void init(javax.servlet.ServletConfig config)
          Reads the application specification when the servlet is first initialized.
protected  void initializeApplication()
          Invoked from init(ServletConfig), after the registry has been constructed, to bootstrap the application via the tapestry.MasterApplicationInitializer service.
protected  void show(java.lang.Exception ex)
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
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
 

Constructor Detail

ApplicationServlet

public ApplicationServlet()
Method Detail

doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException,
                  javax.servlet.ServletException
Invokes doService(HttpServletRequest, HttpServletResponse).

Overrides:
doGet in class javax.servlet.http.HttpServlet
java.io.IOException
javax.servlet.ServletException
Since:
1.0.6

doService

protected void doService(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
                  throws java.io.IOException,
                         javax.servlet.ServletException
Handles the GET and POST requests. Performs the following:

java.io.IOException
javax.servlet.ServletException

show

protected void show(java.lang.Exception ex)

doPost

public void doPost(javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
            throws java.io.IOException,
                   javax.servlet.ServletException
Invokes doService(HttpServletRequest, HttpServletResponse).

Overrides:
doPost in class javax.servlet.http.HttpServlet
java.io.IOException
javax.servlet.ServletException

getApplicationSpecification

public IApplicationSpecification getApplicationSpecification()
Deprecated. Use RequestContext.getApplicationSpecification()instead.

Returns the application specification, which is read by the init(ServletConfig) method.


init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Reads the application specification when the servlet is first initialized. All engine instanceswill have access to the specification via the servlet.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
javax.servlet.ServletException
See Also:
getApplicationSpecification(), #constructApplicationSpecification(), #createResourceResolver()

createClassResolver

protected org.apache.hivemind.ClassResolver createClassResolver()
                                                         throws javax.servlet.ServletException
Invoked from init(ServletConfig)to create a resource resolver for the servlet (which will utlimately be shared and used through the application).

This implementation constructs a DefaultResourceResolver, subclasses may provide a different implementation.

javax.servlet.ServletException
Since:
2.3
See Also:
#getResourceResolver()

close

protected void close(java.io.InputStream stream)
Closes the stream, ignoring any exceptions.


getClassResolver

public org.apache.hivemind.ClassResolver getClassResolver()
Returns a class resolver that can access classes and resources related to the current web application context. Relies on Thread.getContextClassLoader(), which is set by most modern servlet containers.

Since:
2.3

constructRegistry

protected org.apache.hivemind.Registry constructRegistry(javax.servlet.ServletConfig config)
Invoked from init(ServletConfig)to construct the Registry to be used by the application.

This looks in the standard places (on the classpath), but also in the WEB-INF/name and WEB-INF folders (where name is the name of the servlet).

Since:
3.1

addModuleIfExists

protected void addModuleIfExists(org.apache.hivemind.impl.RegistryBuilder builder,
                                 javax.servlet.ServletContext context,
                                 java.lang.String path)
Looks for a file in the servlet context; if it exists, it is expected to be a HiveMind module descriptor, and is added to the builder.

Since:
3.1

initializeApplication

protected void initializeApplication()
Invoked from init(ServletConfig), after the registry has been constructed, to bootstrap the application via the tapestry.MasterApplicationInitializer service.

Since:
3.1

getRegistry

public org.apache.hivemind.Registry getRegistry()
Returns the Registry used by the application.

Since:
3.1

destroy

public void destroy()
Shuts down the registry (if it exists).

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet
Since:
3.1