Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4589

Struts2 REST plugin do not overwrite method name

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3.28, 2.5
    • Component/s: Plugin - REST
    • Labels:
      None
    • Environment:

      tomcat

      Description

      When creating a ActionMapper for a rest url with a method name, an incorrect mapping is created. I haven't been able to determine a fix for this with the new code, but it works in my code provided for WW-4545. A unit test shows the issue:

          public void testMappingWithMethodAndId() throws Exception {
              req.setRequestURI("/myapp/animals/dog/fido/test/some-id!create;jsessionid=29fefpv23do1g");
              req.setServletPath("/animals/dog/fido/test/some-id");
              req.setMethod("GET");
              mapper.setAllowDynamicMethodCalls("true");
              ActionMapping mapping = mapper.getMapping(req, configManager);
      
              assertEquals("/animals", mapping.getNamespace());
              assertEquals("dog/fido/test", mapping.getName());
              assertEquals("some-id", ((String[]) mapping.getParams().get("id"))[0]);
              assertEquals("create", mapping.getMethod());
          }
      

      here is the unit test result:

      junit.framework.ComparisonFailure: null 
      Expected :dog/fido/test
      Actual   :dog/fido
       <Click to see difference>
      
      
      	at junit.framework.Assert.assertEquals(Assert.java:81)
      	at junit.framework.Assert.assertEquals(Assert.java:87)
      	at org.apache.struts2.rest.RestActionMapperTest.testMappingWithMethodAndId(RestActionMapperTest.java:203)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:497)
      	at junit.framework.TestCase.runTest(TestCase.java:168)
      	at junit.framework.TestCase.runBare(TestCase.java:134)
      	at junit.framework.TestResult$1.protect(TestResult.java:110)
      	at junit.framework.TestResult.runProtected(TestResult.java:128)
      	at junit.framework.TestResult.run(TestResult.java:113)
      	at junit.framework.TestCase.run(TestCase.java:124)
      	at junit.framework.TestSuite.runTest(TestSuite.java:243)
      	at junit.framework.TestSuite.run(TestSuite.java:238)
      	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
      
      

      Another test that fails in a different way:

          public void testMappingForStaticFiles() throws Exception {
              req.setRequestURI("/myApp/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image!iframe");
              req.setServletPath("/custom/menu/Yosemite/Vernal_Fall/Vernal_Fall_Image");
              req.setMethod("GET");
              mapper.setAllowDynamicMethodCalls("true");
              ActionMapping mapping = mapper.getMapping(req, configManager);
      
              assertEquals("", mapping.getNamespace());
              assertEquals("custom/menu/Yosemite/Vernal_Fall", mapping.getName());
              assertEquals("Vernal_Fall_Image", ((String[]) mapping.getParams().get("id"))[0]);
              assertEquals("iframe", mapping.getMethod());
          }
      

      Unit test results:

      junit.framework.ComparisonFailure: null 
      Expected :custom/menu/Yosemite/Vernal_Fall
      Actual   :custom/menu/Yosemite
       <Click to see difference>
      
      
      	at junit.framework.Assert.assertEquals(Assert.java:81)
      	at junit.framework.Assert.assertEquals(Assert.java:87)
      	at org.apache.struts2.rest.RestActionMapperTest.testMappingForStaticFiles(RestActionMapperTest.java:216)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:497)
      	at junit.framework.TestCase.runTest(TestCase.java:168)
      	at junit.framework.TestCase.runBare(TestCase.java:134)
      	at junit.framework.TestResult$1.protect(TestResult.java:110)
      	at junit.framework.TestResult.runProtected(TestResult.java:128)
      	at junit.framework.TestResult.run(TestResult.java:113)
      	at junit.framework.TestCase.run(TestCase.java:124)
      	at junit.framework.TestSuite.runTest(TestSuite.java:243)
      	at junit.framework.TestSuite.run(TestSuite.java:238)
      	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
      	at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
      	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
      	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              rpii Rich Peters
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: