The RequestProcessor  of Struts framework is an implementation of Application Controller pattern that takes many infrastructure responsibilities mainly Action management and View Management. The RequestProcessor is a plain Java class. The object is created and initialized by the Action Servlet while the ActionServlet is being initialized as explained in the above section, this class implements importantly three public methods that allows the ActionServlet to initialize the module, delegate request to process, and destroy the module, the method signature of these methods is shown in the below given snippet.

Code Snippet

  1.       Public void init                   (org.apche.struts.action.ActionServlet,org.apache.struts.config.
ModuleConfig)throws javax.servlet.ServletException

  2.       Public void process          (javax.servlet.http.HttpServletRequest,javax.servlet.http
.HttpServletReesponse)throws java.io.IOException,
Javax.servlet.ServletException

  3.       Public void destroy()


As shown in the above code snippet init() method of the RequestProessor takes two arguments one is ActionServlet and the second is ModuleConfig. As described in the above section in the initialization process of ActionServlet, it creates a ModuleConfig object encapsulating the descriptions of the module configured in the respective struts configuration file. The ActionServlet creates an instance of RequestProcessor instance newly created injecting its instance reference(i.e ActionServlet) and ModuleConfilg, which initializes the RequestProcessor instance making it prepared to handle the client request for this module. In case of any problem in initialization, RequestProcessor throws a ServletException to the ActionServlet.


When ActionServlet receives the request after doing its job it delegates the request to RequestProcessor by invoking process() method of RequestProcessor i.e process() method of RequestProcessor is invoked for every time when client request for this module. The process method is responsible to handle the request where it needs to perform number of request processing tasks the RequestProcessor class is designed using Chain of Responsibility(COR) pattern to implement these tasks. The RequestProcesssor class implements separate methods to process each request- processing task the sequence of request processing of tasks that are executed is described in the following table.



Method Name
Description
processMultipart()
This method checks if the request is multipart request then the request object is wrapped into a special request wrapper object that facilitates to get the multipart content easily
processPath()
Resolve the request URI to locate the action to which this request has to be dispatched
processLocale()
Retrieves the client locale from the request and saves it into the session scope in case if it is not available in session and the <controller>
Element in this modules configuration file describes locale attribute value as true, which is by default true.
processContent()
Set the default content type with optional character encoding for the response.
processNoCache()
This method sets no-cache HTTP response header if necessary.
processPreprocess()
This method is given to allow the application provider to include some custom pre processing’s in handling the request, this method of RequestProcessor class does not performs any request processing task, it simply return true, s described this used when we subclass the RequestProcessor.
processCachedMessages()
Removes any ActionMessages object stored in the session under Globals.MESSAGE_KYE and Globals.ERROR_KEY keys if the messages isAccessed() method returns true. This allows messages to be stored in the session, display one time, and be released here.
ProcessMapping()
Select the mapping used to process the action path for this request.

processRoles()
This method performs a security check finding is there any role required to perform this action , if so then find whether the requested user has permission to access the action.
processActionForm()
This method process a ActionForm bean configured to the requested action if any, like this loctes the form bean in the given scope if not found creates a new form bean object
processPopulate()
This method populates the form bean properties with respective request parameter values.
processValidate()
This method makes a validation check on the form properties by invoking validate() method on form bean object if required, the validate(0 method invocation can be controlled using ‘validate’ attribute of <action> tag in struts configuration file
processException()
This method is invoked in case if the processValidate() method throws InvalidCancelException, which may be thrown because of the form beans error
processForward()
This method forwards the request to the path specified by the mapping using forward attribute of <action> element located using the path returned by processPath() method
ProcessInclude()
This method includes the request to the path specified by the mapping using include attribute of <action> element located using the path returned by processPath() method.
processActionCreate()
This method locates an Action instance to process this request if not found then creates a new instance
processActionPerform()
This method invokes execute() method on the Action instance created / located using processActionCreate(). This method returns ActionForward that is returned by the execute method or the ExceptionHandler
processForwardConfig()
This method process the ActionForward instance retuned by the process ActionPerform()

As shown in the architecture and described in the above sections the request after processed by the Request Processor will be delegated to Action instance so that the application provider can add application specific  code to execute in request handling. The next Post describes about the Action class.

Post a Comment

 
Top