Lines 76-176
Link Here
|
76 |
return; |
76 |
return; |
77 |
} |
77 |
} |
78 |
|
78 |
|
79 |
// Bind the context CL to the current thread |
79 |
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); |
80 |
Thread.currentThread().setContextClassLoader |
|
|
81 |
(context.getLoader().getClassLoader()); |
82 |
|
80 |
|
83 |
// Update the session last access time for our session (if any) |
81 |
try { |
84 |
String sessionId = request.getRequestedSessionId(); |
82 |
// Bind the context CL to the current thread |
85 |
Manager manager = context.getManager(); |
83 |
Thread.currentThread().setContextClassLoader |
86 |
if (sessionId != null && manager != null) { |
84 |
(context.getLoader().getClassLoader()); |
87 |
if (manager instanceof StoreManager) { |
85 |
|
88 |
Store store = ((StoreManager) manager).getStore(); |
86 |
// Update the session last access time for our session (if any) |
89 |
if (store != null) { |
87 |
String sessionId = request.getRequestedSessionId(); |
90 |
Session session = null; |
88 |
Manager manager = context.getManager(); |
91 |
try { |
89 |
if (sessionId != null && manager != null) { |
92 |
session = store.load(sessionId); |
90 |
if (manager instanceof StoreManager) { |
93 |
} catch (Exception e) { |
91 |
Store store = ((StoreManager) manager).getStore(); |
94 |
container.getLogger().error("deserializeError"); |
92 |
if (store != null) { |
95 |
} |
93 |
Session session = null; |
96 |
if (session != null) { |
94 |
try { |
97 |
if (!session.isValid() || |
95 |
session = store.load(sessionId); |
98 |
isSessionStale(session, System.currentTimeMillis())) { |
96 |
} catch (Exception e) { |
99 |
if (container.getLogger().isDebugEnabled()) { |
97 |
container.getLogger().error("deserializeError"); |
100 |
container.getLogger().debug("session swapped in is invalid or expired"); |
98 |
} |
|
|
99 |
if (session != null) { |
100 |
if (!session.isValid() || |
101 |
isSessionStale(session, System.currentTimeMillis())) { |
102 |
if (container.getLogger().isDebugEnabled()) { |
103 |
container.getLogger().debug("session swapped in is invalid or expired"); |
104 |
} |
105 |
session.expire(); |
106 |
store.remove(sessionId); |
107 |
} else { |
108 |
session.setManager(manager); |
109 |
// session.setId(sessionId); Only if new ??? |
110 |
manager.add(session); |
111 |
// ((StandardSession)session).activate(); |
112 |
session.access(); |
113 |
session.endAccess(); |
101 |
} |
114 |
} |
102 |
session.expire(); |
|
|
103 |
store.remove(sessionId); |
104 |
} else { |
105 |
session.setManager(manager); |
106 |
// session.setId(sessionId); Only if new ??? |
107 |
manager.add(session); |
108 |
// ((StandardSession)session).activate(); |
109 |
session.access(); |
110 |
session.endAccess(); |
111 |
} |
115 |
} |
112 |
} |
116 |
} |
113 |
} |
117 |
} |
114 |
} |
118 |
} |
115 |
} |
119 |
if (container.getLogger().isDebugEnabled()) { |
116 |
if (container.getLogger().isDebugEnabled()) { |
120 |
container.getLogger().debug("sessionId: " + sessionId); |
117 |
container.getLogger().debug("sessionId: " + sessionId); |
121 |
} |
118 |
} |
|
|
119 |
|
122 |
|
120 |
// Ask the next valve to process the request. |
123 |
// Ask the next valve to process the request. |
121 |
getNext().invoke(request, response); |
124 |
getNext().invoke(request, response); |
122 |
|
125 |
|
123 |
// If still processing async, don't try to store the session |
126 |
// If still processing async, don't try to store the session |
124 |
// TODO: Are there some async states where it would be safe to store |
127 |
// TODO: Are there some async states where it would be safe to store |
125 |
// the session? |
128 |
// the session? |
126 |
if (!request.isAsync()) { |
129 |
if (!request.isAsync()) { |
127 |
// Read the sessionid after the response. |
130 |
// Read the sessionid after the response. |
128 |
// HttpSession hsess = hreq.getSession(false); |
131 |
// HttpSession hsess = hreq.getSession(false); |
129 |
Session hsess; |
132 |
Session hsess; |
130 |
try { |
133 |
try { |
131 |
hsess = request.getSessionInternal(false); |
134 |
hsess = request.getSessionInternal(false); |
132 |
} catch (Exception ex) { |
135 |
} catch (Exception ex) { |
133 |
hsess = null; |
136 |
hsess = null; |
134 |
} |
137 |
} |
135 |
String newsessionId = null; |
138 |
String newsessionId = null; |
136 |
if (hsess!=null) { |
139 |
if (hsess!=null) { |
137 |
newsessionId = hsess.getIdInternal(); |
140 |
newsessionId = hsess.getIdInternal(); |
138 |
} |
141 |
} |
139 |
|
142 |
|
140 |
if (container.getLogger().isDebugEnabled()) { |
143 |
if (container.getLogger().isDebugEnabled()) { |
141 |
container.getLogger().debug("newsessionId: " + newsessionId); |
144 |
container.getLogger().debug("newsessionId: " + newsessionId); |
142 |
} |
145 |
} |
143 |
if (newsessionId!=null) { |
146 |
if (newsessionId!=null) { |
144 |
/* store the session and remove it from the manager */ |
147 |
/* store the session and remove it from the manager */ |
145 |
if (manager instanceof StoreManager) { |
148 |
if (manager instanceof StoreManager) { |
146 |
Session session = manager.findSession(newsessionId); |
149 |
Session session = manager.findSession(newsessionId); |
147 |
Store store = ((StoreManager) manager).getStore(); |
150 |
Store store = ((StoreManager) manager).getStore(); |
148 |
if (store != null && session!=null && |
151 |
if (store != null && session!=null && |
149 |
session.isValid() && |
152 |
session.isValid() && |
150 |
!isSessionStale(session, System.currentTimeMillis())) { |
153 |
!isSessionStale(session, System.currentTimeMillis())) { |
151 |
// ((StandardSession)session).passivate(); |
154 |
// ((StandardSession)session).passivate(); |
152 |
store.save(session); |
155 |
store.save(session); |
153 |
((StoreManager) manager).removeSuper(session); |
156 |
((StoreManager) manager).removeSuper(session); |
154 |
session.recycle(); |
157 |
session.recycle(); |
|
|
158 |
} else { |
159 |
if (container.getLogger().isDebugEnabled()) { |
160 |
container.getLogger().debug("newsessionId store: " + |
161 |
store + " session: " + session + |
162 |
" valid: " + |
163 |
(session == null ? "N/A" : Boolean.toString( |
164 |
session.isValid())) + |
165 |
" stale: " + isSessionStale(session, |
166 |
System.currentTimeMillis())); |
167 |
} |
168 |
|
169 |
} |
155 |
} else { |
170 |
} else { |
156 |
if (container.getLogger().isDebugEnabled()) { |
171 |
if (container.getLogger().isDebugEnabled()) { |
157 |
container.getLogger().debug("newsessionId store: " + |
172 |
container.getLogger().debug("newsessionId Manager: " + |
158 |
store + " session: " + session + |
173 |
manager); |
159 |
" valid: " + |
|
|
160 |
(session == null ? "N/A" : Boolean.toString( |
161 |
session.isValid())) + |
162 |
" stale: " + isSessionStale(session, |
163 |
System.currentTimeMillis())); |
164 |
} |
174 |
} |
165 |
|
|
|
166 |
} |
167 |
} else { |
168 |
if (container.getLogger().isDebugEnabled()) { |
169 |
container.getLogger().debug("newsessionId Manager: " + |
170 |
manager); |
171 |
} |
175 |
} |
172 |
} |
176 |
} |
173 |
} |
177 |
} |
|
|
178 |
} finally { |
179 |
Thread.currentThread().setContextClassLoader(oldClassLoader); |
174 |
} |
180 |
} |
175 |
} |
181 |
} |
176 |
|
182 |
|