EAF 7.4 Implementation

com.lutris.appserver.server.httpPresentation
Class HttpPresentationManager

java.lang.Object
  extended by com.lutris.appserver.server.httpPresentation.HttpPresentationManager

public class HttpPresentationManager
extends java.lang.Object

Presentation manager class. Handles loading and execution of presentation objects.

Version:
$Revision: 1.4 $
Author:
Mark Diekhans

Constructor Summary
HttpPresentationManager(java.lang.String appPresentationPrefix, com.lutris.appserver.server.Application presApplication, java.lang.ClassLoader applicationClassLoader, boolean cacheClasses, boolean cacheFiles)
          Construct a HTTP presentation manager.
 
Method Summary
 void addMimeType(java.lang.String mimeType, java.lang.String extension)
          Add a new mime type to extension mapping.
 void flushCache()
          Flush the presentation object and resource caches.
 java.lang.ClassLoader getAppClassLoader()
          Get the application class loader.
 java.io.InputStream getAppFileAsStream(java.lang.String appFileName)
          Get a file associated with the application.
 javax.servlet.Servlet getServlet()
          Get the servlet we are running in.
 javax.servlet.ServletContext getServletContext()
          Get the servlet context used to initialize the servlet we are running in.
 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.
 boolean isPOCacheEnabled()
          Determine if the PO cache is enabled.
 boolean isPresentationRequest(com.lutris.appserver.server.httpPresentation.HttpPresentationRequest request)
          Determine if a request URL references a presentation object.
 boolean isResourceCacheEnabled()
          Determine if the file resource class cache is enabled.
 void Run(com.lutris.appserver.server.httpPresentation.HttpPresentationRequest request, com.lutris.appserver.server.httpPresentation.HttpPresentationResponse response)
          The method is invoked to fulfill an HTTP request.
 boolean servletRequestPreprocessor(javax.servlet.Servlet me, javax.servlet.ServletContext context, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          This is an internal use only hook, see the description in Application.java.
 void setServletAndContext(javax.servlet.Servlet servlet, javax.servlet.ServletContext servletContext)
          Notify the presentation manager which servlet we are running in.
 int sizeofPOCache()
          Return the number of entries in the PO cache.
 int sizeofResourceCache()
          Return the number of entries in the resource cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpPresentationManager

public HttpPresentationManager(java.lang.String appPresentationPrefix,
                               com.lutris.appserver.server.Application presApplication,
                               java.lang.ClassLoader applicationClassLoader,
                               boolean cacheClasses,
                               boolean cacheFiles)
                        throws com.lutris.appserver.server.httpPresentation.HttpPresentationException
Construct a HTTP presentation manager.

Parameters:
appPresentationPrefix - Prefix added to the file name portion of the URL. The resulting names is used to search for classes and files on the class path.
presApplication - Application object that this presentation is associated with.
applicationClassLoader - the class loader to use for the application.
cacheClasses - Enables or disables caching of presentation object classes in memory.
cacheFiles - Enables or disables caching of files (html, gif, etc) that are servered as part of the application.
Throws:
com.lutris.appserver.server.httpPresentation.HttpPresentationException
Method Detail

Run

public void Run(com.lutris.appserver.server.httpPresentation.HttpPresentationRequest request,
                com.lutris.appserver.server.httpPresentation.HttpPresentationResponse response)
         throws com.lutris.appserver.server.httpPresentation.HttpPresentationException,
                java.io.IOException
The method is invoked to fulfill an HTTP request. This function is thread-safe and does not need synchronization. It is expected that the protocol layer invoking this function provide multi-threading to handle requests. The alogrithm for handling a request is:
 presObj = requestUrl
 while request-not-handled {
    if not error-handler-redirect
        invoke-application-request-preprocessor presObj
    load-presentation-object-class
    invoke-presentation-object
    if not error-handler-redirect
        invoke-application-request-postprocessor presObj
    if (client-side-page-redirect-exception) {
        send-redirect-to-client
        break
    }
    if (server-side-page-redirect-exception) {
        (Not implemented yet)
        set-request-to-redirectUrl
        presObj = redirectUrl
        continue
    }
    if (401-unauthorized-exception) {
        set-header-and-response-code
        break
    }
    if (other-exception) {
        presObj = find-error-handler
    }
 }
 

Parameters:
request - Request object for the protocol invoking the manager.
response - Response object for the protocol invoking the manager.
Throws:
HttpPresentationException - All exceptions will be encapsulated in an exception of this class.
java.io.IOException

servletRequestPreprocessor

public boolean servletRequestPreprocessor(javax.servlet.Servlet me,
                                          javax.servlet.ServletContext context,
                                          javax.servlet.http.HttpServletRequest request,
                                          javax.servlet.http.HttpServletResponse response)
                                   throws javax.servlet.ServletException,
                                          java.io.IOException
This is an internal use only hook, see the description in Application.java. The call is passed through to the application.

Throws:
javax.servlet.ServletException
java.io.IOException

isPOCacheEnabled

public boolean isPOCacheEnabled()
Determine if the PO cache is enabled.

Returns:
true is the cache is enabled.

sizeofPOCache

public int sizeofPOCache()
Return the number of entries in the PO cache.

Returns:
the number of entries in the cache or 0 is disabled.

isResourceCacheEnabled

public boolean isResourceCacheEnabled()
Determine if the file resource class cache is enabled.

Returns:
true is the cache is enabled.

sizeofResourceCache

public int sizeofResourceCache()
Return the number of entries in the resource cache.

Returns:
the number of entries in the cache or 0 is disabled.

getAppFileAsStream

public java.io.InputStream getAppFileAsStream(java.lang.String appFileName)
                                       throws java.io.IOException,
                                              com.lutris.appserver.server.httpPresentation.HttpPresentationException
Get a file associated with the application. The file is located in the same manner as presentation objects are located. That is, prepending the presentationPrefix to the specified path and searching the class path for a directory or JAR containing the file.

Parameters:
appfileName - The file name relative to the to the application's presentationPrefix.
Returns:
An input stream associated with the file.
Throws:
java.io.IOException - If the file can not be found or opened.
com.lutris.appserver.server.httpPresentation.HttpPresentationException

isPresentationRequest

public boolean isPresentationRequest(com.lutris.appserver.server.httpPresentation.HttpPresentationRequest request)
                              throws com.lutris.appserver.server.httpPresentation.HttpPresentationException
Determine if a request URL references a presentation object.

Parameters:
request - The request for the presentation.
Returns:
true if the URL has a presentation object MIME type.
Throws:
com.lutris.appserver.server.httpPresentation.HttpPresentationException

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

Parameters:
request - The (raw) request that would be sent in to this application.
Returns:
The session object that would be associated with the request. Returns null if none is found; a new session is not created.

setServletAndContext

public void setServletAndContext(javax.servlet.Servlet servlet,
                                 javax.servlet.ServletContext servletContext)
Notify the presentation manager which servlet we are running in. This will be done immediatly after this object is created, if this ojbject is created by an HttpPresentationServlet (currently the only creator). In the future, if this class is used in non-servlet situations, this need not be called.

Parameters:
servlet - The servlet we are running in.
servletContext - The ServletContext used to initialize the servlet we are running in.

getServlet

public javax.servlet.Servlet getServlet()
Get the servlet we are running in. Currently this class is only used in a servlet (HttpPresentationServlet), so this value will always be set. But in the future this class may be used in other non-servlet enviornments, in which case this method will return null.

Returns:
The servlet we are running in, if any.

getServletContext

public javax.servlet.ServletContext getServletContext()
Get the servlet context used to initialize the servlet we are running in. Currently this class is only used in a servlet (HttpPresentationServlet), so this value will always be set. But in the future this class may be used in other non-servlet enviornments, in which case this method will return null.

Returns:
The servlet context used to initialize the servlet we are running in, if any.

flushCache

public void flushCache()
Flush the presentation object and resource caches.


addMimeType

public void addMimeType(java.lang.String mimeType,
                        java.lang.String extension)
Add a new mime type to extension mapping.


getAppClassLoader

public java.lang.ClassLoader getAppClassLoader()
Get the application class loader.

Returns:
The application class loader.

EAF 7.4 Implementation