VisualBuilder
  Home > Jsp > Tutorials > ComposableRequestProcessor in Struts 1.3 - Struts Tutorial
Tell a friend
Link to us
Total Members
      Members: 84661
     
Sitemap Forum Chat
Home
Struts Tutorial Home
1 . What is Struts?
2 . Why do we need Struts?
3 . Advantages of Struts
4 . Setting up Eclipse for Web Development
5 . Registration Case Study
6 . Setting up Struts project in Eclipse
7 . Creating an ODBC Data source
8 . Configuring Application Server
9 . Struts Configuration
10 . Writing the User class
11 . ResourceManager
12 . Writing the Struts Business Component
13 . Creating the Action Class
14 . Adding ActionForward
15 . Deploy the Struts Application
16 . Adding the Form bean
17 . Configuring Form Bean in struts-config.xml
18 . Using Struts Tag Libraries
19 . Listing all Users - Struts Iterator Looping
20 . Add User Action - New Struts Action Class
21 . Add User View
22 . Validating Struts Form Bean
23 . Review of the Struts Tutorial
24 . Introduction
25 . DispatchAction
26 . DispatchAction Example Continued...
27 . Introduction to DynaActionForm
28 . DynaActionForm Example Continued...
29 . Struts solution to Duplicate Form Submission (Token mechanism)
30 . Introduction to Validation framework
31 . Example Continued Validation Framework.
32 . Client Side Validation
33 . Introduction to Standard Validator-Rules.xml
34 . Creating custom Valdator rules
35 . Extending the Validator Rules with the inherited SubForm Classes.-2
36 . Internationalization in struts application
37 . Exception Handling in Struts
38 . Creating Custom Exception Handlers in Struts-1
39 . Creating Custom Exception Handlers in Struts.-2
40 . Creating Plugin for the Struts Application. -1
41 . Creating Plugin for the Struts Application. -2
42 . WildCard Character mapping for the Actions-1.
43 . WildCard Character mapping for the Actions-2.
44 . WildCard Character mapping for the Actions-3.
45 . Uploading the Files to Server Using Struts-1
46 . Uploading the Files to Server Using Struts-2
47 . Introduction to Modules in Struts Application
48 . Modules Example-1
49 . Modules Example-2
50 . Customizing the ActionServlet Class for the application-1.
51 . Customizing the ActionServlet Class for the application-2.
52 . Customizing the ActionServlet Class for the application-3.
53 . Customizing the ActionServlet Class for the application-3.
54 . Customizing RequestProcessor Class for the application-1.
55 . Customizing RequestProcessor Class for the application.-2
56 . ComposableRequestProcessor in Struts 1.3
57 . Adding New Command Objects in Struts CoR Pattern
58 . Security in Struts
59 . Example for the Application Managed Security-1
60 . Example for the Application Managed Security-2
 
 
JSP Home
JSP Members (18709)
JSP Member Articles ( 11 )
JSP Discussion (71)
JSP Q & A ( 87 )
- JSP Ask Question
- JSP Questions
- JSP Unanswered Questions
JSP Resources
JSP Source Code (172)
JSP Articles (34)
JSP Blogs (333)
JSP Jobs (0)
JSP Components (10)
JSP Books (9)
JSP Websites (13)
JSP News (12)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Jsp struts Tutorial
 ComposableRequestProcessor in Struts 1.3
  << Prev: Customizing RequestProcessor Class for the application.-2 Next: Adding New Command Objects in Struts CoR Pattern >>

Introduction :- A popular technique for organizing the execution of complex processing flows is the "Chain of Responsibility" pattern. In this pattern the different “commands” are combined into a single chain with a series of processing elements and the context parameter is passed along with all the parameter. All the commands contain a single execute method. A Boolean variable determines whether the command executes successfully or not. This pattern promotes the idea of loose coupling, a common programming practice.


From the version 1.3, the struts replaces the RequestProcessor with ComposableRequestProcessor class which follows the Chain of Responsibility pattern (CoR) design pattern. It is configured via the following context initialization parameters:



  • org.apache.struts.chain.CATALOG_NAME - Name of the Catalog in which we will look up the Command to be executed for each request. If not specified, the default value is struts.

  • org.apache.struts.chain.COMMAND_NAME - Name of the Command which we will execute for each request, to be looked up in the specified Catalog. If not specified, the default value is servlet-standard.


Each step of the processing is represented as a separate Command in the Chain. User can easily customize by changing, removing and replacing the chain commands. The Command classes are following packages:-


 


1. org.apache.struts.chain.commands.


2. org.apache.struts.chain.commands.servlet packages.


 


The following table will listed out all the command objects of CoR.




















































































CommandDescription

SelectLocale



Select a locale for this request, if one hasn't already been selected, and place it in the request.



SetOriginalURI



Store the URI of the original request in the request.



RequestNoCache



If appropriate, set the following response headers: "Pragma", "Cache-Control", and "Expires".



RemoveCachedMessages



Removes any ActionMessages object stored in the session under Globals.MESSAGE_KEY and Globals.ERROR_KEY if the messages' isAccessed method returns true. This allows messages to be stored in the session, displayed one time, and be released.



SetContentType



Set the default content type (with optional character encoding) for all responses if requested.



SelectAction



Determine the ActionMapping associated with this path.



AuthorizeAction



If the mapping has a role associated with it, ensure the requesting client has the specified role. If the client does not, raise an error and stop processing of the request.



CreateActionForm



Instantiate (if necessary) the ActionForm associated with this mapping (if any) and place it into the appropriate scope.



PopulateActionForm



Populate the ActionForm associated with this request, if any.



ValidateActionForm



Perform validation (if requested) on the ActionForm associated with this request (if any).



SelectInput



If validation failed, select the appropriate ForwardConfig for return to the input page.



ExecuteCommand



Lookup and execute a chain command if the current ActionConfig is so-configured.



SelectForward



If this mapping represents a forward, forward to the path specified by the mapping.



SelectInclude



Select the include uri (if any) for the current action mapping.



PerformInclude



If selected, include the result of invoking the path in this request.



CreateAction



Instantiate an instance of the class specified by the current ActionMapping (if necessary).



ExecuteAction



This is the point at which your Action's execute method will be called.



ExecuteForwardCommand



Lookup and execute a chain command if the current ForwardConfig is so-configured.



PerformForward



Finally, the process method of the RequestProcessor takes the ActionForward returned by your Action class, and uses it to select the next resource (if any). Most often the ActionForward leads to the presentation page that renders the response.



 


The default Chain-config file supplied by the apache is as follows:-


 


<?xml version="1.0" ?>
<!--
$Id: chain-config.xml 481833 2006-12-03 17:32:52Z niallp $


Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
This file contains definitions of the standard Chain Of Responsibility chains that emulate Struts 1.2 processing functionality. These chains are defined in a catalog named "struts" so that the application can use the default catalog for its own purposes, without any potential for name clashes.


$Id: chain-config.xml 481833 2006-12-03 17:32:52Z niallp $
-->


<catalog name="struts">


    <define name="lookup" className="org.apache.commons.chain.generic.LookupCommand"/>
<!-- ========== Servlet Complete Request Chain ========================= -->


<chain name="servlet-standard">


<!-- Establish exception handling filter -->
    <command className="org.apache.struts.chain.commands.ExceptionCatcher" catalogName="struts" exceptionCommand="servlet-exception"/>


    <lookup catalogName="struts" name="process-action" optional="false"/>


    <lookup catalogName="struts" name="process-view" optional="false"/>


</chain>


<!-- ========== Action Processing chain ======================== -->
<chain name="process-action">


<!--
This chain attempts to emulate (most of) the standard request processing in the standard org.apache.struts.action.RequestProcessor class, by performing the corresponding tasks in individual Commands
that are composable. The following list defines a cross reference between the processXxx methods and the Commands that perform the corresponding functionality:


processMultipart Integrated into servlet and legacy classes


processPath SelectAction (which also does processMapping)


processException ExceptionCatcher / ExceptionHandler


processLocale SelectLocale


processContent SetContentType


processNoCache RequestNoCache


processPreprocess LookupCommand with optional="true". Multiple occurrences of this can easily be added, to support additional processing hooks at any point in the chain without modifying the standard definition.


processCachedMessages RemoveCachedMessages


processMapping SelectAction (which also does processPath)


processRoles AuthorizeAction


processActionForm CreateActionForm


processPopulate PopulateActionForm


processValidate ValidateActionForm / SelectInput


processForward SelectForward


processInclude SelectInclude / PerformInclude


processActionCreate CreateAction


processActionPerform ExecuteAction
-->
    <!-- Look up optional preprocess command -->


    <lookup catalogName="struts" name="servlet-standard-preprocess" optional="true"/>


    <!-- Identify the Locale for this request -->
    <command className="org.apache.struts.chain.commands.servlet.SelectLocale"/>


    <!-- Set (if needed) the URI of the original request -->
    <command className="org.apache.struts.chain.commands.servlet.SetOriginalURI"/>


    <!-- Set (if needed) no cache HTTP response headers -->
    <command className="org.apache.struts.chain.commands.servlet.RequestNoCache"/>


    <!-- Set (if needed) the HTTP response content type -->
    <command className="org.apache.struts.chain.commands.servlet.SetContentType"/>


    <!-- Remove messages cached in the Session -->
    <command className="org.apache.struts.chain.commands.RemoveCachedMessages"/>


    <!-- Identify the ActionConfig for this request -->
    <command className="org.apache.struts.chain.commands.servlet.SelectAction"/>


    <!-- Authorize the selected ActionConfig for this request -->
    <command className="org.apache.struts.chain.commands.servlet.AuthorizeAction"/>


    <!-- Create (if needed) the ActionForm for this request -->
    <command className="org.apache.struts.chain.commands.CreateActionForm"/>


    <!-- Populate the ActionForm for this request -->
    <command className="org.apache.struts.chain.commands.servlet.PopulateActionForm"/>


    <!-- Validate the ActionForm for this request -->
    <command className="org.apache.struts.chain.commands.servlet.ValidateActionForm"/>


    <!-- Select the appropriate ForwardConfig for return to input page -->
    <command className="org.apache.struts.chain.commands.servlet.SelectInput"/>


    <!-- Lookup and execute a chain command if the current ActionConfig is so-configured. -->
    <command className="org.apache.struts.chain.commands.ExecuteCommand"/>


    <!-- Select the appropriate ForwardConfig for action mappings that only have an ActionForward -->
    <command className="org.apache.struts.chain.commands.servlet.SelectForward"/>


    <!-- Select the include uri (if any) for the current action mapping -->
    <command className="org.apache.struts.chain.commands.SelectInclude"/>


    <!-- Perform the include (if needed) -->
    <command className="org.apache.struts.chain.commands.servlet.PerformInclude"/>


    <!-- Create (if needed) the Action for this request -->
    <command className="org.apache.struts.chain.commands.servlet.CreateAction"/>


    <!-- Execute the Action for this request -->
    <command className="org.apache.struts.chain.commands.servlet.ExecuteAction"/>


 


</chain>


<!-- ========== View Processing chain ======================== -->
<chain name="process-view">


    <!-- Lookup and execute a chain command if the current ForwardConfig is so-configured. -->
    <command className="org.apache.struts.chain.commands.ExecuteForwardCommand"/>


    <!-- Follow the returned ForwardConfig (if any) -->
    <command className="org.apache.struts.chain.commands.servlet.PerformForward"
/>


</chain>


<!-- ========== Servlet Exception Handler Chain ======================== -->


<chain name="servlet-exception">


<!--
This chain is designed to be invoked (by o.a.s.c.ExceptionCatcher) if an unhandled exception is thrown by any subsequent command in a processing chain (including the one that invokes a Struts action). The standard definition of this chain supports the exception mapping of Struts 1.1, but can be replaced in order to handle exceptions differently.
-->


    <!-- Execute the configured exception handler (if any) -->
    <command className="org.apache.struts.chain.commands.servlet.ExceptionHandler"/>


    <!-- Follow the returned ForwardConfig (if any) -->
    <command className="org.apache.struts.chain.commands.servlet.PerformForward"/>


</chain>
</catalog>


  << Prev: Customizing RequestProcessor Class for the application.-2 Next: Adding New Command Objects in Struts CoR Pattern >>
Jsp Struts Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising