EAF 7.4 API

com.lutris.appserver.server
Class StandardApplication

java.lang.Object
  extended by com.lutris.appserver.server.StandardApplication
All Implemented Interfaces:
Application

public abstract class StandardApplication
extends java.lang.Object
implements Application

Default application implementation. This class provides standard start/stop services. This can be used as a base class to derive Application objects.

Version:
$Revision: 1.21 $
Author:
Mark Diekhans

Nested Class Summary
static class StandardApplication.ContextMBean
           
 
Field Summary
protected  com.lutris.appserver.server.StandardApplication.ApplicationConfigMBean appConfigMBean
           
protected  java.lang.String appName
          The name of the application; defaults to the unqualified class name.
protected  com.lutris.util.Config config
          This applications config object.
protected  StandardApplication.ContextMBean contextMBean
           
protected  com.lutris.appserver.server.ApplicationData data
          Application Data accessable through Jolt Fields.
protected  DatabaseManager databaseManager
          Database manager instance for application.
protected  java.lang.String defaultUrl
          Default URL used for application if defined in Config file.
protected  org.enhydra.util.jivan.JivanFactory jivanFactory
          Jivan Factory.
protected  LogChannel logChannel
          The log channel for this application to write to.
protected  Logger logger
           
protected static LogChannel loggerSys
          The logger that logs on System.out.
protected  com.lutris.appserver.server.ResponsePostProcessingManager postProcessingManager
          Response Post Processing Manager instance for application.
protected  com.lutris.appserver.server.RequestPreProcessingManager preProcessingManager
          Request Pre Processing Manager instance for application.
protected  com.lutris.appserver.server.httpPresentation.HttpPresentationManager presentationManager
          Presentation manager instance for application.
protected  com.lutris.appserver.server.StandardApplication.PresentationManagerMBean presentationManagerMBean
           
protected  boolean sendCookieForNewSession
          Determines if a cookie with the session id is sent to the client.
protected  javax.management.MBeanServer server
           
protected  SessionManager sessionManager
          Session manager for all application sessions.
protected  com.lutris.appserver.server.StandardApplication.SessionManagerMBean sessionManagerMBean
           
protected  int state
          Current state of the application.
protected  org.enhydra.xml.xmlc.XMLCFactory xmlcFactory
          XMLC Factory.
 
Fields inherited from interface com.lutris.appserver.server.Application
DEAD, HALTED, INCOMPLETE, RUNNING, STOPPED
 
Constructor Summary
StandardApplication()
          A constructor with no arguments is required.
 
Method Summary
protected  DatabaseManager createDatabaseManager(com.lutris.util.Config databaseMgrConfig)
          Create the database manager to be used by this application.
protected  com.lutris.appserver.server.ResponsePostProcessingManager createPostProcessingManager(com.lutris.util.Config ppConfig)
          Create the response post-processing manager to be used by this application.
protected  com.lutris.appserver.server.RequestPreProcessingManager createPreProcessingManager(com.lutris.util.Config ppConfig)
          Create the request pre-processing manager to be used by this application.
protected  Session createSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
          Create a new session for application.
protected  SessionManager createSessionManager(com.lutris.util.Config sessionMgrConfig)
          Create the session manager to be used by this application.
 java.lang.String encodeUrl(java.lang.String url, java.lang.String sessionKey)
          Returns the specified url rewritten to include the sessionId
 java.lang.String encodeUrl(java.lang.String url, java.lang.String sessionKey, java.lang.String appName)
          Deprecated. Use encodeUrl(String,String)
protected  void ensureSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
          Default method used by requestPreprocessor to ensure that a session exists and initialize the session and sessionData fields in the HttpPresentationComms object.
 com.lutris.util.Config getConfig()
          Get the application's config object.
 DatabaseManager getDatabaseManager()
          Get the DatabaseManager associated with this application.
 com.lutris.appserver.server.httpPresentation.HttpPresentationManager getHttpPresentationManager()
          Get the HttpPresentationManager associated with this application.
 org.enhydra.util.jivan.JivanFactory getJivanFactory()
          Get the Jivan factory object being used by the application.
 LogChannel getLogChannel()
          Get the LogChannel associated with this application.
 java.lang.String getName()
          Get the application symbolic name.
 SessionManager getSessionManager()
          Get the SessionManager associated with this application.
 int getState()
          Get the application state.
 org.enhydra.xml.xmlc.XMLCFactory getXMLCFactory()
          Get the XMLC factory object being used by the application.
 void initDodsAsyncCaches()
          Initialize Asynchronous DODS Caches!
 void initDodsAsyncCaches(int threadNumber)
          Initialize Asynchronous DODS Caches!
protected  void initializeNewSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
          This is called when no valid session is found in an incoming request.
 void printCopyrightHeader()
           
 void requestPostProcessor(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
          Calls application session manager's passivateSession method for the session associated with this request.
 boolean requestPreprocessor(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
          Default application request preprocessor.
 void restartup(com.lutris.util.Config appConfig)
          Continue the startup up process with the application is in the INCOMPLETE state.
 boolean servletRequestPreprocessor(javax.servlet.Servlet servlet, javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This is a hook that allows applications to act on requests before they enter the Enhydra framework.
 void setCookieForNewSession(boolean flag)
          Tells the application if a cookie is used to bind new sessions to a client.
 void setHttpPresentationManager(com.lutris.appserver.server.httpPresentation.HttpPresentationManager pm)
          Tells the application about the Presentation Manager running it.
 void setJivanFactory(boolean reload)
          Initializes the Jivan factory object which can be used by application.
 void setLogChannel(LogChannel chan)
          Set the LogChannel associated with this application.
 void setName(java.lang.String applName)
          Set the application name.
 void setXMLCFactory()
          Set the XMLC factory based on the deferred parsing option.
 void shutdown()
          Shutdown the application.
 void shutdownWithoutMBeanUnRegistration()
          Shutdown the application.
 void startup(com.lutris.util.Config appConfig)
          Start the application.
 java.lang.String toHtml()
          Get the Application Info HTML presentation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sendCookieForNewSession

protected boolean sendCookieForNewSession
Determines if a cookie with the session id is sent to the client.


appName

protected java.lang.String appName
The name of the application; defaults to the unqualified class name.


state

protected int state
Current state of the application. Only modified by the derived application.


sessionManager

protected SessionManager sessionManager
Session manager for all application sessions. A session manager manages the creation, deletion and assocation of sessions with a user.


presentationManager

protected com.lutris.appserver.server.httpPresentation.HttpPresentationManager presentationManager
Presentation manager instance for application. The presentation manager handles incomming http requests.


preProcessingManager

protected com.lutris.appserver.server.RequestPreProcessingManager preProcessingManager
Request Pre Processing Manager instance for application. It handles additional http request processing.


postProcessingManager

protected com.lutris.appserver.server.ResponsePostProcessingManager postProcessingManager
Response Post Processing Manager instance for application. It handles additional http response processing.


databaseManager

protected DatabaseManager databaseManager
Database manager instance for application. The database manager manages logical database and is responsible for allocating connection, create transactions, etc.


config

protected com.lutris.util.Config config
This applications config object. Every application has a configuration object that is created from the application configuration file.

See Also:
Config

defaultUrl

protected java.lang.String defaultUrl
Default URL used for application if defined in Config file. This is used to redirect the user to the preferred start page if a URL equal to the root of this application is given. By setting this to index.html, it behaves in the same way as a http server.


logChannel

protected LogChannel logChannel
The log channel for this application to write to.


logger

protected Logger logger

loggerSys

protected static LogChannel loggerSys
The logger that logs on System.out.


data

protected com.lutris.appserver.server.ApplicationData data
Application Data accessable through Jolt Fields.


xmlcFactory

protected org.enhydra.xml.xmlc.XMLCFactory xmlcFactory
XMLC Factory.


jivanFactory

protected org.enhydra.util.jivan.JivanFactory jivanFactory
Jivan Factory.


server

protected javax.management.MBeanServer server

appConfigMBean

protected com.lutris.appserver.server.StandardApplication.ApplicationConfigMBean appConfigMBean

presentationManagerMBean

protected com.lutris.appserver.server.StandardApplication.PresentationManagerMBean presentationManagerMBean

sessionManagerMBean

protected com.lutris.appserver.server.StandardApplication.SessionManagerMBean sessionManagerMBean

contextMBean

protected StandardApplication.ContextMBean contextMBean
Constructor Detail

StandardApplication

public StandardApplication()
A constructor with no arguments is required.

Method Detail

getState

public int getState()
Get the application state. N.B. Purposely not syncronized for speed.

Specified by:
getState in interface Application
Returns:
The application's state code.

setCookieForNewSession

public void setCookieForNewSession(boolean flag)
Tells the application if a cookie is used to bind new sessions to a client. If no cookie is set, session ID's must be communicated by means of URL rewriting.

Parameters:
flag - indicates whether to send a cookie or not.

getConfig

public com.lutris.util.Config getConfig()
Get the application's config object.

Specified by:
getConfig in interface Application
Returns:
The application's config object.

setName

public void setName(java.lang.String applName)
Set the application name.

Specified by:
setName in interface Application
Parameters:
name - The new name for the application.

getName

public java.lang.String getName()
Get the application symbolic name. This is normally the package name of this application class.

N.B. Purposely not syncronized for speed.

Specified by:
getName in interface Application
Returns:
The symbolic name.

setLogChannel

public void setLogChannel(LogChannel chan)
Set the LogChannel associated with this application.

Specified by:
setLogChannel in interface Application
Parameters:
The - LogChannel to write to.

getLogChannel

public LogChannel getLogChannel()
Get the LogChannel associated with this application.

Specified by:
getLogChannel in interface Application
Returns:
The log channel or null if this application does not have one.

startup

public void startup(com.lutris.util.Config appConfig)
             throws ApplicationException
Start the application. The default method sets the state to RUNNING.

Specified by:
startup in interface Application
Parameters:
appConfig - Application configuration object.
Throws:
ApplicationException - If an error occurs starting the application.

initDodsAsyncCaches

public void initDodsAsyncCaches()
                         throws ApplicationException
Initialize Asynchronous DODS Caches!

Throws:
ApplicationException - If an error occurs restart the application.

initDodsAsyncCaches

public void initDodsAsyncCaches(int threadNumber)
                         throws ApplicationException
Initialize Asynchronous DODS Caches!

Parameters:
threadNumber - Number of parallel cache loading threads
Throws:
ApplicationException - If an error occurs restart the application.

printCopyrightHeader

public void printCopyrightHeader()

restartup

public void restartup(com.lutris.util.Config appConfig)
               throws ApplicationException
Continue the startup up process with the application is in the INCOMPLETE state. The default method generates an error, as the application should never be in the INCOMPLETE state if it doesn't implment this method.

Specified by:
restartup in interface Application
Parameters:
appConfig - The same appConfig object that was passed to startup.
Throws:
ApplicationException - If an error occurs restarting the application.

shutdown

public void shutdown()
Shutdown the application. The default method sets the state to STOPPED.

Specified by:
shutdown in interface Application

shutdownWithoutMBeanUnRegistration

public void shutdownWithoutMBeanUnRegistration()
Shutdown the application. The default method sets the state to STOPPED.


createSessionManager

protected SessionManager createSessionManager(com.lutris.util.Config sessionMgrConfig)
                                       throws ApplicationException
Create the session manager to be used by this application. By default this will return the Lutris standard session manager. This method can be overwritten to create a custom session manager.

Parameters:
sessionMgrConfig - Configuration object containing "SessionManager" keys. This can be null to use defaults.
Returns:
The session manager.
Throws:
ApplicationException - If an error occurs in creating a session manager.

createPreProcessingManager

protected com.lutris.appserver.server.RequestPreProcessingManager createPreProcessingManager(com.lutris.util.Config ppConfig)
Create the request pre-processing manager to be used by this application. This method can be overwritten to create a custom request pre-processing manager.

Parameters:
ppConfig - Configuration object containing "RequestPreProcessor" keys. This can be null to use none.
Returns:
The request pre-processor.

createPostProcessingManager

protected com.lutris.appserver.server.ResponsePostProcessingManager createPostProcessingManager(com.lutris.util.Config ppConfig)
Create the response post-processing manager to be used by this application. This method can be overwritten to create a custom response post-processing manager.

Parameters:
ppConfig - Configuration object containing "ResponsePostProcessor" keys. This can be null to use none.
Returns:
The response post-processor.

createDatabaseManager

protected DatabaseManager createDatabaseManager(com.lutris.util.Config databaseMgrConfig)
                                         throws ApplicationException
Create the database manager to be used by this application. By default this will return the Lutris StandardDatabaseManager. This method can be overwritten to create a custom session manager.

Parameters:
databaseMgrConfig - Configuration object containing "DatabaseManager" keys.
Throws:
ApplicationException - If an error occurs in creating a database manager.

createSession

protected Session createSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
                         throws ApplicationException
Create a new session for application. By default this will create the Lutris StandardSession. This method can be overwritten to create a custom session.

Parameters:
comms - Object containing request, response and redirect objects. Warning: comms.session and comms.sessionData will be null. they are filled in after this method returns.
Returns:
The session.
Throws:
ApplicationException - If an error occurs in creating the session.

ensureSession

protected void ensureSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
                      throws ApplicationException
Default method used by requestPreprocessor to ensure that a session exists and initialize the session and sessionData fields in the HttpPresentationComms object. New sessions are only created on requests to presentation objects, not requests for other types of files (such as gifs). This avoids allocating multiple sessions when a browser makes multiple requests for HREFs. If the session already exist, it is alwasy set in comms

This normally looks up the session using a session key from a cookie.

Parameters:
comms - Object containing request, response and redirect objects.
Throws:
ApplicationException - If an error occurs setting up the session.

requestPostProcessor

public void requestPostProcessor(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
                          throws ApplicationException
Calls application session manager's passivateSession method for the session associated with this request.

Specified by:
requestPostProcessor in interface Application
Parameters:
comms - Object containing request, response and redirect objects.
Throws:
ApplicationException - If the session manager was unable to "passivate" the session.
See Also:
com.lutris.appserver.server.session.SessionManager.passivateSession

initializeNewSession

protected void initializeNewSession(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
                             throws ApplicationException
This is called when no valid session is found in an incoming request. A new session is created and added to comms. If sending session cookies is enabled, a cookie is created and added to the response, so future requests will be associated with the newly created session. If sending session cookies is disabled, it is the application's responsibility to include the session ID in URLs to associate further requests with the session.

Warning: At first comms.session and comms.sessionData are null. This method initializes them both.

Parameters:
comms - Object containing request, response and redirect objects. Session and SessionData objects are initialized.
Throws:
ApplicationException - If an error occurs setting up the session.
See Also:
setCookieForNewSession(boolean)

encodeUrl

public java.lang.String encodeUrl(java.lang.String url,
                                  java.lang.String sessionKey)
                           throws ApplicationException
Returns the specified url rewritten to include the sessionId

Parameters:
url - String to urlencode
Returns:
the param url rewritten to contain the sessionId
Throws:
ApplicationException

encodeUrl

public java.lang.String encodeUrl(java.lang.String url,
                                  java.lang.String sessionKey,
                                  java.lang.String appName)
                           throws ApplicationException
Deprecated. Use encodeUrl(String,String)

Returns the specified url rewritten to include the sessionId

Parameters:
url - String to urlencode
Returns:
the param url rewritten to contain the sessionId
Throws:
ApplicationException

requestPreprocessor

public boolean requestPreprocessor(com.lutris.appserver.server.httpPresentation.HttpPresentationComms comms)
                            throws java.lang.Exception
Default application request preprocessor. This method sets up a session data structure if a cookie is not set for the application. It doesn't require a login however. The unauthenticated session is useful for persistence in simple applications. It is possible to later force a login. If the URL is not a reference to a presentation object, then a session will not be allocated if it does not already exist. This prevents allocation of multiple sessions when a browser is requesting other objects, such as gifs, in parallel. Thus, after this function is called, it is possible for session to be null.

N.B. Purposely not syncronized for speed/concurrency.

Specified by:
requestPreprocessor in interface Application
Parameters:
comms - Object containing request, response and redirect objects.
Returns:
Always returns false, as request handling is not done.
Throws:
java.lang.Exception - May throw any exception, as with a presentation object; including page redirects.

getSessionManager

public SessionManager getSessionManager()
Get the SessionManager associated with this application.

Specified by:
getSessionManager in interface Application
Returns:
The session manager or null if the application doesn't have a SessionManager.

getDatabaseManager

public DatabaseManager getDatabaseManager()
Get the DatabaseManager associated with this application.

Specified by:
getDatabaseManager in interface Application
Returns:
The database manager or null if the application doesn't have a DatabaseManager.

getHttpPresentationManager

public com.lutris.appserver.server.httpPresentation.HttpPresentationManager getHttpPresentationManager()
Get the HttpPresentationManager associated with this application.

Specified by:
getHttpPresentationManager in interface Application
Returns:
The presentation manager.

setHttpPresentationManager

public void setHttpPresentationManager(com.lutris.appserver.server.httpPresentation.HttpPresentationManager pm)
Tells the application about the Presentation Manager running it. This is necessary because the presentation manager is created before the application.

Specified by:
setHttpPresentationManager in interface Application
Parameters:
pm - The HTTP presentation manager running this application.

servletRequestPreprocessor

public boolean servletRequestPreprocessor(javax.servlet.Servlet servlet,
                                          javax.servlet.ServletContext context,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                                   throws javax.servlet.ServletException,
                                          java.io.IOException
This is a hook that allows applications to act on requests before they enter the Enhydra framework. This implementation always returns false, so the request is processed normally. Do not override this unless you absolutly have to. Currently the only application that needs to is the debugger, because it needs to hand off requests to other non-Enhydra servlets.

In contrast, the method requestPreprocessor() is commonly overridden. It provides applications with a centeral place to put code that has to be run on every request before it is sent to the presentation objects.

Specified by:
servletRequestPreprocessor in interface Application
Parameters:
servlet - The servlet we are running in.
context - The ServletContext that was used to initialize our servlet.
request - The incomming request object.
response - The incomming response object.
Returns:
True if this method handled the request, in which case no further action will be taken. Or false if normal processing should continue.
Throws:
javax.servlet.ServletException - You are allowed to throw the same exceptions that the servlet's service() method throws.
java.io.IOException - You are allowed to throw the same exceptions that the servlet's service() method throws.

getXMLCFactory

public org.enhydra.xml.xmlc.XMLCFactory getXMLCFactory()
Get the XMLC factory object being used by the application.

Specified by:
getXMLCFactory in interface Application

setXMLCFactory

public void setXMLCFactory()
Set the XMLC factory based on the deferred parsing option.

Specified by:
setXMLCFactory in interface Application

setJivanFactory

public void setJivanFactory(boolean reload)
Initializes the Jivan factory object which can be used by application.

Specified by:
setJivanFactory in interface Application
Parameters:
reload - swich which indicates realoading status of Jivan generated pages in presentation layer (true = reload is on, false = reload is off)

getJivanFactory

public org.enhydra.util.jivan.JivanFactory getJivanFactory()
Get the Jivan factory object being used by the application.

Specified by:
getJivanFactory in interface Application

toHtml

public java.lang.String toHtml()
Get the Application Info HTML presentation.


EAF 7.4 API