View Javadoc

1   package test.crispy.example.interceptor;
2   
3   import net.sf.crispy.InterceptorContext;
4   import net.sf.crispy.InvocationException;
5   import net.sf.crispy.Modifier;
6   
7   public class RemoveSecurityTokenModifier implements Modifier {
8   
9   	/**
10  	 * Get the security token from args index 0. Than remove index 0 and set args index to the
11  	 * original position. 
12  	 */
13  	public InterceptorContext modifyBeforeInvocation(InterceptorContext pvInterceptorContext) {
14  		if (pvInterceptorContext.getMethod().getParameterTypes().length != pvInterceptorContext.getArgs().length) {
15  			int lvLengthArgs = pvInterceptorContext.getArgs().length;
16  			Object lvArgs[] = new Object[lvLengthArgs - 1];
17  			String lvToken = (String) pvInterceptorContext.getArgs()[0];
18  			if ( ! (lvToken.equals(AddSecurityTokenModifier.SERCURITY_TEST_TOKEN)) ) {
19  				throw new InvocationException("Not valid Token: " + lvToken + " (expected: " + AddSecurityTokenModifier.SERCURITY_TEST_TOKEN + ")");
20  			}
21  			for (int i=1;i<lvLengthArgs; i++) {
22  				lvArgs[i-1] = pvInterceptorContext.getArgs()[i];
23  			}
24  			pvInterceptorContext.setArgs(lvArgs);
25  		}
26  		return pvInterceptorContext;
27  	}
28  
29  	public InterceptorContext modifyAfterInvocation(InterceptorContext pvInterceptorContext) {
30  		return pvInterceptorContext;
31  	}
32  
33  }