ART#115 - How to Add OR Insert a new Servlet in DAF Servlet Pipeline?





Previous article describes the basics of servlet pipeline. Now is the time to customize it.
The concept behind the customization of servlet pipeline is, inserting a new servlet somewhere between the chain of servlets in the pipeline.

The "PipelineableServlet" interface

Every servlet which is to be inserted in Servlet Pipeline should implement PipelineableServlet interface (or its child interfaces or its child classes). 
ATG also provides a PipelineableServletImpl class which implements the PipelineableServlet, which can be extended to create a new servlet for the pipeline. The PipelineableServletImpl implements all the methods in PipelineableServlet. Therefore, you just have to override the service() method.
The PipelineableServlet has a "nextServlet" property, which is used to point to the next servlet.

Consider an example, wherein there are two servlets, viz. ServletA and ServletB in the pipeline, and you have to insert ServletMid in between, you can follow the below steps to do this. Assuming "ServletA" and "ServletB" are already in servlet pipeline. See below diagram from details:-




a. Create a class ServletMid which extends PipelineableServletImpl.
b. Override the service() method and write your custom code in the ServletMid class.



c. Create a new properties file in your ATG's config path.
  • Next, set the $class property with the fully qualified package name of ServletMid class you created.
  • set the $scope to global


d. Now that the component of your ServletMid has been created, we have to insert this servlet in between ServletA and ServletB.



e. Override the component of ServletA and set the "nextServlet" property to your custom component defined above. Now, ServletA's next servlet becomes ServletMid.





f. Now, set the "nextServlet" property of ServletMid's component to config path of ServletB. Now ServletMid's next servlet becomes ServletB.





g. Finally, add this servlet's config path to Initial.properties. For more details on Intial.properties, read ART#105 - Nucleus and ATG.

Your customized pipeline now looks like:-

Let us explore other ways of customizing the DAF Servlet pipeline in next articles.

Back



Next




3 comments:

  1. There is mistake in point a) class should extends PipelineServletImpl

    ReplyDelete
  2. Monis thankyou for this article. I just have a question.

    What would be the difference in following the above process by extending PipelinableServletImpl and by extending InsertableServletImpl adding property insertAfterServlet=servletA.

    ReplyDelete

Subscribe

Get All The Latest Updates Delivered Straight Into Your Inbox For Free!

Flickr