You can also modify a pipeline by inserting servlets that subclass atg.servlet.pipeline.InsertableServletImpl
. InsertableServletImpl
is an implementation of InsertableServlet
that inserts itself into an existing servlet pipeline at startup. This capability is required because it is difficult to use Nucleus configuration files to splice into a pipeline whose configuration cannot be determined when the configuration files are written.
A servlet that implements InsertableServlet
explicitly adds itself to a pipeline when the service starts, and uses the insertAfterServlet
property to determine its location. Such a servlet might be the first servlet in its own secondary servlet pipeline; in that case, it has a nextServlet
property. If so, it inserts itself into the primary pipeline after the insertAfterServlet
servlet by changing that servlet’s nextServlet
property to the InsertableServlet
servlet. Then, the InsertableServlet
servlet changes the nextServlet
property of the last servlet in the secondary pipeline to point to the next servlet in the primary pipeline.
To add an InsertableServlet
to the servlet pipeline:
Write your servlet, extending
InsertableServletImpl
.Define it as a component in the Nucleus hierarchy. It does not really matter where you put your servlet in the component hierarchy (though the location affects references to other components if you use relative pathnames).
Set the
insertAfterServlet
property of your servlet to point to the path of the pipeline servlet you want your servlet to follow. For example, if you want your servlet to follow theDynamoServlet
in the pipeline, use:insertAfterServlet=/atg/dynamo/servlet/pipeline/DynamoServlet
Add the path to your servlet to the
initialServices
property of/atg/dynamo/servlet/Initial
:initialServices+=/myServlet
Note: Subclasses of InsertableServletImpl
that need to add their own logic to doStartService
should be sure to call super.doStartService()
at some point.
When your servlet finishes processing, it passes the request and response objects to the next servlet in the pipeline. InsertableServletImpl
defines a method called passRequest
, which automatically passes the request and response objects to the next servlet in the pipeline.
The following is an example of a pipeline servlet that prints the request URI before passing the request on to the next servlet in the pipeline:
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import atg.servlet.*; import atg.servlet.pipeline.*; public class URIPrinter extends InsertableServletImpl { public URIPrinter () {} public void service (DynamoHttpServletRequest request, DynamoHttpServletResponse response) throws IOException, ServletException { System.out.println ("Handling request for " + request.getRequestURI ()); passRequest (request, response); } }