You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2011/08/12 14:35:11 UTC
svn commit: r1157074 -
/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Author: struberg
Date: Fri Aug 12 12:35:10 2011
New Revision: 1157074
URL: http://svn.apache.org/viewvc?rev=1157074&view=rev
Log:
OWB-601 allow initialisation of a 'dummy' SessionScope.
This is needed to allow batch processing and similar situations
Modified:
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Modified: openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java?rev=1157074&r1=1157073&r2=1157074&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java (original)
+++ openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java Fri Aug 12 12:35:10 2011
@@ -400,24 +400,31 @@ public class WebContextsService extends
*/
private void initSessionContext(HttpSession session)
{
+ SessionContext currentSessionContext;
+
if (session == null)
{
- // no session -> no SessionContext
- return;
+ // no session -> create a dummy SessionContext
+ // this is handy if you create asynchronous tasks or
+ // batches which use a 'admin' user.
+ currentSessionContext = new SessionContext();
}
+ else
+ {
+ String sessionId = session.getId();
- String sessionId = session.getId();
- //Current context
- SessionContext currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
+ //Current context
+ currentSessionContext = sessionCtxManager.getSessionContextWithSessionId(sessionId);
- //No current context
- if (currentSessionContext == null)
- {
- currentSessionContext = new SessionContext();
- sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
+ //No current context
+ if (currentSessionContext == null)
+ {
+ currentSessionContext = new SessionContext();
+ sessionCtxManager.addNewSessionContext(sessionId, currentSessionContext);
+ }
+ //Activate
+ currentSessionContext.setActive(true);
}
- //Activate
- currentSessionContext.setActive(true);
//Set thread local
sessionContext.set(currentSessionContext);