com.ibm.dse.cs.servlet
Class CSReqServlet

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--com.ibm.dse.cs.servlet.CSReqServlet
Direct Known Subclasses:
CSEstablishSessionServlet, CSReqProtocolServlet, XmlRequestServlet

public class CSReqServlet
extends javax.servlet.http.HttpServlet
implements ChannelDriver

The CSReqServlet implements the ChannelDriver interface

This servlet defines the front door for all devices supporting the HTTP protocol This class implements HTTP specifical behaviour for saving the information associated to a session into a databse using the service suplies by the WebSphere through the HttpSession class. For this example, the parent context for ALL the workstation contexts is the "root" context. To use the data persistence you must set the value of the tag "channelHandlers.html.requestHandler" of the dse.ini file to: com.ibm.dse.cs.html.ext.PersistHtmlRequestHandler It's also possible to specify if exists session affinity or not with the tag "initialization.sessionAffinity" of the dse.ini file. By default session affinity is assumed. To specify that there isn't session affinity sets its value to "no" ( or "false", or "0", or "disable" ). To use this feature you must activate the persistence of the session of the WebSphere, see the WebSphere documentation.

See Also:
Serialized Form

Field Summary
protected  boolean sessionAffinity
          Indicates whether the server configuration features session affinity.
protected  boolean sessionPersistence
          Indicates whether the server is configured to work under persistence conditions.
 
Constructor Summary
CSReqServlet()
          CSServlet constructor.
 
Method Summary
 ChannelContext createChannelContext(java.lang.Object req, java.lang.Object res, java.lang.Object driver)
          Creates a ChannelContext object with the req, res, driver attributes.
 void createChannelHandler(ChannelContext channelContext)
          Creates a ChannelHandler object with the channelContext attribute.
protected  void createSessionEntry(java.lang.Object sessionObject)
          Restore the information.
protected  void getDeviceType(ChannelContext channelContext)
          Determine the device type for the handler and add to the ChannelContext object.
protected  PresentationHandler getPresentationHandler(ChannelContext channelContext)
          Determine the PresentationHandler to invoke for the specific channel driver
protected  RequestHandler getRequestHandler(ChannelContext channelContext)
          Determine the RequestHandler to invoke for the specific channel driver
 boolean getSessionAffinity()
          Returns the value of the attribute sessionAffinity.
 boolean getSessionPersistence()
          Returns the value of the attribute sessionPersistence.
protected  void handleException(ChannelContext channelContext, java.lang.Exception ex)
          Invoke the presentation handler to pass the exception to the client
protected  void handleException(java.lang.Exception ex)
          Log the exception with the framwework trace facility
protected  void handleServerResponse(ChannelContext channelContext, java.lang.Exception e)
          Convenience method to ensure that a response is returned to the client for the case where no presentation handler exists or because the server is not initialized.
 void parseRequestData(ChannelContext channelContext)
          Parse the contents of the parameters contained in the HttpServletRequest
 void parseRequestHeader(ChannelContext channelContext)
          Parse the contents of the header contained in the HttpServletRequest
 void preProcessRequest(ChannelContext channelContext)
          Perform any session management/control required at the device level.
protected  void removeSessionEntry(java.lang.Object sessionObject)
          Removes an entry of the session table.
 void retrieve(ChannelContext channelContext)
          Restores the data associated to the session saved previously.
protected  void retrieveWithoutSessionAffinity(ChannelContext channelContext)
          Restore the information when there isn't session affinity.
protected  void retrieveWithSessionAffinity(ChannelContext channelContext)
          Restore the information when there is session affinity.
protected  boolean runInSession(ChannelContext channelContext)
          Determine from the HandlerRegistry if the device type should run in session
protected  void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Define the process flow to execute a request.
protected  void setSessionAffinity()
          Gets from the initialization file (dse.ini) the value of the tag initialization.sessionAffinity, and sets the value of the attribute sessionAffinity.
 void setSessionAffinity(boolean sessAffinity)
          Sets the value of the attribute sessionAffinity.
protected  void setSessionPersistence()
          Gets from the initialization file (dse.ini) the value of the tag initialization.sessionPersistence, and sets the value of the attribute sessionPersistence.
 void setSessionPersistence(boolean newSessionPersistence)
          Sets the value of the attribute sessionPersistence.
 void store(ChannelContext channelContext)
          Saves the information associated to the session sessionId through the HttpSession.
protected  void updateChannelHandler(ChannelHandler ch, java.lang.String key, java.lang.String value)
          Special processing required for the channel specific parameters in the server dse.ini file
protected  boolean usingCookies(ChannelContext channelContext)
          Determine from the HandlerRegistry if the device type is using cookies to manage the session
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sessionAffinity

protected boolean sessionAffinity
Indicates whether the server configuration features session affinity. This attribute is specifical for HttpSession persistence.

sessionPersistence

protected boolean sessionPersistence
Indicates whether the server is configured to work under persistence conditions.
Constructor Detail

CSReqServlet

public CSReqServlet()
CSServlet constructor.
Method Detail

createChannelContext

public ChannelContext createChannelContext(java.lang.Object req,
                                           java.lang.Object res,
                                           java.lang.Object driver)
Creates a ChannelContext object with the req, res, driver attributes.

The parameters are passed as objects to support all potential channel drivers

Specified by:
createChannelContext in interface ChannelDriver
Parameters:
req - java.lang.Object
res - java.lang.Object
rep - java.lang.Object
Returns:
com.ibm.dse.clientserver.ChannelContext - An instance of ChannelContext.

createChannelHandler

public void createChannelHandler(ChannelContext channelContext)
                          throws java.lang.Exception
Creates a ChannelHandler object with the channelContext attribute.

Cache the ChannelHandler into the HandlerRegistry singleton. Instiate RequestHandler, PresentationHandler and a Hashtable to contain all variable params located in the dse.ini file.

This should only be performed the first time that the channel is accessed

Specified by:
createChannelHandler in interface ChannelDriver
Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext

createSessionEntry

protected void createSessionEntry(java.lang.Object sessionObject)
                           throws DSEException
Restore the information. The information is always restored. This method is specifical for HttpSession persistence.

getDeviceType

protected void getDeviceType(ChannelContext channelContext)
                      throws DSENoRegisteredDeviceTypeException
Determine the device type for the handler and add to the ChannelContext object.

This is the default implementation to obtain the requester device type. Currently support (Java clients, Web Browsers and XML Clients)

The default implementation uses the "User-Agent" tag in the Http request header

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext

getPresentationHandler

protected PresentationHandler getPresentationHandler(ChannelContext channelContext)
                                              throws DSENoRegisteredPresentationHandlerException
Determine the PresentationHandler to invoke for the specific channel driver

Obtain the presenation handler from the HandlerRegistry

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
Returns:
com.ibm.dse.clientserver.PresenationHandler

getRequestHandler

protected RequestHandler getRequestHandler(ChannelContext channelContext)
                                    throws DSENoRegisteredRequestHandlerException
Determine the RequestHandler to invoke for the specific channel driver

Obtain the request handler from the HandlerRegistry

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
Returns:
com.ibm.dse.clientserver.RequestHandler

getSessionAffinity

public boolean getSessionAffinity()
Returns the value of the attribute sessionAffinity. This method is specifical for HttpSession persistence.
Returns:
boolean

getSessionPersistence

public boolean getSessionPersistence()
Returns the value of the attribute sessionPersistence.
Returns:
boolean

handleException

protected void handleException(ChannelContext channelContext,
                               java.lang.Exception ex)
Invoke the presentation handler to pass the exception to the client

Test to ensure that the server is started and the channel context has a device type. If the server is unable to process a response to the server trace the exception

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
ex - java.lang.Exception

handleException

protected void handleException(java.lang.Exception ex)
Log the exception with the framwework trace facility
Parameters:
ex - java.lang.Exception

handleServerResponse

protected void handleServerResponse(ChannelContext channelContext,
                                    java.lang.Exception e)
                             throws java.lang.Exception
Convenience method to ensure that a response is returned to the client for the case where no presentation handler exists or because the server is not initialized. By default, this implementation of the channel driver is trying to reply to an HTML client. The extensions of this driver which handle channels different than the HTML, should implement this method in order to reply with a channel compliant mechanism.
Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
java.lang.Exception -  
Throws:
java.lang.DSECSServerNotStartedException -  

parseRequestData

public void parseRequestData(ChannelContext channelContext)
                      throws java.lang.Exception
Parse the contents of the parameters contained in the HttpServletRequest

Parse to the request data into the KeyedCollection. Add the kColl to the ChannelContext request data

Override this method to modify the behaviour of the data parsing

Specified by:
parseRequestData in interface ChannelDriver
Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext

parseRequestHeader

public void parseRequestHeader(ChannelContext channelContext)
                        throws java.lang.Exception
Parse the contents of the header contained in the HttpServletRequest

Parse to the request header into the KeyedCollection. Add the kColl to the ChannelContext request data

Override this method to modify the behaviour of the data parsing

Specified by:
parseRequestHeader in interface ChannelDriver
Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext

preProcessRequest

public void preProcessRequest(ChannelContext channelContext)
                       throws DSECSSessionNotEstablishedException
Perform any session management/control required at the device level.

Insert the channel session into the ChannelContext

Must provide support for using cookies and hidden form field to manage the session.

Throw a DSECSSessionNotExtablishedException if the session has expired.

Specified by:
preProcessRequest in interface ChannelDriver
Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
Throws:
DSECSSessionNotEstablishedException -  

removeSessionEntry

protected void removeSessionEntry(java.lang.Object sessionObject)
                           throws DSEException
Removes an entry of the session table. The information is always restored. This method is specifical for HttpSession persistence.

retrieve

public void retrieve(ChannelContext channelContext)
              throws DSEException
Restores the data associated to the session saved previously. Checks if there is session affinity. This method is specifical for HttpSession persistence.

retrieveWithoutSessionAffinity

protected void retrieveWithoutSessionAffinity(ChannelContext channelContext)
                                       throws DSEException
Restore the information when there isn't session affinity. The information is always restored. This method is specifical for HttpSession persistence.

retrieveWithSessionAffinity

protected void retrieveWithSessionAffinity(ChannelContext channelContext)
                                    throws DSEException
Restore the information when there is session affinity. The information is only restored if the sessionId doesn't exist inside the session table. This method is specifical for HttpSession persistence.

runInSession

protected boolean runInSession(ChannelContext channelContext)
                        throws DSECSSessionNotEstablishedException
Determine from the HandlerRegistry if the device type should run in session

This requires that the application have a valid session and the opertation has a parent context. Default is true - always run in session for backwards compatibility.

If the request is to run out of session add the "dse_ignore" to the application id

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
Returns:
boolean

service

protected void service(javax.servlet.http.HttpServletRequest req,
                       javax.servlet.http.HttpServletResponse res)
                throws javax.servlet.ServletException,
                       java.io.IOException
Define the process flow to execute a request. This method is the entry point for each request coming to this servlet.
Overrides:
service in class javax.servlet.http.HttpServlet
Parameters:
req - HttpServletRequest
res - HttpServletResponse
Throws:
javax.servlet.ServletException -  
java.io.IOException -  

setSessionAffinity

protected void setSessionAffinity()
Gets from the initialization file (dse.ini) the value of the tag initialization.sessionAffinity, and sets the value of the attribute sessionAffinity. If its value is "false" then the WSBCC assumes that does not exist session affinity. By default is "true". This method is specifical for HttpSession persistence.

setSessionAffinity

public void setSessionAffinity(boolean sessAffinity)
Sets the value of the attribute sessionAffinity. This method is specifical for HttpSession persistence.
Parameters:
newSessionPersistence - boolean

setSessionPersistence

protected void setSessionPersistence()
Gets from the initialization file (dse.ini) the value of the tag initialization.sessionPersistence, and sets the value of the attribute sessionPersistence. If its value is "true" then the WSBCC assumes that the server is not configured to persist sessions. By default is "false". This method is specifical for HttpSession persistence.

setSessionPersistence

public void setSessionPersistence(boolean newSessionPersistence)
Sets the value of the attribute sessionPersistence.
Parameters:
newSessionPersistence - boolean

store

public void store(ChannelContext channelContext)
           throws DSEException
Saves the information associated to the session sessionId through the HttpSession. The key names assigned for each WSBCC item are: WSBCC item key name context dse_context timestamp dse_timestamp TID dse_TID expired dse_expired # of appls dse_applCount applications dse_applications java.util.Hashtable key value appl. id context This method is specifical for HttpSession persistence.

updateChannelHandler

protected void updateChannelHandler(ChannelHandler ch,
                                    java.lang.String key,
                                    java.lang.String value)
                             throws java.lang.Exception
Special processing required for the channel specific parameters in the server dse.ini file

Instantiate the instances of the PresentationHandler and RequestHandler. All other parameters are added to a Hashtable.

Parameters:
ch - com.ibm.dse.clientserver.ChannelHandler
key - java.lang.String
value - java.lang.String

usingCookies

protected boolean usingCookies(ChannelContext channelContext)
Determine from the HandlerRegistry if the device type is using cookies to manage the session

Default is to return false to support backwards compatibility.

Parameters:
channelContext - com.ibm.dse.clientserver.ChannelContext
Returns:
boolean