The atg.servlet.pipeline
package provides interfaces for creating request handling pipeline servlets. All pipeline servlet classes directly or indirectly implement interface atg.servlet.pipeline.PipelineableServlet
. This interface provides a nextServlet
property that points to the next component in the pipeline. The Oracle Commerce Platform installation provides the implementation class atg.servlet.pipeline.PipelineableServletImpl
, which you can subclass to create your own servlets. PipelineableServletImpl
implements all Servlet
methods, so you only need to override the service
method.
To insert into a request handling pipeline a servlet that subclasses PipelineableServletImpl
:
Extend
atg.servlet.pipeline.PipelineableServletImpl
.Define the servlet as a globally scoped Nucleus component.
Reset the previous servlet’s
nextServlet
property to point to the new servlet.Set the new servlet’s
nextServlet
property to point to the next servlet in the pipeline.Add the servlet’s path to the
initialServices
property of/atg/dynamo/servlet/Initial
.
The PipelineableServlet
interface has two sub-interfaces that provide more flexibility for inserting new servlets into the pipeline:
atg.servlet.pipeline.
InsertableServletatg.servlet.pipeline.
DispatcherPipelineableServlet
InsertableServlet
The InsertableServlet
interface lets a servlet insert itself into the pipeline when the service starts, without requiring changes to servlets already in the pipeline, through the insertAfterServlet
property, which points back to the preceding servlet. The inserted servlet reads the preceding servlet’s nextServlet
property and points to it as the next servlet to execute after itself.
For example, a servlet pipeline might contain Servlet1, whose nextServlet
property points to Servlet2. You can insert MyNewServlet, which implements InsertableServlet
, between the two by setting its insertAfterServlet
property so it points to Servlet1. This configuration splices ServletNew between Servlet1 and Servlet2 as follows:
MyNewServlet sets its own
nextServlet
property to the value of Servlet1’snextServlet
property.MyNewServlet reads Servlet1’s
nextServlet
property and links to Servlet2 as the next servlet to execute after itself.
If an insertable servlet inserts only itself into a pipeline, it uses the nextServlet
property of its insertAfterServlet
servlet to resume pipeline execution. However, if the inserted servlet starts a secondary pipeline, it sets its own nextServlet
property to the next servlet in that pipeline. After the last secondary pipeline servlet executes, it passes control to the nextServlet
servlet originally specified by the insertAfterServlet
servlet, and the original pipeline resumes execution.
The Oracle Commerce Platform installation provides an implementation of the InsertableServlet
interface, atg.servlet.pipeline.InsertableServletImpl
. This class implements all Servlet
methods, so you only need to override the service
method.
To add an InsertableServlet
to the servlet pipeline:
Write your servlet by extending
atg.servlet.pipeline.InsertableServletImpl
.Define the servlet as a globally scoped Nucleus component.
Set the
insertAfterServlet
property of your servlet to point to the path of the pipeline servlet you want your servlet to follow. For example, you can insert a servlet afterDynamoServlet
as follows:insertAfterServlet=/atg/dynamo/servlet/dafpipeline/DynamoServlet
Add the servlet’s path to the
initialServices
property of/atg/dynamo/servlet/Initial
:initialServices+=/myServlet
When the inserted servlet finishes processing, it calls the method passRequest()
(defined in InsertableServletImpl
), which automatically passes the request and response objects to the next servlet in the pipeline.
Sample Servlet Code
The following pipeline servlet class URIPrinter
extends atg.servlet.pipeline.InsertableServletImpl
. It 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); } }
Note: Subclasses of InsertableServletImpl
that add their own logic to doStartService
must call super.doStartService()
.
DispatcherPipelineableServlet
The DispatcherPipelineableServlet
interface provides a mechanism for conditionally branching the pipeline. This interface includes a dispatcherServiceMap
property that is a Map of possible servlets to invoke next, depending on some condition. For example, the MimeTypeDispatcher
servlet determines which servlet to invoke depending on the MIME type of the request. The Oracle Commerce Platform provides the implementation class DispatcherPipelineableServletImpl
.