70. What is the request processor in struts and how it works

The RequestProcessor Class is the actual place where the request processing takes place in a Struts controller environment.

When the request object first reaches the actionservlet class then it invokes the process method of the underlying RequestProcessor Class.

This process method then looks into the struts-config.xml file and tries to locate the name of the action that has come with the request.Once it identifies the action in the xml file it continues the rest of the steps needed for request processing.

processor has most of the following responsibilities:

  1. Determine path,
  2. Handle Locale,
  3. Process content and encoding type,
  4. Process cache headers
  5. Pre Processing hook
  6. Pre-processing hook,
  7. Determine mapping,
  8. Determine roles,
  9. Process and validate actionForm,
  10. Return a response

It is one instance per application module; it invokes proper Action instance

Of course processes all requests for a module.

27 Responses

  1. testing

  2. I think one must also explain how the actions under the action- mapping tags in the struts-config.xml file are loaded into the memory. its like a dom structure, every action tag available as an object from where the processor can know about PATH, INPUT, NAME, VALIDATE=true/false, the respective FORM, and FORWARD attribute if given any. the Util and the config classes help loading the xml file, and Actionmapping is the class from where all this info is available internally in a key value pair.

  3. Hi Arvind,
    I think you are right, can you please give a brief more information about how the request flows from struts-config..mean some more about when struts-config come in picture then how the object of action take place, how server uses this obejct…etc

    Thankx

  4. I am fullly satishfied….

  5. Hi Arvind, Plz clarity ur point. it seems vague

  6. […] 70. What is the request processor in struts and how it works […]

  7. nice job do it

  8. Hi friends,

    can we extend requestProcessor class , so we can define our own processing steps..?
    if yes, then pls send me the sample code for that..

    thanks & regards
    charan

  9. hi friends,
    it was very useful.
    also if u know how to integrate struts with spring,please let me know.
    also send me the sample code.

    byee.
    dhinesh

  10. nice link to learn about request processor…….
    http://www.onjava.com/pub/a/onjava/2004/11/10/ExtendingStruts.html

    njoi….

  11. import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.*;
    import org.apache.struts.action.RequestProcessor;

    /**
    *
    * @author Manoj Paul
    */
    public class CustomRequestProcessor
    extends RequestProcessor
    {
    protected boolean processPreprocess (HttpServletRequest request,HttpServletResponse response)
    {
    HttpSession session = request.getSession(false);
    String requestURL=null;

    if( request.getServletPath().equals(“/Home”)
    || request.getServletPath().equals(“/login”) || request.getServletPath().equals(“/terms”)
    || request.getServletPath().equals(“/report_abuse”) || request.getServletPath().equals(“/report”)
    || request.getServletPath().equals(“/sendReportAbuse”) || request.getServletPath().equals(“/faq”)
    || request.getServletPath().equals(“/contact”) || request.getServletPath().equals(“/actionActivate”)
    || request.getServletPath().equals(“/prepareSimple”) || request.getServletPath().equals(“/editprofile”)
    || request.getServletPath().equals(“/edituser”) || request.getServletPath().equals(“/processSimple”)
    || request.getServletPath().equals(“/checkLogin”) || request.getServletPath().equals(“/forgotPassword”)
    || request.getServletPath().equals(“/generateUrl”) || request.getServletPath().equals(“/copyUrl”)
    || request.getServletPath().equals(“/logout”) || request.getServletPath().equals(“/customPick”)
    || request.getServletPath().equals(“/abuseword”) || request.getServletPath().equals(“/CheckWordAbuse”)
    || request.getServletPath().equals(“/cancel”) || request.getServletPath().equals(“/regist_home”)
    || request.getServletPath().equals(“/processUrl”) || request.getServletPath().equals(“/service”)
    || request.getServletPath().equals(“/recoverPassword”))
    {

    return true;
    }
    else
    {
    requestURL=request.getRequestURL().toString();
    RedirectUrlFormat object=new RedirectUrlFormat();
    object.process(requestURL,request,response);
    }
    return false;
    }
    }

  12. It is very usefull for me.

  13. sir , I want to know what is the exactly use of request processor. ActionServlet is there but why request processor is come in struts 1.1,1.2…

  14. Hi Ravi,

    ActionServlet was previously used to cater all requests and handle the business logic around it aswell, like interaction with ServiceLocators, BusinessDeligates, etc. But as and when J2EE patterns grooms, developers decide to make their code more transparent and managable.

    ActionServlet is a FrontController, it should only cater requests and thts wht ActionServlet is doing in version1.1. RequestProcessor has become the ApplicationContoller in the struts framework. which means it will cater the individual request, locate the service (by ModuleConfig) and delegate it to different BusinessObjects(wht u know as Action classes). FrontController should not have business logic involved at al.
    Ravi, I hope it gives you a better understanding now. But in current version of struts, they have replaced RequestProcessor with RequestDispatcher.

    Hi Manoj,
    You have mentioned one way of creating your own RequestProcessor, but to locate services you should look at ModuleConfig in detail. It will give u a better clean picture. ModuleConfig uses Digesters to create java representation of struts-config.xml. Here in Struts framework ModuleConfig is an implementation of wht you know as ServiceLocator.

    I hope with this you can write much cleaner code.

    Cheerio 😉
    Anjan

  15. The Action servlet is the main controller object. It gets control as soon as a user requests “myAction.do”. The Request Processor is a helper class instantiated and used by Action Servlet to process each request that comes in. The Request Processor actually does most of the work involved when a request comes in and a response goes out

  16. org.apache.struts.action.RequestProcessor processException
    WARNING: Unhandled Exception thrown: class

    iam getting this error.. when at the same time 2 people save the application the data is getting saved it came came bback to action but from action to jsp this error is comin…

  17. You guys really given a good face of struts working flow.

    thanks to all.

  18. thaks to all

  19. And in the struts-xml what i have to put???

  20. awsome xplanations… thanks 2 all.. 🙂

  21. can we override requestprocessor?

  22. Reblogged this on Srikanth's Blog.

  23. An interesting discussion is definitely worth comment.
    There’s no doubt that that you need to publish more about this topic, it might not be a taboo matter but generally people don’t talk about these subjects.
    To the next! Many thanks!!

  24. friends
    i am not able to get how request processor identify the different request?
    mean suppose 4 user log in same time from different terminal then how processor understand that request is coming from particular terminal.
    i think it may be using request object or anything else.

  25. It’s a pity you don’t have a donate button!

    I’d most certainly donate to this outstanding blog! I suppose for now i’ll settle for book-marking
    and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk about this site with my Facebook group.
    Talk soon!

  26. Nice……….. to clear the concept of struts working
    ……………..

Leave a comment