Enhydra 3.1 API

com.lutris.appserver.server
Class StandardApplication

java.lang.Object
  |
  +--com.lutris.appserver.server.StandardApplication

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.62.8.2 $

Field Summary
protected  java.lang.String appName
          The name of the application; defaults to the unqualified class name.
protected  Config config
          This applications config object.
protected  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  LogChannel logChannel
          The log channel for this application to write to.
protected  HttpPresentationManager presentationManager
          Presentation manager instance for application.
protected  boolean sendCookieForNewSession
          Determines if a cookie with the session id is sent to the client.
protected  SessionManager sessionManager
          Session manager for all application sessions.
protected  int state
          Current state of the application.
protected  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(Config databaseMgrConfig)
          Create the database manager to be used by this application.
protected  Session createSession(HttpPresentationComms comms)
          Create a new session for application.
protected  SessionManager createSessionManager(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(HttpPresentationComms comms)
          Default method used by requestPreprocessor to ensure that a session exists and initialize the session and sessionData fields in the HttpPresentationComms object.
 ApplicationData getApplicationData()
          Application Data accessable through Jolt Fields.
 Config getConfig()
          Get the application's config object.
 DatabaseManager getDatabaseManager()
          Get the DatabaseManager associated with this application.
 HttpPresentationManager getHttpPresentationManager()
          Get the HttpPresentationManager associated with this 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.
 XMLCFactory getXMLCFactory()
          Get the XMLC factory object being used by the application.
protected  void initializeNewSession(HttpPresentationComms comms)
          This is called when no valid session is found in an incoming request.
 void printCopyrightHeader()
           
 void requestPostProcessor(HttpPresentationComms comms)
          Calls application session manager's passivateSession method for the session associated with this request.
 boolean requestPreprocessor(HttpPresentationComms comms)
          Default application request preprocessor.
 void restartup(Config appConfig)
          Continue the startup up process with the application is in the INCOMPLETE state.
 boolean servletRequestPreprocessor(Servlet servlet, ServletContext context, HttpServletRequest request, 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(HttpPresentationManager pm)
          Tells the application about the Presentation Manager running it.
 void setLogChannel(LogChannel chan)
          Set the LogChannel associated with this application.
 void setName(java.lang.String name)
          Set the application name.
 void setXMLCFactory(boolean enableReload, boolean enableRecompilation)
          Set the XMLC factory based on the recload and recompilation options.
 void shutdown()
          Shutdown the application.
 void startup(Config appConfig)
          Start the application.
 
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 HttpPresentationManager presentationManager
Presentation manager instance for application. The presentation manager handles incomming http requests.

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 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.

data

protected ApplicationData data
Application Data accessable through Jolt Fields.

xmlcFactory

protected XMLCFactory xmlcFactory
XMLC Factory.
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 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 name)
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(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.

printCopyrightHeader

public void printCopyrightHeader()

restartup

public void restartup(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

createSessionManager

protected SessionManager createSessionManager(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.

createDatabaseManager

protected DatabaseManager createDatabaseManager(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(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(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(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(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

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

getApplicationData

public ApplicationData getApplicationData()
Application Data accessable through Jolt Fields.
Specified by:
getApplicationData in interface Application

requestPreprocessor

public boolean requestPreprocessor(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 HttpPresentationManager getHttpPresentationManager()
Get the HttpPresentationManager associated with this application.
Specified by:
getHttpPresentationManager in interface Application
Returns:
The presentation manager.

setHttpPresentationManager

public void setHttpPresentationManager(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(Servlet servlet,
                                          ServletContext context,
                                          HttpServletRequest request,
                                          HttpServletResponse response)
                                   throws 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:
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 XMLCFactory getXMLCFactory()
Get the XMLC factory object being used by the application.
Specified by:
getXMLCFactory in interface Application

setXMLCFactory

public void setXMLCFactory(boolean enableReload,
                           boolean enableRecompilation)
Set the XMLC factory based on the recload and recompilation options.
Specified by:
setXMLCFactory in interface Application

Enhydra 3.1 API