creamtec.webcream
Class ServletHelper

java.lang.Object
  extended by creamtec.webcream.ServletHelper
All Implemented Interfaces:
WebCreamServlet

public class ServletHelper
extends java.lang.Object
implements WebCreamServlet

Provides implementation for most of the logic of processing an incoming HTTP servlet request and forwarding it to a client agent.


Nested Class Summary
 class ServletHelper.InProcessAppDesc
          Declare this class to resolve classpath to the application classes.
static class ServletHelper.InProcessClientAgent
          Declare this class to resolve classpath to the application classes.
 
Field Summary
static java.lang.String APP_NAME
           
 FileUploadHandler fileUploadHandler
           
static java.lang.String PROPS_FILE_NAME
           
 
Method Summary
 ClientAgent createClientAgent(java.lang.String appName)
          Creates a new client agent.
 java.lang.String decodeValue(java.lang.String value)
          Decode value from the source encoding into internal UTF8 encoding
 AppDesc getAppDesc(javax.servlet.http.HttpServletRequest request, HttpRequestData data)
          Returns the application descriptor for a given request
 ClientAgentRemote getClientAgent(AppDesc appDesc, javax.servlet.http.HttpServletRequest request, HttpRequestData data, javax.servlet.http.HttpServletResponse response)
          Returns a client agent that should process the given request.
static int getClientId(ClientAgentRemote agent)
          We have to use Object's implementation of hashCode() because RemoteObject always return the same value for all out-of-process agents
 java.lang.String getDocsRealPath(AppDesc appDesc, javax.servlet.http.HttpServletRequest request)
          Real path is disk path such as C:\Java\WebCream and it's needed for SnapshotRenderer temp directory
 java.lang.String getErrorPage(AppDesc appDesc, java.lang.Throwable x, javax.servlet.http.HttpServletRequest request)
          Renders a simple error page used for system errors.
static ServletHelper getInstance(javax.servlet.ServletContext servletContext, java.lang.String sourceEncoding)
          Returns the instance of the servlet helper
static java.lang.String getListenerName(java.lang.String appName)
          Helper method to return the listener name for a given application name
 java.lang.String getParameterValue(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Returns the value of the given request parameter
 java.lang.String[] getParameterValues(javax.servlet.http.HttpServletRequest request, java.lang.String name)
          Returns all values of a HTTP request parameter.
 RouterRequestFilter getRequestFilter()
          Returns the request filter instance
 java.lang.String getServerURL(AppDesc appDesc, javax.servlet.http.HttpServletRequest request)
          Obtains the web server URL based on the scheme, port and web app context.
 java.lang.Object getSessionAttribute(javax.servlet.http.HttpSession session, java.lang.String name)
          Version-safe way of getting a value from a session
 java.lang.String getSubmitURL(AppDesc appDesc, javax.servlet.http.HttpServletRequest request)
          Obtains the submit URL based on the application configuration or the request URL
 void parseAppNameAndAction(javax.servlet.http.HttpServletRequest request, HttpRequestData data)
          Obtain application name and the requested action from HTTP parameters and query string
 void processHttpRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Extracts parameters from HttpServletRequest, finds (creates) a client agent and delegates to it for processing and HTML generation.
 void processRequestData(AppDesc appDesc, javax.servlet.http.HttpServletRequest request, HttpRequestData data)
          Extracts and processes the request data
 boolean processRouterMode(javax.servlet.http.HttpServletRequest request, HttpRequestData data)
          Sets the servlet parameters such as the application name and action based on the deployment method
 void removeSessionAttribute(javax.servlet.http.HttpSession session, java.lang.String name)
          Version-safe way of removing a value from a session
 void setDataFromPath(HttpRequestData data, java.lang.String path)
          Extracts the servlet parameters such as the application name and action from the given string
 void setSessionAttribute(javax.servlet.http.HttpSession session, java.lang.String name, java.lang.Object value)
          Version-safe way of storing a value in a session
 void shutdown()
          Shuts down agents and all running external JVMs
static void shutdownAgent(AppDesc appDesc, java.lang.Integer sessionId, ClientAgentRemote agent)
          Shuts down the client agent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fileUploadHandler

public FileUploadHandler fileUploadHandler

APP_NAME

public static final java.lang.String APP_NAME
See Also:
Constant Field Values

PROPS_FILE_NAME

public static final java.lang.String PROPS_FILE_NAME
See Also:
Constant Field Values
Method Detail

getParameterValue

public java.lang.String getParameterValue(javax.servlet.http.HttpServletRequest request,
                                          java.lang.String name)
                                   throws java.lang.Exception
Returns the value of the given request parameter

Parameters:
request - HttpServletRequest
name - parameter name
Returns:
parameter value
Throws:
java.lang.Exception

getParameterValues

public java.lang.String[] getParameterValues(javax.servlet.http.HttpServletRequest request,
                                             java.lang.String name)
                                      throws java.lang.Exception
Returns all values of a HTTP request parameter. For instance, lists with multiple selection return all selected items.

Parameters:
request - HttpServletRequest
name - parameter name
Returns:
array of values
Throws:
java.lang.Exception

decodeValue

public java.lang.String decodeValue(java.lang.String value)
                             throws java.lang.Exception
Decode value from the source encoding into internal UTF8 encoding

Parameters:
value - String
Returns:
String
Throws:
java.lang.Exception

shutdown

public void shutdown()
Shuts down agents and all running external JVMs


processHttpRequest

public void processHttpRequest(javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException,
                               java.io.IOException
Extracts parameters from HttpServletRequest, finds (creates) a client agent and delegates to it for processing and HTML generation.

Parameters:
request - HttpServletRequest
response - HttpServletResponse
Throws:
javax.servlet.ServletException
java.io.IOException

getErrorPage

public java.lang.String getErrorPage(AppDesc appDesc,
                                     java.lang.Throwable x,
                                     javax.servlet.http.HttpServletRequest request)
Renders a simple error page used for system errors. Can't use StandardPageRenderer because we don't have a client agent yet


getSubmitURL

public java.lang.String getSubmitURL(AppDesc appDesc,
                                     javax.servlet.http.HttpServletRequest request)
                              throws java.lang.Exception
Obtains the submit URL based on the application configuration or the request URL

Parameters:
appDesc - application descriptor
request - HttpServletRequest
Returns:
URL used to submit pages to WebCreamRouter servlet
Throws:
java.lang.Exception

getDocsRealPath

public java.lang.String getDocsRealPath(AppDesc appDesc,
                                        javax.servlet.http.HttpServletRequest request)
                                 throws java.lang.Exception
Real path is disk path such as C:\Java\WebCream and it's needed for SnapshotRenderer temp directory

Throws:
java.lang.Exception

getServerURL

public java.lang.String getServerURL(AppDesc appDesc,
                                     javax.servlet.http.HttpServletRequest request)
                              throws java.lang.Exception
Obtains the web server URL based on the scheme, port and web app context.

Parameters:
appDesc - AppDesc
request - HttpServletRequest
Returns:
String
Throws:
java.lang.Exception

processRequestData

public void processRequestData(AppDesc appDesc,
                               javax.servlet.http.HttpServletRequest request,
                               HttpRequestData data)
                        throws java.lang.Exception
Extracts and processes the request data

Parameters:
appDesc - application descriptor
request - HttpServletRequest
data - HttpRequestData
Throws:
java.lang.Exception

getClientAgent

public ClientAgentRemote getClientAgent(AppDesc appDesc,
                                        javax.servlet.http.HttpServletRequest request,
                                        HttpRequestData data,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws java.lang.Exception
Returns a client agent that should process the given request. The agent is first looked up based on the session information. If an existing agent is not found, a new one is created and initialized.

Parameters:
appDesc - application descriptor
request - HttpServletRequest
data - HttpRequestData
response - HttpServletResponse
Returns:
ClientAgentRemote
Throws:
java.lang.Exception

createClientAgent

public ClientAgent createClientAgent(java.lang.String appName)
                              throws java.lang.Exception
Creates a new client agent.

Specified by:
createClientAgent in interface WebCreamServlet
Parameters:
appName - application name
Returns:
ClientAgent
Throws:
java.lang.Exception

shutdownAgent

public static void shutdownAgent(AppDesc appDesc,
                                 java.lang.Integer sessionId,
                                 ClientAgentRemote agent)
Shuts down the client agent

Parameters:
appDesc - application descriptor
sessionId - WebCream internal session identification
agent - ClientAgentRemote

getClientId

public static int getClientId(ClientAgentRemote agent)
We have to use Object's implementation of hashCode() because RemoteObject always return the same value for all out-of-process agents

Parameters:
agent -
Returns:
unique client agent id

getAppDesc

public AppDesc getAppDesc(javax.servlet.http.HttpServletRequest request,
                          HttpRequestData data)
                   throws java.lang.Exception
Returns the application descriptor for a given request

Parameters:
request - HttpServletRequest
data - HttpRequestData
Returns:
AppDesc
Throws:
java.lang.Exception

parseAppNameAndAction

public void parseAppNameAndAction(javax.servlet.http.HttpServletRequest request,
                                  HttpRequestData data)
                           throws java.lang.Exception
Obtain application name and the requested action from HTTP parameters and query string

Throws:
java.lang.Exception

processRouterMode

public boolean processRouterMode(javax.servlet.http.HttpServletRequest request,
                                 HttpRequestData data)
                          throws java.lang.Exception
Sets the servlet parameters such as the application name and action based on the deployment method

Parameters:
request - HttpServletRequest
data - HttpRequestData
Returns:
true if the method was able to determine the deployment method
Throws:
java.lang.Exception

getSessionAttribute

public java.lang.Object getSessionAttribute(javax.servlet.http.HttpSession session,
                                            java.lang.String name)
                                     throws java.lang.Exception
Version-safe way of getting a value from a session

Parameters:
session - HttpSession
name - attribute name
Returns:
value
Throws:
java.lang.Exception

setSessionAttribute

public void setSessionAttribute(javax.servlet.http.HttpSession session,
                                java.lang.String name,
                                java.lang.Object value)
                         throws java.lang.Exception
Version-safe way of storing a value in a session

Parameters:
session - HttpSession
name - attribute name
value - attribute value
Throws:
java.lang.Exception

removeSessionAttribute

public void removeSessionAttribute(javax.servlet.http.HttpSession session,
                                   java.lang.String name)
                            throws java.lang.Exception
Version-safe way of removing a value from a session

Parameters:
session - HttpSession
name - attribute name
Throws:
java.lang.Exception

setDataFromPath

public void setDataFromPath(HttpRequestData data,
                            java.lang.String path)
                     throws java.lang.Exception
Extracts the servlet parameters such as the application name and action from the given string

Parameters:
data - HttpRequestData
path - String
Throws:
java.lang.Exception

getListenerName

public static java.lang.String getListenerName(java.lang.String appName)
Helper method to return the listener name for a given application name

Parameters:
appName - String
Returns:
String

getRequestFilter

public RouterRequestFilter getRequestFilter()
Returns the request filter instance

Returns:
RouterRequestFilter or null

getInstance

public static ServletHelper getInstance(javax.servlet.ServletContext servletContext,
                                        java.lang.String sourceEncoding)
                                 throws java.lang.Exception
Returns the instance of the servlet helper

Parameters:
servletContext - ServletContext
sourceEncoding - String
Returns:
ServletHelper
Throws:
java.lang.Exception


Copyright © 2000-2006 CreamTec LLC. All Rights Reserved.