openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1679794 - in /openwebbeans/trunk/webbeans-web/src: it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/ it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/ it/webcdiapp/src/main/webapp/ it/webcdiapp/src/test/java/org/apa...
Date Sat, 16 May 2015 17:50:10 GMT
Author: struberg
Date: Sat May 16 17:50:09 2015
New Revision: 1679794

URL: http://svn.apache.org/r1679794
Log:
OWB-1048 enable SessionContext on re-activate

This is important if the SessionContext gets first accessed
after the session got serialized over from another node or the file system.

Added:
    openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/TestServlet.java
    openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/RequestScopedBean.java
    openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/webapp/index.jsp
    openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/test/java/org/apache/openwebbeans/web/it/RequestScopedIT.java
    openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java

Modified: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/TestServlet.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/TestServlet.java?rev=1679794&r1=1679793&r2=1679794&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/TestServlet.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/TestServlet.java
Sat May 16 17:50:09 2015
@@ -44,6 +44,7 @@ public class TestServlet extends HttpSer
 
         if ("reset".equals(action))
         {
+            request.getSession().invalidate();
             RequestScopedBean.resetCounter();
             ContextEventCounter.resetCounter();
         }

Modified: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/RequestScopedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/RequestScopedBean.java?rev=1679794&r1=1679793&r2=1679794&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/RequestScopedBean.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/RequestScopedBean.java
Sat May 16 17:50:09 2015
@@ -19,6 +19,7 @@
 package org.apache.openwebbeans.web.it.beans;
 
 import javax.annotation.PostConstruct;
+import javax.enterprise.context.ContextNotActiveException;
 import javax.enterprise.context.Initialized;
 import javax.enterprise.context.RequestScoped;
 import javax.enterprise.event.Observes;
@@ -34,6 +35,7 @@ public class RequestScopedBean
     private static int requestContextCounter = 0;
 
     private @Inject NonAnnotatedDependentBean nonAnnotatedBean;
+    private @Inject SessionScopedCounter sessionScopedCounter;
 
     private String name = "Super name";
 
@@ -69,11 +71,19 @@ public class RequestScopedBean
     public void onRequestInit(@Observes @Initialized(RequestScoped.class) Object payload)
     {
         requestContextCounter++;
+        try
+        {
+            sessionScopedCounter.increment();
+        }
+        catch (ContextNotActiveException cnae)
+        {
+            // ignore if on app startup.
+        }
     }
 
     public static String info()
     {
-        return String.valueOf(requestInstanceCounter) + ',' + String.valueOf(requestContextCounter);
+        return String.valueOf(requestInstanceCounter) + "," + String.valueOf(requestContextCounter);
     }
 
     public int getMeaningOfLife()

Added: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java?rev=1679794&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java
(added)
+++ openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java
Sat May 16 17:50:09 2015
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openwebbeans.web.it.beans;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
+
+/**
+ */
+@SessionScoped
+@Named
+public class SessionScopedCounter implements Serializable
+{
+    private int count = 0;
+
+    public void increment()
+    {
+        count++;
+    }
+
+    public int getCount()
+    {
+        return count;
+    }
+}

Propchange: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/java/org/apache/openwebbeans/web/it/beans/SessionScopedCounter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/webapp/index.jsp
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/webapp/index.jsp?rev=1679794&r1=1679793&r2=1679794&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/webapp/index.jsp (original)
+++ openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/main/webapp/index.jsp Sat May 16
17:50:09 2015
@@ -35,5 +35,9 @@ Current instance: <c:out value="${reques
 <br/>
 Meaning of Life: <c:out value="${requestScopedBean.meaningOfLife}"/>
 
+<br/>
+SessionScoped Counter: <c:out value="${sessionScopedCounter.count}"/>
+
+
 </body>
 </html>

Modified: openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/test/java/org/apache/openwebbeans/web/it/RequestScopedIT.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/test/java/org/apache/openwebbeans/web/it/RequestScopedIT.java?rev=1679794&r1=1679793&r2=1679794&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/test/java/org/apache/openwebbeans/web/it/RequestScopedIT.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/it/webcdiapp/src/test/java/org/apache/openwebbeans/web/it/RequestScopedIT.java
Sat May 16 17:50:09 2015
@@ -46,7 +46,7 @@ public class RequestScopedIT extends Owb
 
         // application and session still running
         // for the session we got 2 full requests + 1 end after the reset + 1 start before
the info gets rendered in the last request
-        Assert.assertEquals("application:1/0\nsession:1/0\nrequest:3/3", response);
+        Assert.assertEquals("application:1/0\nsession:1/1\nrequest:3/3", response);
     }
 
 }

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=1679794&r1=1679793&r2=1679794&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
Sat May 16 17:50:09 2015
@@ -478,6 +478,7 @@ public class WebContextsService extends
                 // we do that in any case.
                 // This is needed to trigger delta-replication on most servers
                 session.setAttribute(OWB_SESSION_CONTEXT_ATTRIBUTE_NAME, currentSessionContext);
+                currentSessionContext.setActive(true);
             }
             //Set thread local
             sessionContexts.set(currentSessionContext);



Mime
View raw message