Menu

DispatchAction caused errors

JD
2002-11-07
2002-11-08
  • JD

    JD - 2002-11-07

    I have a test that uses DispatchAction in a sub-app and it's causing errors, but another plain action in the same sub-app works fine.  What's wrong here?

    Here's my test code:
    -----------------------------
        public void testUpdate()
        {
            setConfigFile("subapp","/WEB-INF/subapp-config.xml");
            setRequestPathInfo("/subapp", "/select.do");
            actionPerform();
            verifyNoActionErrors();     // any validation error?
            verifyForward("update");   // are we going to the right place?
            assertEquals("update", getSession().getAttribute("lastAction"));
        }
    -------------------------

    Here's my action mapping:
    -------------------------
            <action path="/select"
                    type="mike.web.SelectAction"
                    input="/list.jsp"
                    parameter="task">
                <forward name="select" path="/select.jsp"/>
                <forward name="update" path="/update.jsp"/>
                <forward name="delete" path="/delete.jsp"/>
            </action>
    -------------------------

    Here's the error message:
    ------------------------
    ..0    [main] ERROR org.apache.struts.actions.DispatchAction  - Request[/select] does not contain handler parameter named task
    0    [main] ERROR org.apache.struts.actions.DispatchAction  - Dispatch[/select] to method unspecified returned an exception
    java.lang.reflect.InvocationTargetException:
    junit.framework.AssertionFailedError: received error 400 : Request[/select] does not contain handler parameter named task
        at servletunit.HttpServletResponseSimulator.sendError(HttpServletResponseSimulator.java:445)
        at org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:243)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
        at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
        at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:249)
        at mike.web.TestSubappLoginAction.testUpdate(TestSubappLoginAction.java:28)
        at java.lang.reflect.Method.invoke(Native Method)
        at junit.framework.TestCase.runTest(TestCase.java:154)
        at junit.framework.TestCase.runBare(TestCase.java:127)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:118)
        at junit.framework.TestSuite.runTest(TestSuite.java:208)
        at junit.framework.TestSuite.run(TestSuite.java:203)
        at junit.textui.TestRunner.doRun(TestRunner.java:116)
        at junit.textui.TestRunner.doRun(TestRunner.java:109)
        at junit.textui.TestRunner.run(TestRunner.java:72)
        at junit.textui.TestRunner.run(TestRunner.java:57)
        at mike.web.TestSubappLoginAction.main(TestSubappLoginAction.java:35)
    F
    Time: 0.86
    There was 1 failure:
    1) testUpdate(mike.web.TestSubappLoginAction)junit.framework.AssertionFailedError: received error 500 : Dispatch[/select] to method unspecified returned an exception
        at servletunit.HttpServletResponseSimulator.sendError(HttpServletResponseSimulator.java:445)
        at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:308)
        at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:220)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:446)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:266)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1292)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)
        at servletunit.struts.MockStrutsTestCase.actionPerform(MockStrutsTestCase.java:249)
        at mike.web.TestSubappLoginAction.testUpdate(TestSubappLoginAction.java:28)
        at mike.web.TestSubappLoginAction.main(TestSubappLoginAction.java:35)
    ------------------------

    Any idea what's wrong?

    jd

     
    • Deryl Seale

      Deryl Seale - 2002-11-08

      You need to explicitly pass in the request parameter that selects the appropriate method in your DispatchAction.  So, in order for your test to work, you need to add the following line (or something like it):

      addRequestParameter("task","action.name.here");

      If you don't, then the DispatchAction can't tell where to send the request, resulting in the error you see.

      hope this helps.
      -d.

       

Log in to post a comment.