KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > interceptor > TokenSessionStoreInterceptor


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.interceptor;
6
7 import com.opensymphony.webwork.ServletActionContext;
8 import com.opensymphony.webwork.util.InvocationSessionStore;
9 import com.opensymphony.webwork.util.TokenHelper;
10 import com.opensymphony.xwork.ActionInvocation;
11 import com.opensymphony.xwork.Result;
12 import com.opensymphony.xwork.util.OgnlValueStack;
13
14 import javax.servlet.http.HttpServletRequest JavaDoc;
15
16
17 /**
18  * @author Jason Carreira
19  */

20 public class TokenSessionStoreInterceptor extends TokenInterceptor {
21     //~ Methods ////////////////////////////////////////////////////////////////
22

23     /**
24      * @param invocation
25      * @return
26      * @throws Exception
27      */

28     protected String JavaDoc handleInvalidToken(ActionInvocation invocation) throws Exception JavaDoc {
29         HttpServletRequest JavaDoc request = ServletActionContext.getRequest();
30         String JavaDoc tokenName = TokenHelper.getTokenName(request);
31         String JavaDoc token = TokenHelper.getToken(tokenName, request);
32
33         if ((tokenName != null) && (token != null)) {
34             ActionInvocation savedInvocation = InvocationSessionStore.loadInvocation(tokenName, token);
35
36             if (savedInvocation != null) {
37                 // set the valuestack to the request scope
38
OgnlValueStack stack = savedInvocation.getStack();
39                 ServletActionContext.getRequest().setAttribute(ServletActionContext.WEBWORK_VALUESTACK_KEY, stack);
40
41                 Result result = savedInvocation.getResult();
42
43                 if ((result != null) && (savedInvocation.getProxy().getExecuteResult())) {
44                     result.execute(savedInvocation);
45                 }
46
47                 // turn off execution of this invocations result
48
invocation.getProxy().setExecuteResult(false);
49
50                 return savedInvocation.getResultCode();
51             }
52         }
53
54         return INVALID_TOKEN_CODE;
55     }
56
57     /**
58      * @param invocation
59      * @return
60      * @throws Exception
61      */

62     protected String JavaDoc handleValidToken(ActionInvocation invocation) throws Exception JavaDoc {
63         // we know the token name and token must be there
64
HttpServletRequest JavaDoc request = ServletActionContext.getRequest();
65         String JavaDoc key = TokenHelper.getTokenName(request);
66         String JavaDoc token = TokenHelper.getToken(key, request);
67         InvocationSessionStore.storeInvocation(key, token, invocation);
68
69         return invocation.invoke();
70     }
71 }
72
Popular Tags