Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.appserver.server.httpPresentation.servlet
Class HttpPresentationServlet  view HttpPresentationServlet download HttpPresentationServlet.java

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycom.lutris.appserver.server.httpPresentation.servlet.HttpPresentationServlet
All Implemented Interfaces:
FilterableServlet, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class HttpPresentationServlet
extends javax.servlet.http.HttpServlet
implements FilterableServlet

Presentation server implemented as a servlet. Translates servlet requests into HttpPresentationManager requests. There is a one to one correspondence between an instance of this servlet and an Enhydra application. An instance of the application is created by the servlet. The servlet requires a single init parameter `configFile', that contains the path to the application's configuration file. This file must define the following fields:

This servlet also implements the ListenableServlet interface. This allows other objects to register with this servlet and be notified every time service is called. These remote listeners may ignore the notification, examine the request, or even replace the request and/or response with extended versions. This is used by the debugging and monitoring servlets.

Since:
1.3
Version:
$Revision: 1.63.2.3.4.3 $

Field Summary
private static java.lang.String APP_APP_CLASS_FIELD
           
private static java.lang.String APP_AUTO_RELOAD_FIELD
           
private static java.lang.String APP_CLASS_PATH_FIELD
           
private static java.lang.String APP_CONFIG_INIT_PARAM_NAME
           
private static java.lang.String APP_LOG_TO_FILE
           
private static java.lang.String APP_LOG_TO_STDERR
           
private static java.lang.String APP_LOGFILE
           
private static java.lang.String APP_PRESENTATION_PREFIX_FIELD
           
(package private)  com.lutris.util.Config appConfig
           
(package private)  com.lutris.appserver.server.Application application
           
(package private)  boolean autoReload
           
(package private)  boolean cacheClasses
           
(package private)  boolean cacheFiles
           
protected  javax.servlet.ServletContext context
           
private  java.io.PrintWriter domStatsLogWriter
          If not null, log DOM statistics here after each DOM write.
private  java.util.Vector filters
           
private  com.lutris.logging.LogChannel logChannel
           
private  boolean needToConfigureLogChannel
           
(package private)  com.lutris.appserver.server.httpPresentation.HttpPresentationManager presentationManager
           
(package private)  java.lang.String presentationPrefix
           
private  com.lutris.logging.StandardLogger standardLogger
           
static java.lang.String XMLC_DOM_STATS_LOG_LEVEL
          Log level for DOM statistics.
 
Fields inherited from class javax.servlet.http.HttpServlet
 
Fields inherited from class javax.servlet.GenericServlet
 
Constructor Summary
HttpPresentationServlet()
          Create a new HttpPresentationServlet.
 
Method Summary
 void addFilter(org.enhydra.servlet.filter.Filter filter)
          Add a filter to the end of the list of filters.
private  void changeToRunningState()
          Attempt to change the application to the running state.
private  void checkAutoReload()
          Check if the application should be automatically reloaded and, if so, call initApplication with a new instance of the class loader.
private  void configureLogChannel(java.lang.String configFile)
           
 void destroy()
          Destroys the servlet.
 void ensureAppIsRunning()
          This method is public for use by the ServletManager to run the application startup() method after init().
protected  com.lutris.util.Config getAppConfigInitParam()
          Returns the application configuration init parameter.
protected  java.lang.String getAppConfigInitParamName()
          Returns the application configuration init parameter name.
 com.lutris.appserver.server.Application getApplication()
          Returns the application being run by this instance of the servlet.
protected  com.lutris.appserver.server.httpPresentation.HttpPresentationRequest getHttpPresentationRequest(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          This method instantiates the HttpPresentationRequest object that the presentation manager expects when servicing a request.
protected  com.lutris.appserver.server.httpPresentation.HttpPresentationResponse getHttpPresentationResponse(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          This method instantiates the HttpPresentationResponse object that the presentation manager expects when servicing a request.
 java.lang.String getServletInfo()
          Return information specific to this servlet.
 com.lutris.appserver.server.session.Session getSession(javax.servlet.ServletRequest request)
          Looks up the session object (if any) that would be used to process the request.
 void init(javax.servlet.ServletConfig config)
          Called by the servlet container to indicate to a servlet that the servlet is being placed into service.
private  void initApplication(javax.servlet.ServletConfig servletConfig, com.lutris.classloader.MultiClassLoader appClassLoader)
          Open and read the application's configuration file and initialize the application, but don't start it yet.
private  void missingConfField(java.lang.String field, java.lang.String file)
          Generate an error for a field not being specified in a config file.
 void removeFilter(org.enhydra.servlet.filter.Filter filter)
          Remove a filter from the list of current filters.
 void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Handle a service request.
 void serviceDirect(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          This is an HTTP-specific version of the Servlet.service method that translates that request into a request to a presentation manager.
private  void setPresentationManager(javax.servlet.ServletContext context, java.lang.ClassLoader appClassLoader)
          Sets the presentation manager for the application.
private  void throwServletException(java.lang.String msg, java.lang.Throwable cause)
          Throw a servlet exceptionm logging the message if possible.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XMLC_DOM_STATS_LOG_LEVEL

public static final java.lang.String XMLC_DOM_STATS_LOG_LEVEL
Log level for DOM statistics.

See Also:
Constant Field Values

context

protected javax.servlet.ServletContext context

APP_CONFIG_INIT_PARAM_NAME

private static final java.lang.String APP_CONFIG_INIT_PARAM_NAME
See Also:
Constant Field Values

APP_CLASS_PATH_FIELD

private static final java.lang.String APP_CLASS_PATH_FIELD
See Also:
Constant Field Values

APP_APP_CLASS_FIELD

private static final java.lang.String APP_APP_CLASS_FIELD
See Also:
Constant Field Values

APP_PRESENTATION_PREFIX_FIELD

private static final java.lang.String APP_PRESENTATION_PREFIX_FIELD
See Also:
Constant Field Values

APP_AUTO_RELOAD_FIELD

private static final java.lang.String APP_AUTO_RELOAD_FIELD
See Also:
Constant Field Values

APP_LOGFILE

private static final java.lang.String APP_LOGFILE
See Also:
Constant Field Values

APP_LOG_TO_FILE

private static final java.lang.String APP_LOG_TO_FILE
See Also:
Constant Field Values

APP_LOG_TO_STDERR

private static final java.lang.String APP_LOG_TO_STDERR
See Also:
Constant Field Values

logChannel

private com.lutris.logging.LogChannel logChannel

standardLogger

private com.lutris.logging.StandardLogger standardLogger

needToConfigureLogChannel

private boolean needToConfigureLogChannel

application

com.lutris.appserver.server.Application application

appConfig

com.lutris.util.Config appConfig

presentationPrefix

java.lang.String presentationPrefix

cacheClasses

boolean cacheClasses

cacheFiles

boolean cacheFiles

autoReload

boolean autoReload

presentationManager

com.lutris.appserver.server.httpPresentation.HttpPresentationManager presentationManager

domStatsLogWriter

private java.io.PrintWriter domStatsLogWriter
If not null, log DOM statistics here after each DOM write.


filters

private java.util.Vector filters
Constructor Detail

HttpPresentationServlet

public HttpPresentationServlet()
Create a new HttpPresentationServlet.

Method Detail

throwServletException

private void throwServletException(java.lang.String msg,
                                   java.lang.Throwable cause)
                            throws javax.servlet.ServletException
Throw a servlet exceptionm logging the message if possible.


missingConfField

private void missingConfField(java.lang.String field,
                              java.lang.String file)
                       throws com.lutris.appserver.server.httpPresentation.HttpPresentationException
Generate an error for a field not being specified in a config file.


initApplication

private void initApplication(javax.servlet.ServletConfig servletConfig,
                             com.lutris.classloader.MultiClassLoader appClassLoader)
                      throws javax.servlet.ServletException
Open and read the application's configuration file and initialize the application, but don't start it yet. This is done on in service so it part of the standard state-change mechanism.


init

public void init(javax.servlet.ServletConfig config)
          throws javax.servlet.ServletException
Description copied from class: javax.servlet.GenericServlet
Called by the servlet container to indicate to a servlet that the servlet is being placed into service. See Servlet.init(javax.servlet.ServletConfig)>Servlet.init(javax.servlet.ServletConfig) 55 .

This implementation stores the javax.servlet.ServletConfig object it receives from the servlet container for later use. When overriding this form of the method, call super.init(config).

Specified by:
init in interface javax.servlet.Servlet

setPresentationManager

private void setPresentationManager(javax.servlet.ServletContext context,
                                    java.lang.ClassLoader appClassLoader)
                             throws javax.servlet.ServletException
Sets the presentation manager for the application. First creates a new presentation manager with the presentationPrefix, application, cacheClasses and cacheFiles fields (so these parameters must already be initialized). Then, the presentation manager is set in the application.


changeToRunningState

private void changeToRunningState()
                           throws com.lutris.appserver.server.ApplicationException
Attempt to change the application to the running state.


configureLogChannel

private void configureLogChannel(java.lang.String configFile)
                          throws com.lutris.appserver.server.httpPresentation.HttpPresentationException

serviceDirect

public void serviceDirect(javax.servlet.http.HttpServletRequest req,
                          javax.servlet.http.HttpServletResponse resp)
                   throws javax.servlet.ServletException,
                          java.io.IOException
This is an HTTP-specific version of the Servlet.service method that translates that request into a request to a presentation manager. This object is method is not synchronized, the thread is used to handle to entire request.

As part of implementing the FiterableServlet interface, the real work is done here in serviceDirect(), while calls to service() result in filters being applied and called. The end of the filter chain is a glue servlet that directly calls this method.

Specified by:
serviceDirect in interface FilterableServlet

ensureAppIsRunning

public void ensureAppIsRunning()
                        throws javax.servlet.ServletException
This method is public for use by the ServletManager to run the application startup() method after init().


getServletInfo

public java.lang.String getServletInfo()
Return information specific to this servlet.

Specified by:
getServletInfo in interface javax.servlet.Servlet

getHttpPresentationRequest

protected com.lutris.appserver.server.httpPresentation.HttpPresentationRequest getHttpPresentationRequest(javax.servlet.http.HttpServletRequest req,
                                                                                                          javax.servlet.http.HttpServletResponse resp)
This method instantiates the HttpPresentationRequest object that the presentation manager expects when servicing a request.


getHttpPresentationResponse

protected com.lutris.appserver.server.httpPresentation.HttpPresentationResponse getHttpPresentationResponse(javax.servlet.http.HttpServletRequest req,
                                                                                                            javax.servlet.http.HttpServletResponse resp)
This method instantiates the HttpPresentationResponse object that the presentation manager expects when servicing a request.


getApplication

public com.lutris.appserver.server.Application getApplication()
Returns the application being run by this instance of the servlet.


getAppConfigInitParam

protected com.lutris.util.Config getAppConfigInitParam()
Returns the application configuration init parameter.


getAppConfigInitParamName

protected java.lang.String getAppConfigInitParamName()
Returns the application configuration init parameter name.


addFilter

public void addFilter(org.enhydra.servlet.filter.Filter filter)
Add a filter to the end of the list of filters.

Specified by:
addFilter in interface FilterableServlet

removeFilter

public void removeFilter(org.enhydra.servlet.filter.Filter filter)
Remove a filter from the list of current filters. Silently fails if the filter is not in the list.

Specified by:
removeFilter in interface FilterableServlet

service

public void service(javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
             throws javax.servlet.ServletException,
                    java.io.IOException
Handle a service request. Use the first filter to wrap the request, response, and servlet (this) objects. This will return new objects. Then use the second filter to wrap those, again returning new objects. Then use the fourth filter to wrap those etc.... Then finally call service() on the outermost results.


getSession

public com.lutris.appserver.server.session.Session getSession(javax.servlet.ServletRequest request)
Looks up the session object (if any) that would be used to process the request. This is will not used normally, because the session is give to the application's preprocessor method and the presentation objects. Also, it is not normal to have a raw ServletRequest. The debugger uses this to examine the session data before and after each request. Consider this an internal use only method.


checkAutoReload

private void checkAutoReload()
                      throws javax.servlet.ServletException
Check if the application should be automatically reloaded and, if so, call initApplication with a new instance of the class loader. The application should be reloaded if the autoReload flag is true and any class has changed in the application's classpath.


destroy

public void destroy()
Destroys the servlet. Called by the servlet manager when the servlet is shutdown.

Specified by:
destroy in interface javax.servlet.Servlet