Wednesday, June 16, 2010

Struts 1.3 Observations.
Below are some of differences I noticed in struts behaviors while converting one of my project at work from struts 1.2.8 to struts 1.3.
In Struts 1.2.x Tiles processing required configuring the framework to use the TilesRequestProcessor implementation when you override RequestProcessor.
In Struts application if we need any custom RequestProcessor, we have to create an extension of the Struts RequestProcessor:

public class ExtendedRequestProcessor extends RequestProcessor {

public ExtendedRequestProcessor() {

}

public boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) {

...

return true;
}
}
Easy enough-I added a controller entry to my struts-config.xml file:


and restarted my container. As I am watching the console output fly by, I saw the following:
javax.servlet.ServletException: TilesPlugin : Specified RequestProcessor not compatible with TilesRequestProcessor
at org.apache.struts.tiles.TilesPlugin.initRequestProcessorClass(TilesPlugin.java:360)
at org.apache.struts.tiles.TilesPlugin.init(TilesPlugin.java:164)
at org.apache.struts.action.ActionServlet.initModulePlugIns(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:473)
at javax.servlet.GenericServlet.init(GenericServlet.java:258)

Because I use Tiles, I am forced to extend their RequestProcessor.
public class ExtendedRequestProcessor extends TilesRequestProcessor {

public ExtendedRequestProcessor () {

}

public boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) {
...

return true;
}

}

But in Struts 1.3 this will not work in the same way. In the Struts 1.3 Chain based request processor using Tiles simply involves configuring it to use an additional Tiles Command, and deploying the tiles sub-project jar(Struts-tiles.jar). The following Command is in the org.apache.struts.tiles.commands package.
Here we need to extend ComposableRequestProcessor and include the following content in the web.xml telling the framework to use Tiles Preprocessor.

chainConfig
org/apache/struts/tiles/chain-config.xml

Since version 1.3, the default Request Processor (ComposableRequestProcessor) is composed using Commons Chain, which is an implementation of the Chain of Responsibility pattern (CoR). It is designed as a drop-in replacement of the Struts 1.2.x behaviour and brings greater flexibility and easier customization to the request processing process. Each step of the processing is represented as a separate Command in the Chain. By inserting, substituting, or removing Commands, you can customize the framework to work your way. Let's take a look at thedefault commands for the ComposableRequestProcessor Chain in turn. These Command classes are in either theorg.apache.struts.chain.commands or org.apache.struts.chain.commands.servlet packages.

No comments:

Post a Comment