com.ibm.wsspi.webcontainer.servlet

Class GenericServletWrapper

  1. java.lang.Object
  2. extended bycom.ibm.wsspi.webcontainer.servlet.GenericServletWrapper
All implemented interfaces:
RequestProcessor, IServletWrapper

  1. public abstract class GenericServletWrapper
  2. extends java.lang.Object
  3. implements IServletWrapper
A convenience class that implements IServletWrapper. This class must be subclassed if IServletWrapper implementations want to leverage the webcontainer's handling of the following: -> Servlet lifecycle management -> Event generation and firing -> Request handling leveraging sessions and security Subclasses usually override the handleRequest() method wherein they implement logic specific to the container they are part of, and at the end call on super.handleRequest() which then handles the actual dispatch to the servlet and invokes the Servlet's service() method.
Since:
WAS6.0

Constructor Summary

Constructor and Description
GenericServletWrapper(IServletContext parent)
Public constructor.

Method Summary

Modifier and Type Method and Description
  1. void
addServletReferenceListener(ServletReferenceListener listener)
Add a listener which will listen to the invalidation events for this wrapper instance.
  1. void
destroy()
This method will be invoked when the parent container wishes to destroy this IServletWrapper instance.
  1. long
getLastAccessTime()
This method will be called by the webcontainer's reaper mechanism which polls for the access times of the wrappers in its datastructures, and invalidates them if they have been inactive for a preconfigured amount of time.
  1. java.lang.String
getName()
  1. IServletConfig
getServletConfig()
Returns the ServletConfig associated with the target
  1. ServletContext
getServletContext()
  1. java.lang.String
getServletName()
Returns the servlet name of the target
  1. Servlet
getTarget()
Returns the target Servlet instance
  1. java.lang.ClassLoader
getTargetClassLoader()
Returns the current classloader which loaded (or will, in the future, load) the target.
  1. void
handleRequest(ServletRequest req,ServletResponse res)
Method that processes the request, and ultimately invokes the service() on the Servlet target.
  1. void
initialize(IServletConfig config)
Method that handles the initialization of this IServletWrapper instance.
  1. boolean
isAvailable()
Returns whether the requested wrapper resource exists.
  1. boolean
isInternal()
  1. void
load()
  1. void
loadOnStartupCheck()
  1. void
modifyTarget(Servlet s)
  1. void
nameSpacePostInvoke()
  1. void
nameSpacePreInvoke()
  1. void
prepareForReload()
Gracefully invalidates the target by overseeing its lifecycle (destroy()) This method must be called before the target is invalidated for reload.
  1. void
service(ServletRequest request,ServletResponse response)
  1. void
setParent(IServletContext parent)
  1. void
setTarget(Servlet target)
Sets the target for this IServletWrapper.
  1. void
setTargetClassLoader(java.lang.ClassLoader loader)
Instructs the underlying implementation to use the supplied class loader to instantiate the target instance.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

GenericServletWrapper

  1. public GenericServletWrapper(IServletContext parent)
  2. throws java.lang.Exception
Public constructor. This contructor must be invoked from within the constructor of the subclass passing in the IServletContext so that the parent object can be constructed correctly.
Parameters:
parent - The IServletContext that this IServletWrapper will be a part of
Throws:
java.lang.Exception

Method Detail

initialize

  1. public void initialize(IServletConfig config)
  2. throws java.lang.Exception
Method that handles the initialization of this IServletWrapper instance. Subclasses must call this by invoking super.initialize(config), so that the underlying target Servlet can be setup and initialized by calling its init() method (if specified in the config as loadAtStartUp).
Specified by:
Parameters:
config - the IServletConfig associated with this IServletWrapper
Throws:
java.lang.Exception
See Also:

handleRequest

  1. public void handleRequest(ServletRequest req,
  2. ServletResponse res)
  3. throws java.lang.Exception
Method that processes the request, and ultimately invokes the service() on the Servlet target. Subclasses may override this method to put in additional logic (eg., reload/retranslation logic in the case of JSP containers). Subclasses must call this method by invoking super.handleRequest() if they want the webcontainer to handle initialization and servicing of the target in a proper way. An example scenario: class SimpleJSPServletWrapper extends GenericServletWrapper { ... public void handleRequest(ServletRequest req, ServletResponse res) { String jspFile = getFileFromRequest(req); // get the JSP target if (hasFileChangedOnDisk(jspFile)) { prepareForReload(); // invalidate the target and targetClassLoader setTargetClassLoader(null); setTarget(null); JSPServlet jsp = compileJSP(jspFile); ClassLoader loader = getLoaderForServlet(jsp); setTarget(jsp.getClassName()); setTargetClassLoader(loader); } super.handleRequest(req, res); } ... }
Specified by:
Specified by:
Throws:
java.lang.Exception

prepareForReload

  1. public void prepareForReload()
Gracefully invalidates the target by overseeing its lifecycle (destroy()) This method must be called before the target is invalidated for reload.
Specified by:

getServletName

  1. public java.lang.String getServletName( )
Returns the servlet name of the target
Specified by:
Returns:

getServletConfig

  1. public IServletConfig getServletConfig( )
Returns the ServletConfig associated with the target
Specified by:
Returns:

getServletContext

  1. public ServletContext getServletContext( )
Description copied from interface: IServletWrapper
Returns the servlet context associated with this servlet wrapper.
Specified by:
Returns:

setTargetClassLoader

  1. public void setTargetClassLoader( java.lang.ClassLoader loader)
Instructs the underlying implementation to use the supplied class loader to instantiate the target instance. Calling this method with a null, accompanied with a setTarget(null) will result in the current classloader being destroyed and garbage collected along with the target instance.
Specified by:

getTarget

  1. public Servlet getTarget()
Returns the target Servlet instance
Specified by:
getTarget in interface IServletWrapper
Returns:

getTargetClassLoader

  1. public java.lang.ClassLoader getTargetClassLoader( )
Returns the current classloader which loaded (or will, in the future, load) the target.
Specified by:

setTarget

  1. public void setTarget(Servlet target)
Sets the target for this IServletWrapper.
Specified by:
setTarget in interface IServletWrapper

addServletReferenceListener

  1. public void addServletReferenceListener( ServletReferenceListener listener)
Add a listener which will listen to the invalidation events for this wrapper instance. The invalidate() event will be fired only when the wrapper itself (not the target) is about to be destroyed by the parent container.
Specified by:

getLastAccessTime

  1. public long getLastAccessTime()
This method will be called by the webcontainer's reaper mechanism which polls for the access times of the wrappers in its datastructures, and invalidates them if they have been inactive for a preconfigured amount of time. Wrapper subclasses that do not want to be 'reaped' may override this method by returning the current system time.
Specified by:
Returns:

destroy

  1. public void destroy()
This method will be invoked when the parent container wishes to destroy this IServletWrapper instance. Thew subclasses may override this method to implement any resource clean up, but must invoke this method by calling super.destroy() inorder to correctly destroy the underlying target.
Specified by:
destroy in interface IServletWrapper

service

  1. public void service(ServletRequest request,
  2. ServletResponse response)
  3. throws java.io.IOException
  4. ServletException
Specified by:
service in interface IServletWrapper
Throws:
java.io.IOException
ServletException

setParent

  1. public void setParent(IServletContext parent)
Description copied from interface: IServletWrapper
Sets the parent context for this servletwrapper
Specified by:
setParent in interface IServletWrapper

isAvailable

  1. public boolean isAvailable()
Returns whether the requested wrapper resource exists.
Specified by:

nameSpacePostInvoke

  1. public void nameSpacePostInvoke( )

nameSpacePreInvoke

  1. public void nameSpacePreInvoke( )

getName

  1. public java.lang.String getName( )
Specified by:
getName in interface RequestProcessor

isInternal

  1. public boolean isInternal()
Specified by:
Returns:
boolean Returns true if this request processor is for internal use only

loadOnStartupCheck

  1. public void loadOnStartupCheck( )
  2. throws java.lang.Exception
Description copied from interface: IServletWrapper
Initializes this wrapper with the specified config. Depending on the startup weight specified in the config, the underlying target Servlet will either be initialized within this call. NOTE: This initialization behaviour of the target Servlet can be controlled by calling the setStartUpWeight() method on the IServletConfig
Specified by:
Throws:
java.lang.Exception
See Also:

load

  1. public void load()
  2. throws java.lang.Exception
Description copied from interface: IServletWrapper
Loads the servlet and calls the Servlet's init method with the previously passed IServletConfig. One component that calls this is SIP.
Specified by:
load in interface IServletWrapper
Throws:
java.lang.Exception

modifyTarget

  1. public void modifyTarget(Servlet s)
Specified by: