cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r170325 - /cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java
Date Mon, 16 May 2005 07:27:37 GMT
Author: rgoers
Date: Mon May 16 00:27:35 2005
New Revision: 170325

URL: http://svn.apache.org/viewcvs?rev=170325&view=rev
Log:
Return a single HttpSession per session.

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java?rev=170325&r1=170324&r2=170325&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/environment/http/HttpRequest.java Mon May 16 00:27:35
2005
@@ -24,6 +24,8 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Vector;
+import java.util.WeakHashMap;
+import java.lang.ref.WeakReference;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.http.HttpServletRequest;
@@ -57,8 +59,10 @@
     /** The default form encoding of the servlet container */
     private String container_encoding;
 
-    /** The current session */
-    private HttpSession session;
+    /**
+     * The map to assure 1:1-mapping of server sessions and Cocoon session wrappers
+     */
+    private static final Map sessions = new WeakHashMap();
 
     private final Map attributes = new HashMap();
 
@@ -232,21 +236,27 @@
      */
     public Session getSession(boolean create) {
         javax.servlet.http.HttpSession serverSession = this.req.getSession(create);
-        if ( null != serverSession) {
-            if ( null != this.session ) {
-                if ( this.session.wrappedSession != serverSession ) {
-                    // update wrapper
-                    this.session.wrappedSession = serverSession;
+        HttpSession session;
+        if (serverSession != null)
+        {
+            synchronized (sessions)
+            {
+                // retrieve existing wrapper
+                WeakReference ref = (WeakReference) sessions.get(serverSession);
+                if (ref == null || (session = (HttpSession) ref.get()) == null)
+                {
+                    // create new wrapper
+                    session = new HttpSession(serverSession);
+                    sessions.put(serverSession, new WeakReference(session));
                 }
-            } else {
-                // new wrapper
-                this.session = new HttpSession( serverSession );
             }
-        } else {
+        }
+        else
+        {
             // invalidate
-            this.session = null;
+            session = null;
         }
-        return this.session;
+        return session;
     }
 
     public Session getSession() {



Mime
View raw message