01: /*
02: * Created on 28-Feb-2006
03: */
04: package uk.org.ponder.rsf.servlet;
05:
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpSession;
08:
09: import uk.org.ponder.rsf.state.TokenStateHolder;
10:
11: /** A TokenStateHolder that stores flow state in the HTTP Session.
12: *
13: * <p>This is, unexpectedly, an application scope bean. The HttpSession object
14: * stored inside is an AOP alliance proxy for the actual request-scope session.
15: * It is app-scope since alternative TSH implementations are also app-scope,
16: * and cross-scope overriding is not supported. Also having one less request bean
17: * is desirable.
18: * <p>NB Expiryseconds not yet implemented. Would require *extra* server-side
19: * storage of map of tokens to sessions, in order to save long-term storage
20: * within sessions - awaiting research from performance clients.
21: * @author Antranig Basman (antranig@caret.cam.ac.uk)
22: *
23: */
24: public class InSessionTSH implements TokenStateHolder {
25: // NB - this is a proxy of the request
26: private HttpServletRequest request;
27: private int expiryseconds;
28:
29: public void setHttpRequest(HttpServletRequest request) {
30: this .request = request;
31: }
32:
33: public Object getTokenState(String tokenID) {
34: HttpSession session = request.getSession(false);
35: return session == null ? null : session.getAttribute(tokenID);
36: }
37:
38: public void putTokenState(String tokenID, Object trs) {
39: HttpSession session = request.getSession(true);
40: session.setAttribute(tokenID, trs);
41: }
42:
43: public void clearTokenState(String tokenID) {
44: try {
45: HttpSession session = request.getSession(false);
46: session.removeAttribute(tokenID);
47: } catch (Exception e) {
48: // We really don't care if the "session has been invalidated".
49: }
50: }
51:
52: public void setExpirySeconds(int seconds) {
53: this .expiryseconds = seconds;
54: }
55:
56: public String getId() {
57: HttpSession session = request.getSession(false);
58: return session == null ? null : session.getId();
59: }
60:
61: }
|