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 ATG 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:

The PipelineableServlet interface has two sub-interfaces that provide more flexibility for inserting new servlets into the pipeline:

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:

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 ATG 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:

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. ATG provides the implementation class DispatcherPipelineableServletImpl.


Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices