struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hernán <heam...@gmail.com>
Subject Struts2 RedirectAction Situation
Date Wed, 11 Jul 2012 14:12:21 GMT
Some days ago I wrote about a problem I had with struts2. As nobody knew
the answer, I solved it but then I forgot to comment about it. So I'll do
it now.
I upgraded a Struts2, Spring, Hibernate Application to the latest version
of struts2 2.3.4, that's way I also upgraded it's corresponding Spring,
Spring security and Tiles dependencies. The web app had spring 2.5.6,
Spring security 2.0 and Tiles 2.0.6. Now it uses spring 3.0.7.RELEASE,
Spring Security 3.1 and Tiles 2.2.2.

The problem I had was with RedirectAction Result, in a nutshell: whenever
struts2 redirected an action, it added !Something#Something at the end of
the correct action I wanted to redirect. As you should know these are the
method and anchor parameters of RedirectAction result... The thing is that
this "Something" comes from Spring Security 3.1 (the same happened with
Spring Security 3.0 as I tried it)

    <beans:bean id="successLogoutUrl" class="java.lang.String">
        <beans:constructor-arg value="Something" />
    </beans:bean>

    <beans:bean id="logoutFilter"
class="org.springframework.security.web.authentication.logout.LogoutFilter">
        <beans:constructor-arg ref="successLogoutUrl" />
        <beans:constructor-arg>
            <beans:list>
                <beans:ref bean="rememberMeServices" />
                <beans:ref bean="securityContextLogoutHandler" />
            </beans:list>
        </beans:constructor-arg>
        <beans:property name="filterProcessesUrl"
value="/logout/j_spring_security_logout"/>
    </beans:bean>


For an unknown reason (at least for me). The Struts2 class
ServletActionRedirectResult used this constructor and...

    public ServletActionRedirectResult(String namespace, String actionName,
String method, String anchor) {
        super(null, anchor);
        this.namespace = namespace;
        this.actionName = actionName;
        this.method = method;
    }

the values passed in each parameter where the String "Something" then there
was no way to avoid method and anchor parameters of being added to the
redirected action, that's why I made a patch and solve the problem.
What I did is something childish but efficient, I passed "null" String
value to parameters anchor and method and in the code, if the parameters
were the String "null" I set the parameters to null. I know it's a little
bit weird but it worked for me... Maybe I am doing something wrong. Dunno.
Anyway bear it in mind, maybe I'm wrong, maybe it's a bug. I don't know.

Here goes my Patch Adams Code Snippets:

struts.xml

        <action name="ChangeLocaleTo*Action"
class="changeLocaleTo{1}Action" >
            <interceptor-ref name="i18nStack" />

            <result name="success" type="redirectAction">
                <param name="actionName">${redirectToAction}</param>
                <param name="namespace">${redirectToNamespace}</param>
                <param name="method">null</param>
                <param name="anchor">null</param>
            </result>
        </action>

org.apache.struts2.dispatcher.ServletActionRedirectResult.java

    public void execute(ActionInvocation invocation) throws Exception {
        actionName = conditionalParse(actionName, invocation);
        if (namespace == null) {
            namespace = invocation.getProxy().getNamespace();
        } else {
            namespace = conditionalParse(namespace, invocation);
        }
        if (method == null || method.equalsIgnoreCase("null")) {
            method = "";
        } else {
            method = conditionalParse(method, invocation);
        }

        String tmpLocation = actionMapper.getUriFromActionMapping(new
ActionMapping(actionName, namespace, method, null));

        setLocation(tmpLocation);

        super.execute(invocation);
    }

org.apache.struts2.dispatcher.ServletRedirectResult.java

    public void execute(ActionInvocation invocation) throws Exception {
        if (anchor != null && !anchor.equalsIgnoreCase("null") &&
!anchor.equalsIgnoreCase("")) {
            anchor = conditionalParse(anchor, invocation);
        }
        super.execute(invocation);
    }


Greetings, any comment will be appreciated.

-- 
Hernán

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message