Re: Extending TokenInterceptor

smartr <[email protected]> Fri, 29 Dec 2006 10:01:30 CST
Newsgroups gmane.comp.java.open-symphony.webwork
Message-ID <14863970.1167408205619.JavaMail.os-j2ee@opensymphony01.managed.contegix.com>
Here's more on the code with the weird behavior... 
PrivateToken.java[code]
package foo;

import com.opensymphony.webwork.interceptor.TokenInterceptor;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.ValidationAware;

public class PrivateToken extends TokenInterceptor {
    /**
     * Determines what to do if an invalida token is provided. If the action implements {@link ValidationAware}
     *
     * @param invocation the action invocation where the invalid token failed
     * @return the return code to indicate should be processed
     * @throws Exception when any unexpected error occurs.
     */
    protected String handleInvalidToken(ActionInvocation invocation) throws Exception {
        // invoke the action to handle parameters.
    	invocation.invoke();

        return INVALID_TOKEN_CODE;
    }
}[/code]
xwork.xml[code]
<!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.1.1//EN" "http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
...
		<interceptors>
			<interceptor name="tcToken" class="foo.PrivateToken" />
			<interceptor-stack name="myStack">
				<interceptor-ref name="servlet-config" />
				<interceptor-ref name="defaultStack" />
			</interceptor-stack>
			...
		</interceptors>
...
		<action name="TimeClock" class="foo.TimeClockAction" method="clockView">
			<interceptor-ref name="myStack" />
			<result name="success">punchclock.jsp</result>
		</action>
		<action name="TimeClockView" class="foo.TimeClockAction" method="view">
			<interceptor-ref name="tcToken" />
			<interceptor-ref name="myStack" />
			<result name="success">punchclock_view.jsp</result>
			<result name="invalid.token" type="redirect-action">
				<param name="actionName">TimeClock</param>
				<param name="myParam">${myParam}</param>
			</result>
		</action>
...
[/code]
punchclock.jsp
[code]
<%@ taglib uri="/webwork" prefix="ww"%>
...
<form name='myForm' id='myForm' method=post action='TimeClockView.action?myParam=<ww:property value="myParam"/>'  ...>
		<ww:token />
...
</form>
...
[/code]
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=55812&messageID=111045#111045