facebook

Extending org.apache.struts.action.RequestProcessor [Closed]

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #227656 Reply

    ivansaraiva
    Member

    Hi All,

    I’m extending the org.apache.struts.action.RequestProcessor as the rules in the Programming Jakarta Strus 2nd Edition book. I’m receiving the follow error page all times I configure the <controller> tag in the strus-config.xml.
    What I’m doing wrong?
    Even, if I just include the controller tag int the struts-config file with the CustomRequestProcessor extension class hasn’t any overwritten method I’d got the same behavior, Why?
    If I comment the <controller> tag in the struts-config file, all things go fine!

    Thanks in advance,
    Ivan.

    ****************
    error page
    ****************
    HTTP Status 404 – Servlet action is not available
    type Status report

    message Servlet action is not available

    description The requested resource (Servlet action is not available) is not available.

    ****************
    struts-config.xml
    ****************
    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE struts-config PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 1.2//EN” “http://struts.apache.org/dtds/struts-config_1_2.dtd”&gt;
    <struts-config>
    <data-sources />
    <form-beans >
    <form-bean
    name=”loginForm”
    type=”com.dedalus.struts.form.LoginForm” />
    <form-bean name=”indexForm” type=”com.dedalus.struts.form.IndexForm” />
    </form-beans>

    <global-exceptions />
    <global-forwards >
    </global-forwards>

    <action-mappings >
    <action
    attribute=”loginForm”
    input=”login.jsp”
    name=”loginForm”
    path=”/login”
    scope=”request”
    type=”com.dedalus.struts.action.LoginAction”>
    <forward name=”erro” path=”/login.jsp” />
    <forward name=”sucesso” path=”/main.jsp” />
    </action>

    <action
    input=”index.jsp”
    name=”indexForm”
    path=”/loginInput”
    scope=”request”
    parameter=”/login.jsp”
    type=”org.apache.struts.actions.ForwardAction” />

    <action
    input=”tabs.jsp”
    path=”/logout”
    scope=”request”
    parameter=”/logout.jsp”
    type=”org.apache.struts.actions.ForwardAction”
    validate=”false” />

    </action-mappings>

    <controller
    contentType=”text/html:charset=UTF-8″
    locale=”true”
    nocache=”true”
    processorClass=”com.dedalus.strus.CustomRequestProcessor”/>

    <message-resources parameter=”com.dedalus.struts.ApplicationResources” />
    </struts-config>

    ****************
    CustomRequestProcessor
    ****************
    /*
    * Created on Apr 2, 2005
    *
    * TODO To change the template for this generated file go to
    * Window – Preferences – Java – Code Style – Code Templates
    */
    package com.dedalus.struts;

    import javax.servlet.http.*;
    import javax.servlet.RequestDispatcher;
    import java.util.Locale;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.RequestProcessor;
    import org.apache.struts.config.ForwardConfig;
    import org.apache.struts.Globals;

    import com.dedalus.utils.IConstants;

    /**
    * @author administrator
    *
    * TODO To change the template for this generated type comment go to
    * Window – Preferences – Java – Code Style – Code Templates
    */
    public class CustomResquestProcessor extends RequestProcessor {

    protected boolean processPreprocess (
    HttpServletRequest request,
    HttpServletResponse response) {
    HttpSession session = request.getSession(false);

    //If user is trying to access login page
    // then don’t check
    if( request.getServletPath().equals(“/loginInput.do”)
    || request.getServletPath().equals(“/login.do” ) )
    return true;

    //Check if userName attribute is there is session.
    //If so, it means user has allready logged in
    if( session != null &&
    session.getAttribute(IConstants.USER_CONTAINER) != null)
    return true;
    else{
    try{
    //If no redirect user to login Page
    request.getRequestDispatcher
    (“/login.jsp”).forward(request,response);
    }catch(Exception ex){
    }
    }
    return false;
    }

    }

    #227661 Reply

    Riyad Kalla
    Member

    What exactly is the validation error?

    #227678 Reply

    ivansaraiva
    Member

    I see in session scope if there is an objet indicating that the user is logged in. By extending RequestProcessor I can test all requests send to server in just one place. I put a breakpoint into the CustomRequestProcessor , in this line “if( request.getServletPath().equals(“/loginInput.do”)”, but, the executiion didn’t reach it. The error page is raised before.
    If the method processPreProcess return false the Struts doesn’t do any other thing and foward to login.jsp.

    Thanks,
    Ivan

    #227679 Reply

    ivansaraiva
    Member

    If I just extend the RequestProcessor class without overwriting any method the same error page appears to.

    #227681 Reply

    Riyad Kalla
    Member

    ivan,
    Your original post was about a validation error in your struts-config.xml file, NOW you are asking about a Struts processing exception, I am having a very hard time establishing what the problem even is here. Please clarify for me a) what the problem is and b) what you need help with. If this is a Struts question, you need to ask it on the Struts mailing list, not here. We are not Struts experts, even though we play them on TV.

    #227766 Reply

    ivansaraiva
    Member

    The question is the same all time!
    If I add the <controller> tag in the strus-config file, pointing out to my extension RequestProcessor class I’ve got the error page described in the first message. Even if I overwrite, or not, any method. That’s all!
    Is this the validation error that You talked about? I thought that it was about the processPreProcess method in my extension class.
    I guess that both of us are misunderstanding each other.

    Ivan.

    #227772 Reply

    Riyad Kalla
    Member

    Moving to OT > Soft Dev, this is not a MyEclipse issue, this is a Struts development issue. I have never implemented a custom RequestProcessor and do not know why you are encountering this behavior.

    #227820 Reply

    ivansaraiva
    Member

    RKalla,

    I ran my application under Tomcat 5.5 in standalone mode, just under Windows, everything is OK! But, when I tried to run under the same Tomcat version in debug mode, under MyEclipse perspective, I’ve got the the error page that was described above.
    Another thing with strus-config file, when I include the attribute “debug” in <controller> tag, the MyEclipse’s GUI shows me an error: “Attribute “”debug”” must to be declared for element type “”controller””.”
    This isn’t still being a MyEclipse matter?

    Ivan.

    #227830 Reply

    Riyad Kalla
    Member

    Ivan, that was my mistake. Moving back to J2EE.

    #227838 Reply

    support-michael
    Keymaster

    I have an example struts 1.1 project with the following “controller” configuration. I will try porting it to Struts 1.2.

    <controller>
    <!– <set-property property=”processorClass”
    value=”org.apache.struts.action.RequestProcessor”/>
    –>
    <set-property property=”processorClass” value=”com.yourcompany.struts.MyRequestProcessor”/>
    </controller>

    #227839 Reply

    support-michael
    Keymaster

    I ported my example to Struts 1.2 and it worked fine when the controller was explictly configured to use the org.apache.struts.action.RequestProcessor and then later my custom RequestProcessor.

    Try isolating the RequestProcessor problem by creating as simple WebProject. Add Struts 1.2 capabilities to the project. Then define only the controller element with the default Struts RequestProcess; don’t add any other elements to the file. Deploy the webProject, start Tomcat5 and see if the webserver can initialize it.

    <controller processorClass="org.apache.struts.action.RequestProcessor"/>

    If this works then try your custom RP. I have a simple RP subclass that logs every request and then delegates processing to the org.apache.struts.action.RequestProcessor superclass. Try doing something like this once the default RequestProcessor is deployed correctly.

    Get it working, Get it working right, Get it working fast. Then make it small and maintainable.

    Good luck!

    #228101 Reply

    ivansaraiva
    Member

    Hi Michael,

    Apologies, there were a sequence of mistakes in my code. Wrong package name, class name no match with configuration’s statement.
    Now, after I corrected my mistakes, everything works fine.
    By the way, in my controller tag when I put ‘debug=”3″‘ the GUI shows me an error message ‘Attribute “debug” must to be declared for element type “controller”‘. I’ve deployed the application and the app runs without matter. Is it ok?

    Best Regards,
    Ivan Saraiva

    #228105 Reply

    support-michael
    Keymaster

    Congrats on your progress! Thank you for taking the time to follow up on this thread. Debugging configuration details can be a real pain.

    Changing status of this thread to closed.

    Regards,

Viewing 13 posts - 1 through 13 (of 13 total)
Reply To: Extending org.apache.struts.action.RequestProcessor [Closed]

You must be logged in to post in the forum log in