Class GenericServletWrapper
java.lang.Object
com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper
- All Implemented Interfaces:
- RequestProcessor,- 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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd a listener which will listen to the invalidation events for this wrapper instance.voiddestroy()This method will be invoked when the parent container wishes to destroy this IServletWrapper instance.longThis 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.getName()Returns the ServletConfig associated with the targetjavax.servlet.ServletContextReturns the servlet context associated with this servlet wrapper.Returns the servlet name of the targetjavax.servlet.ServletReturns the target Servlet instanceReturns the current classloader which loaded (or will, in the future, load) the target.voidhandleRequest(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) Method that processes the request, and ultimately invokes the service() on the Servlet target.voidinitialize(IServletConfig config) Method that handles the initialization of this IServletWrapper instance.booleanReturns whether the requested wrapper resource exists.booleanvoidload()Loads the servlet and calls the Servlet's init method with the previously passed IServletConfig.voidInitializes this wrapper with the specified config.voidmodifyTarget(javax.servlet.Servlet s) voidvoidvoidGracefully invalidates the target by overseeing its lifecycle (destroy()) This method must be called before the target is invalidated for reload.voidservice(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) voidsetParent(IServletContext parent) Sets the parent context for this servletwrappervoidsetTarget(javax.servlet.Servlet target) Sets the target for this IServletWrapper.voidsetTargetClassLoader(ClassLoader loader) Instructs the underlying implementation to use the supplied class loader to instantiate the target instance.
- 
Constructor Details- 
GenericServletWrapperPublic 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:
- Exception
 
 
- 
- 
Method Details- 
initializeMethod 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:
- initializein interface- IServletWrapper
- Parameters:
- config- the IServletConfig associated with this IServletWrapper
- Throws:
- Exception
- See Also:
 
- 
handleRequestpublic void handleRequest(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res) throws 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:
- handleRequestin interface- IServletWrapper
- Specified by:
- handleRequestin interface- RequestProcessor
- Throws:
- Exception
 
- 
prepareForReloadpublic 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:
- prepareForReloadin interface- IServletWrapper
 
- 
getServletNameReturns the servlet name of the target- Specified by:
- getServletNamein interface- IServletWrapper
- Returns:
 
- 
getServletConfigReturns the ServletConfig associated with the target- Specified by:
- getServletConfigin interface- IServletWrapper
- Returns:
 
- 
getServletContextpublic javax.servlet.ServletContext getServletContext()Description copied from interface:IServletWrapperReturns the servlet context associated with this servlet wrapper.- Specified by:
- getServletContextin interface- IServletWrapper
- Returns:
 
- 
setTargetClassLoaderInstructs 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:
- setTargetClassLoaderin interface- IServletWrapper
 
- 
getTargetpublic javax.servlet.Servlet getTarget()Returns the target Servlet instance- Specified by:
- getTargetin interface- IServletWrapper
- Returns:
 
- 
getTargetClassLoaderReturns the current classloader which loaded (or will, in the future, load) the target.- Specified by:
- getTargetClassLoaderin interface- IServletWrapper
 
- 
setTargetpublic void setTarget(javax.servlet.Servlet target) Sets the target for this IServletWrapper.- Specified by:
- setTargetin interface- IServletWrapper
 
- 
addServletReferenceListenerAdd 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:
- addServletReferenceListenerin interface- IServletWrapper
 
- 
getLastAccessTimepublic 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:
- getLastAccessTimein interface- IServletWrapper
- Returns:
 
- 
destroypublic 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:
- destroyin interface- IServletWrapper
 
- 
servicepublic void service(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws IOException, javax.servlet.ServletException - Specified by:
- servicein interface- IServletWrapper
- Throws:
- IOException
- javax.servlet.ServletException
 
- 
setParentDescription copied from interface:IServletWrapperSets the parent context for this servletwrapper- Specified by:
- setParentin interface- IServletWrapper
 
- 
isAvailablepublic boolean isAvailable()Returns whether the requested wrapper resource exists.- Specified by:
- isAvailablein interface- IServletWrapper
 
- 
nameSpacePostInvokepublic void nameSpacePostInvoke()
- 
nameSpacePreInvokepublic void nameSpacePreInvoke()
- 
getName- Specified by:
- getNamein interface- RequestProcessor
 
- 
isInternalpublic boolean isInternal()- Specified by:
- isInternalin interface- RequestProcessor
- Returns:
- boolean Returns true if this request processor is for internal use only
 
- 
loadOnStartupCheckDescription copied from interface:IServletWrapperInitializes 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:
- loadOnStartupCheckin interface- IServletWrapper
- Throws:
- Exception
- See Also:
 
- 
loadDescription copied from interface:IServletWrapperLoads the servlet and calls the Servlet's init method with the previously passed IServletConfig. One component that calls this is SIP.- Specified by:
- loadin interface- IServletWrapper
- Throws:
- Exception
 
- 
modifyTargetpublic void modifyTarget(javax.servlet.Servlet s) - Specified by:
- modifyTargetin interface- IServletWrapper
 
 
-