|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.apache.tapestry.ApplicationServlet
public class ApplicationServlet
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 IEngine
and 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 HttpSession
at the
end of each request cycle.
As of release 1.0.1, it is no longer necessary for a HttpSession
to 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 IEngine
from a Pool
is used. Additional work must be done
so that the IEngine
can change locale without forcing
the creation of a session; this involves the servlet and the engine storing
locale information in a Cookie
.
Constructor Summary | |
---|---|
ApplicationServlet()
|
Method Summary | |
---|---|
protected void |
close(InputStream stream)
Closes the stream, ignoring any exceptions. |
protected IApplicationSpecification |
constructApplicationSpecification()
Invoked from init(ServletConfig) to read and construct
the ApplicationSpecification for this servlet. |
protected IApplicationSpecification |
constructStandinSpecification()
Invoked from constructApplicationSpecification() when
the application doesn't have an explicit specification. |
protected IEngine |
createEngine(RequestContext context)
Invoked by getEngine(RequestContext) to create
the IEngine instance specific to the
application, if not already in the
HttpSession . |
protected IPropertySource |
createPropertySource()
Creates an instance of IPropertySource used for
searching of configuration values. |
protected RequestContext |
createRequestContext(HttpServletRequest request,
HttpServletResponse response)
Invoked by doService(HttpServletRequest, HttpServletResponse) to create
the RequestContext for this request cycle. |
protected IResourceResolver |
createResourceResolver()
Invoked from init(ServletConfig) to create a resource resolver
for the servlet (which will utlimately be shared and used through the
application). |
void |
destroy()
Ensures that shared janitor thread is terminated. |
void |
doGet(HttpServletRequest request,
HttpServletResponse response)
Invokes doService(HttpServletRequest, HttpServletResponse) . |
void |
doPost(HttpServletRequest request,
HttpServletResponse response)
Invokes doService(HttpServletRequest, HttpServletResponse) . |
protected void |
doService(HttpServletRequest request,
HttpServletResponse response)
Handles the GET and POST requests. |
IApplicationSpecification |
getApplicationSpecification()
Returns the application specification, which is read by the init(ServletConfig) method. |
protected IResourceLocation |
getApplicationSpecificationLocation()
Gets the location of the application specification, if there is one. |
protected String |
getApplicationSpecificationPath()
Reads the servlet init parameter org.apache.tapestry.application-specification , which
is the location, on the classpath, of the application specification. |
protected IEngine |
getEngine(RequestContext context)
Retrieves the engine that will process this
request. |
protected String |
getEngineClassName()
Returns the name of the class to use when instantiating an engine instance for this application. |
protected Locale |
getLocaleFromRequest(RequestContext context)
Determines the Locale for the incoming request. |
IResourceResolver |
getResourceResolver()
Returns a resource resolver that can access classes and resources related to the current web application context. |
void |
init(ServletConfig config)
Reads the application specification when the servlet is first initialized. |
protected IApplicationSpecification |
parseApplicationSpecification(IResourceLocation location)
Invoked from constructApplicationSpecification() to
actually parse the stream (with content provided from the path)
and convert it into an ApplicationSpecification . |
protected String |
searchConfiguration(String propertyName)
Searches for a configuration property in: The servlet's initial parameters The servlet context's initial parameters JVM system properties |
protected void |
show(Exception ex)
|
void |
writeLocaleCookie(Locale locale,
IEngine engine,
RequestContext cycle)
Invoked from the engine , just prior to starting to
render a response, when the locale has changed. |
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 |
---|
public ApplicationServlet()
Method Detail |
---|
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
doService(HttpServletRequest, HttpServletResponse)
.
doGet
in class HttpServlet
IOException
ServletException
protected void doService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
RequestContext
getEngine(RequestContext)
to get or create the IEngine
IEngine.service(RequestContext)
on the application
IOException
ServletException
protected RequestContext createRequestContext(HttpServletRequest request, HttpServletResponse response) throws IOException
doService(HttpServletRequest, HttpServletResponse)
to create
the RequestContext
for this request cycle. Some applications may need to
replace the default RequestContext with a subclass for particular behavior.
IOException
protected void show(Exception ex)
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
doService(HttpServletRequest, HttpServletResponse)
.
doPost
in class HttpServlet
IOException
ServletException
public IApplicationSpecification getApplicationSpecification()
init(ServletConfig)
method.
protected IEngine getEngine(RequestContext context) throws ServletException
engine
that will process this
request. This comes from one of the following places:
HttpSession
, if the there is one.
ServletException
protected Locale getLocaleFromRequest(RequestContext context) throws ServletException
Locale
for the incoming request.
This is determined from the locale cookie or, if not set,
from the request itself. This may return null
if no locale is determined.
ServletException
public void init(ServletConfig config) throws ServletException
engine instances
will have access to the specification via the servlet.
init
in interface Servlet
init
in class GenericServlet
ServletException
getApplicationSpecification()
,
constructApplicationSpecification()
,
createResourceResolver()
protected IResourceResolver createResourceResolver() throws ServletException
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.
ServletException
getResourceResolver()
protected IApplicationSpecification constructApplicationSpecification() throws ServletException
init(ServletConfig)
to read and construct
the ApplicationSpecification
for this servlet.
Invokes getApplicationSpecificationPath()
, opens
the resource as a stream, then invokes
parseApplicationSpecification(IResourceLocation)
.
This method exists to be overriden in applications where the application specification cannot be loaded from the classpath. Alternately, a subclass could override this method, invoke this implementation, and then add additional data to it (for example, an application where some of the pages are defined in an external source such as a database).
ServletException
protected IResourceLocation getApplicationSpecificationLocation() throws ServletException
getApplicationSpecificationPath()
to get the
location of the application specification on the classpath.
Returns the location of the application specification, or null if not found.
ServletException
protected IApplicationSpecification constructStandinSpecification()
constructApplicationSpecification()
when
the application doesn't have an explicit specification. A
simple specification is constructed and returned. This is useful
for minimal applications and prototypes.
protected IApplicationSpecification parseApplicationSpecification(IResourceLocation location) throws ServletException
constructApplicationSpecification()
to
actually parse the stream (with content provided from the path)
and convert it into an ApplicationSpecification
.
ServletException
protected void close(InputStream stream)
protected String getApplicationSpecificationPath() throws ServletException
org.apache.tapestry.application-specification
, which
is the location, on the classpath, of the application specification.
If the parameter is not set, this method returns null, and a search for the application specification within the servlet context will begin.
ServletException
getApplicationSpecificationLocation()
protected IEngine createEngine(RequestContext context) throws ServletException
getEngine(RequestContext)
to create
the IEngine
instance specific to the
application, if not already in the
HttpSession
.
The IEngine
instance returned is stored into the
HttpSession
.
ServletException
getEngineClassName()
protected String getEngineClassName()
org.apache.tapestry.engine-class
occurs (see searchConfiguration(String)
).
If the search is still unsuccessful, then
BaseEngine
is used.
protected String searchConfiguration(String propertyName)
createPropertySource()
protected IPropertySource createPropertySource()
IPropertySource
used for
searching of configuration values. Subclasses may override
this method if they want to change the normal locations
that properties are searched for within.
public void writeLocaleCookie(Locale locale, IEngine engine, RequestContext cycle)
engine
, just prior to starting to
render a response, when the locale has changed. The servlet writes a
Cookie
so that, on subsequent request cycles, an engine localized
to the selected locale is chosen.
At this time, the cookie is not persistent. That may change in subsequent releases.
public IResourceResolver getResourceResolver()
Thread.getContextClassLoader()
, which is set by
most modern servlet containers.
public void destroy()
destroy
in interface Servlet
destroy
in class GenericServlet
Servlet.destroy()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |