com.ibm.wsspi.webcontainer.servlet
Class GenericServletWrapper
- java.lang.Object
com.ibm.wsspi.webcontainer.servlet.GenericServletWrapper
All implemented interfaces:
- public abstract class GenericServletWrapper
- extends java.lang.Object
- implements IServletWrapper
Since:
WAS6.0
Constructor Summary
Constructor and Description |
---|
GenericServletWrapper(IServletContext parent)
Public constructor.
|
Method Summary
Modifier and Type | Method and Description |
---|---|
|
addServletReferenceListener(ServletReferenceListener listener)
Add a listener which will listen to the invalidation events for this
wrapper instance.
|
|
destroy()
This method will be invoked when the parent container wishes to destroy
this IServletWrapper instance.
|
|
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.
|
|
getName()
|
getServletConfig()
Returns the ServletConfig associated with the target
|
|
|
getServletContext()
|
|
getServletName()
Returns the servlet name of the target
|
|
getTarget()
Returns the target Servlet instance
|
|
getTargetClassLoader()
Returns the current classloader which loaded (or will, in the future, load)
the target.
|
|
handleRequest(ServletRequest req,ServletResponse res)
Method that processes the request, and ultimately invokes the service() on the
Servlet target.
|
|
initialize(IServletConfig config)
Method that handles the initialization of this IServletWrapper instance.
|
|
isAvailable()
Returns whether the requested wrapper resource exists.
|
|
isInternal()
|
|
load()
|
|
loadOnStartupCheck()
|
|
modifyTarget(Servlet s)
|
|
nameSpacePostInvoke()
|
|
nameSpacePreInvoke()
|
|
prepareForReload()
Gracefully invalidates the target by overseeing its lifecycle (destroy())
This method must be called before the target is invalidated for reload.
|
|
service(ServletRequest request,ServletResponse response)
|
|
setParent(IServletContext parent)
|
|
setTarget(Servlet target)
Sets the target for this IServletWrapper.
|
|
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
- public GenericServletWrapper(IServletContext parent)
- 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
- public void initialize(IServletConfig config)
- 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:
initialize
in interface IServletWrapper
Parameters:
config
- the IServletConfig associated with this IServletWrapper Throws:
java.lang.Exception
See Also:
handleRequest
- public void handleRequest(ServletRequest req,
- ServletResponse res)
- 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:
handleRequest
in interface RequestProcessor
Specified by:
handleRequest
in interface IServletWrapper
Throws:
java.lang.Exception
prepareForReload
- 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:
prepareForReload
in interface IServletWrapper
getServletName
- public java.lang.String getServletName( )
Returns the servlet name of the target
Specified by:
getServletName
in interface IServletWrapper
Returns:
getServletConfig
- public IServletConfig getServletConfig( )
Returns the ServletConfig associated with the target
Specified by:
getServletConfig
in interface IServletWrapper
Returns:
getServletContext
- public ServletContext getServletContext( )
Description copied from interface:
IServletWrapper
Returns the servlet context associated with this servlet wrapper.
Specified by:
getServletContext
in interface IServletWrapper
Returns:
setTargetClassLoader
- 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:
setTargetClassLoader
in interface IServletWrapper
getTarget
- public Servlet getTarget()
Returns the target Servlet instance
Specified by:
getTarget
in interface IServletWrapper
Returns:
getTargetClassLoader
- public java.lang.ClassLoader getTargetClassLoader( )
Returns the current classloader which loaded (or will, in the future, load)
the target.
Specified by:
getTargetClassLoader
in interface IServletWrapper
setTarget
- public void setTarget(Servlet target)
Sets the target for this IServletWrapper.
Specified by:
setTarget
in interface IServletWrapper
addServletReferenceListener
- 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:
addServletReferenceListener
in interface IServletWrapper
getLastAccessTime
- 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:
getLastAccessTime
in interface IServletWrapper
Returns:
destroy
- 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
- public void service(ServletRequest request,
- ServletResponse response)
- throws java.io.IOException
- ServletException
Specified by:
service
in interface IServletWrapper
Throws:
java.io.IOException
ServletException
setParent
- public void setParent(IServletContext parent)
Description copied from interface:
IServletWrapper
Sets the parent context for this servletwrapper
Specified by:
setParent
in interface IServletWrapper
isAvailable
- public boolean isAvailable()
Returns whether the requested wrapper resource exists.
Specified by:
isAvailable
in interface IServletWrapper
nameSpacePostInvoke
- public void nameSpacePostInvoke( )
nameSpacePreInvoke
- public void nameSpacePreInvoke( )
getName
- public java.lang.String getName( )
Specified by:
getName
in interface RequestProcessor
isInternal
- public boolean isInternal()
Specified by:
isInternal
in interface RequestProcessor
Returns:
boolean Returns true if this request processor is for internal use only
loadOnStartupCheck
- public void loadOnStartupCheck( )
- 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:
loadOnStartupCheck
in interface IServletWrapper
load
- public void load()
- 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
- public void modifyTarget(Servlet s)
Specified by:
modifyTarget
in interface IServletWrapper