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

Redirect Action calls wrong method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 2.3.4, 2.3.4.1
    • 2.3.7
    • Plugin - Spring
    • Mac OS X Lion 10.7.4
      java version "1.6.0_35"
      Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
      Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

    • Important

    Description

      I call an action and expect to be redirected to another action BUT instead I get java.lang.NoSuchMethodException. In my example Spring is in charge of constructing my Action object and I have a naive object that returns a random String. It turns out that this random string is being somehow mistaken by the action name, so I get something like java.lang.NoSuchMethodException: test.action.Test.TSldxhPcLq().

      I've made a simple project that is very simple to test.

      In the following example you can call "redirect" action and see the bug. I have a small zip with this test project but I'm not finding any upload button.

      Here is my config

      struts.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE struts PUBLIC
       "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
       "http://struts.apache.org/dtds/struts-2.1.7.dtd">
      
      <struts>
      	<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
      	<constant name="struts.devMode" value="false" />
      	<!-- Prevents struts from appending .action ... use a comma for empty suffix --> 
      	<constant name="struts.action.extension" value="," />
      
      	<package name="general" extends="struts-default">
      
      		<action name="test" method="test"
      			class="test.action.Test">
      			<result name="success">/jsp/test.jsp</result>
      		</action>
      		
      		<action name="redirect" method="redirect"
      			class="test.action.Redirect">
      			<result type="redirectAction">test</result>
      		</action>
      		
      	</package>
      </struts>
      

      ApplicationContext.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!-- Developer -->
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:security="http://www.springframework.org/schema/security"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
      	xmlns:tx="http://www.springframework.org/schema/tx"  xmlns:task="http://www.springframework.org/schema/task"
      	xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
      
      	<bean id="testRandomKey" class="test.utils.RandomString" factory-method="createRandomString" lazy-init="false">
      		<constructor-arg>
      	 		<value type="java.lang.Integer">10</value>
      	 	</constructor-arg>
      	</bean>
      </beans>
      

      Test.java

      public class Test {
      	
      	public String test(){
      		return ActionSupport.SUCCESS;
      	}
      
      }
      

      Redirect.java

      public class Redirect {
      	
      	public String redirect(){
      		return ActionSupport.SUCCESS;
      	}
      
      }
      

      RandomString.java

      public class RandomString {
      
      	public RandomString() {
      	}
      
      	public static char createChar(int temp) {
      
      		return (char) temp;
      	}
      
      	public static int createInt(char temp) {
      
      		return (int) temp;
      	}
      
      	public static void createAsciiTable() {
      		for (int z = 0; z < 256; z++) {
      			char[] test3;
      			test3 = new char[1];
      			test3[0] = RandomString.createChar(z);
      			String test2 = new String(test3);
      			byte[] t3;
      			t3 = test2.getBytes();
      			int a2 = t3[0];
      			int a3 = (a2 & 0x7F) + (a2 < 0 ? 128 : 0);
      			System.out.println("mitChar: " + RandomString.createChar(z) + " "
      					+ RandomString.createInt(RandomString.createChar(z))
      					+ " mitString: " + test2 + " " + a3);
      		}
      
      	}
      
      	public static char createRandomChar() {
      
      		int temp = new Random().nextInt(256); // limitation of Ascii Char 33 to
      		// 255
      
      		if ((temp < 48) || (temp > 47 && temp < 65) || (temp > 90 && temp < 97)
      				|| (temp > 122))
      
      		{
      			temp = createRandomChar();
      			return (char) temp;
      		}
      
      		else {
      			// System.out.println(temp);
      			return (char) temp;
      
      		}
      
      	}
      
      	public static String createRandomString(int length) {
      		StringBuffer sb = new StringBuffer();
      		for (int j = 0; j < length; j++) {
      			sb.append(createRandomChar());
      		}
      		return sb.toString();
      	}
      
      }
      

      Attachments

        1. test-struts2.zip
          16 kB
          Javier Lecuona

        Activity

          People

            lukaszlenart Lukasz Lenart
            javiercbk Javier Lecuona
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: