com.creamtec.ajaxswing

## Class ServletHelper

- java.lang.Object
- - com.creamtec.ajaxswing.ServletHelper

- All Implemented Interfaces:
    AjaxSwingServlet

      public final class ServletHelper
      extends java.lang.Object
      implements AjaxSwingServlet

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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `APP_NAME`
    `FileUploadHandler` | `fileUploadHandler`
    `static java.lang.String` | `PROPS_FILE_NAME`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static long` | `copyInputToOutput(java.io.InputStream input, java.io.OutputStream output)` Copy bytes from an `InputStream` to an `OutputStream`.
    `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
    `AgentInitData` | `getAgentInitData(AppDesc appDesc, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `AppDesc` | `getAppDesc(javax.servlet.http.HttpServletRequest request, java.lang.String appName)` Returns the application descriptor for a given request
    `ClientAgentRemote` | `getClientAgent(AppDesc appDesc, javax.servlet.http.HttpServletRequest request, HttpRequestData requestData, 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\AjaxSwing and it's needed for SnapshotRenderer temp directory
    `static ServletHelper` | `getInstance(javax.servlet.ServletContext servletContext)` 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
    `static java.lang.String` | `getServerURL(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, javax.servlet.http.HttpServletResponse response)` 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 requestData)` 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
    `void` | `shutdownAllAgents()`

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

    - #### shutdownAllAgents

          public void shutdownAllAgents()

    - #### processHttpRequest

          public void processHttpRequest(javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
                                  throws 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:
        `java.io.IOException`

    - #### copyInputToOutput

          public static long copyInputToOutput(java.io.InputStream input,
                               java.io.OutputStream output)
                                        throws java.io.IOException

      Copy bytes from an `InputStream` to an `OutputStream`.

      This method buffers the input internally, so there is no need to use a `BufferedInputStream`.

      Large streams (over 2GB) will return a bytes copied value of `-1` after the copy has completed since the correct number of bytes cannot be returned as an int. For large streams use the `copyLarge(InputStream, OutputStream)` method.

      Parameters:
        `input` - the `InputStream` to read from
        `output` - the `OutputStream` to write to
      Returns:
        the number of bytes copied
      Throws:
        `java.lang.NullPointerException` - if the input or output is null
        `java.io.IOException` - if an I/O error occurs
        `java.lang.ArithmeticException` - if the byte count is too large

    - #### getSubmitURL

          public java.lang.String getSubmitURL(AppDesc appDesc,
                                      javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response)

      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 AjaxSwingRouter 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\AjaxSwing and it's needed for SnapshotRenderer temp directory
      Throws:
        `java.lang.Exception`

    - #### getServerURL

          public static java.lang.String getServerURL(javax.servlet.http.HttpServletRequest request)

      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 requestData)
                                  throws java.lang.Exception

      Extracts and processes the request data
      Parameters:
        `appDesc` - application descriptor
        `request` - HttpServletRequest
        `requestData` - HttpRequestData
      Throws:
        `java.lang.Exception`

    - #### getClientAgent

          public ClientAgentRemote getClientAgent(AppDesc appDesc,
                                         javax.servlet.http.HttpServletRequest request,
                                         HttpRequestData requestData,
                                         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
        `requestData` - 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 `AjaxSwingServlet`
      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` - AjaxSwing internal session identification
        `agent` - ClientAgentRemote

    - #### getAgentInitData

          public AgentInitData getAgentInitData(AppDesc appDesc,
                                       javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response)
                                         throws java.lang.Exception

      Throws:
        `java.lang.Exception`

    - #### 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,
                           java.lang.String appName)
                             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)

      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)
                                           throws java.lang.Exception

      Returns the instance of the servlet helper
      Parameters:
        `servletContext` - ServletContext
        `sourceEncoding` - String
      Returns:
        ServletHelper
      Throws:
        `java.lang.Exception`

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