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 2015/05/06 21:42:45 UTC
svn commit: r1678078 - in /openwebbeans/trunk:
webbeans-impl/src/main/java/org/apache/webbeans/conversation/
webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/
webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/
webbean...
Author: struberg
Date: Wed May 6 19:42:44 2015
New Revision: 1678078
URL: http://svn.apache.org/r1678078
Log:
OWB-1050 move firing of @Initialized(ConversationScoped.class) into ContextsService to prevent endless loops.
This prevents an endless loop if a @ConversationScoped bean observers the @Initialized(ConverationScoped.class) event
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedInitBean.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/EndConversationObserver.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
openwebbeans/trunk/webbeans-web/src/main/java/org/apache/webbeans/web/context/WebContextsService.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java?rev=1678078&r1=1678077&r2=1678078&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/conversation/ConversationManager.java Wed May 6 19:42:44 2015
@@ -33,7 +33,6 @@ import javax.enterprise.inject.spi.BeanM
import org.apache.webbeans.annotation.DefaultLiteral;
import org.apache.webbeans.annotation.DestroyedLiteral;
-import org.apache.webbeans.annotation.InitializedLiteral;
import org.apache.webbeans.config.OWBLogConst;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.context.ConversationContext;
@@ -112,8 +111,6 @@ public class ConversationManager
conversationContext.setActive(true);
conversationContext.getConversation().setProblemDuringCreation(problem);
- webBeansContext.getBeanManagerImpl().fireEvent(getLifecycleEventPayload(conversationContext), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
-
return conversationContext;
}
@@ -190,7 +187,7 @@ public class ConversationManager
webBeansContext.getBeanManagerImpl().fireEvent(getLifecycleEventPayload(ctx), DestroyedLiteral.INSTANCE_CONVERSATION_SCOPED);
}
- private Object getLifecycleEventPayload(ConversationContext ctx)
+ public Object getLifecycleEventPayload(ConversationContext ctx)
{
Object payLoad = null;
if (ctx.getConversation().getId() != null)
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java?rev=1678078&r1=1678077&r2=1678078&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java Wed May 6 19:42:44 2015
@@ -41,6 +41,7 @@ import org.apache.webbeans.context.Depen
import org.apache.webbeans.context.RequestContext;
import org.apache.webbeans.context.SessionContext;
import org.apache.webbeans.context.SingletonContext;
+import org.apache.webbeans.conversation.ConversationManager;
public class DefaultContextsService extends AbstractContextsService
@@ -315,9 +316,15 @@ public class DefaultContextsService exte
private void startConversationContext(Object object)
{
- ConversationContext ctx = webBeansContext.getConversationManager().getConversationContext(getCurrentSessionContext());
-
+ ConversationManager conversationManager = webBeansContext.getConversationManager();
+ ConversationContext ctx = conversationManager.getConversationContext(getCurrentSessionContext());
+ ctx.setActive(true);
conversationContext.set(ctx);
+
+ if (ctx.getConversation().isTransient())
+ {
+ webBeansContext.getBeanManagerImpl().fireEvent(conversationManager.getLifecycleEventPayload(ctx), InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+ }
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedInitBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedInitBean.java?rev=1678078&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedInitBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedInitBean.java Wed May 6 19:42:44 2015
@@ -0,0 +1,43 @@
+/*
+* 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.webbeans.test.contexts.conversation;
+
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.Initialized;
+import javax.enterprise.event.Observes;
+import java.io.Serializable;
+
+/**
+ * A @Conversational Bean which observes the @Initialized(ConversationScoped.class) event
+ */
+@ConversationScoped
+public class ConversationScopedInitBean implements Serializable
+{
+ public static boolean gotStarted = false;
+
+ public int ping()
+ {
+ return 0;
+ }
+
+ public void onContextStart(@Observes @Initialized(ConversationScoped.class) Object payload)
+ {
+ gotStarted = true;
+ }
+}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java?rev=1678078&r1=1678077&r2=1678078&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java Wed May 6 19:42:44 2015
@@ -53,4 +53,32 @@ public class ConversationScopedTest exte
}
}
+
+ @Test
+ public void testConversationEvents()
+ {
+ try
+ {
+ ConversationScopedInitBean.gotStarted = false;
+ EndConversationObserver.endConversationCalled = false;
+
+ System.setProperty(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION, "true");
+ startContainer(ConversationScopedInitBean.class, EndConversationObserver.class);
+
+ ConversationScopedInitBean instance = getInstance(ConversationScopedInitBean.class);
+ instance.ping();
+
+ Assert.assertTrue(ConversationScopedInitBean.gotStarted);
+
+ shutDownContainer();
+
+ Assert.assertTrue(EndConversationObserver.endConversationCalled);
+ }
+ finally
+ {
+ System.clearProperty(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION);
+ }
+ }
+
+
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/EndConversationObserver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/EndConversationObserver.java?rev=1678078&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/EndConversationObserver.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/EndConversationObserver.java Wed May 6 19:42:44 2015
@@ -0,0 +1,35 @@
+/*
+* 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.webbeans.test.contexts.conversation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.ConversationScoped;
+import javax.enterprise.context.Destroyed;
+import javax.enterprise.event.Observes;
+
+@ApplicationScoped
+public class EndConversationObserver
+{
+ public static boolean endConversationCalled = false;
+
+ public void onEndConversation(@Observes @Destroyed(ConversationScoped.class) Object payload)
+ {
+ endConversationCalled = true;
+ }
+}
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=1678078&r1=1678077&r2=1678078&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 Wed May 6 19:42:44 2015
@@ -654,6 +654,13 @@ public class WebContextsService extends
conversationContext = conversationManager.getConversationContext(sessionContext);
conversationContexts.set(conversationContext);
+ if (conversationContext.getConversation().isTransient())
+ {
+ webBeansContext.getBeanManagerImpl().fireEvent(conversationManager.getLifecycleEventPayload(conversationContext),
+ InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
+ }
+
+
if (!ignoreProblems && conversationContext.getConversation().getProblemDuringCreation() != null)
{
throw conversationContext.getConversation().getProblemDuringCreation();