This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openwebbeans.git


The following commit(s) were added to refs/heads/main by this push:
     new 04171df9c OWB-1074 - implement automatic supportsConversation() 
detection
04171df9c is described below

commit 04171df9cff1393e230d75685e33b4cd078ca2be
Author: tandraschko <[email protected]>
AuthorDate: Tue Apr 14 17:32:38 2026 +0200

    OWB-1074 - implement automatic supportsConversation() detection
---
 .../org/apache/webbeans/config/BeansDeployer.java  |  6 ++
 .../webbeans/config/OpenWebBeansConfiguration.java | 14 -----
 .../webbeans/context/AbstractContextsService.java  | 27 ++++++++-
 .../META-INF/openwebbeans/openwebbeans.properties  |  4 --
 .../conversation/ConversationManagerTest.java      | 10 +++-
 .../conversation/ConversationScopedTest.java       |  3 -
 .../ConversationSupportAutoModeTest.java           | 66 ++++++++++++++++++++++
 .../META-INF/openwebbeans/openwebbeans.properties  |  4 --
 .../junit5/internal/ScopesExtension.java           |  8 ++-
 .../META-INF/openwebbeans/openwebbeans.properties  |  2 -
 .../META-INF/openwebbeans/openwebbeans.properties  |  6 --
 .../web/tests/ConversationLoggingTest.java         |  1 -
 12 files changed, 112 insertions(+), 39 deletions(-)

diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java 
b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
index 1b9f88d85..dce99a7df 100644
--- a/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
+++ b/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
@@ -43,6 +43,7 @@ import org.apache.webbeans.container.AnnotatedTypeWrapper;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectableBeanManager;
 import org.apache.webbeans.container.InjectionResolver;
+import org.apache.webbeans.context.AbstractContextsService;
 import 
org.apache.webbeans.context.control.ActivateRequestContextInterceptorBean;
 import org.apache.webbeans.corespi.se.DefaultJndiService;
 import org.apache.webbeans.decorator.DecoratorsManager;
@@ -313,6 +314,11 @@ public class BeansDeployer
                 // We are finally done with our bean discovery
                 fireAfterBeanDiscoveryEvent();
 
+                if (webBeansContext.getContextsService() instanceof 
AbstractContextsService acs)
+                {
+                    acs.detectConversationSupport(webBeansContext);
+                }
+
                 // activate InjectionResolver cache now
                 
webBeansContext.getBeanManagerImpl().getInjectionResolver().setStartup(false);
 
diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
 
b/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
index a8c12b58e..c47ef8f92 100644
--- 
a/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
+++ 
b/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
@@ -114,9 +114,6 @@ public class OpenWebBeansConfiguration
     /**Application is core JSP*/
     public static final String APPLICATION_IS_JSP = 
"org.apache.webbeans.application.jsp";
 
-    /**Supports conversations*/
-    public static final String APPLICATION_SUPPORTS_CONVERSATION = 
"org.apache.webbeans.application.supportsConversation";
-
     /** @Produces with interceptor/decorator support */
     public static final String PRODUCER_INTERCEPTION_SUPPORT = 
"org.apache.webbeans.application.supportsProducerInterception";
 
@@ -426,17 +423,6 @@ public class OpenWebBeansConfiguration
         return Boolean.valueOf(value);
     }
 
-    /**
-     * Gets conversation supports property.
-     * @return true if supports
-     */
-    public boolean supportsConversation()
-    {
-        String value = getProperty(APPLICATION_SUPPORTS_CONVERSATION);
-
-        return Boolean.valueOf(value);
-    }
-
     /**
      * Flag which indicates that only jars with an explicit META-INF/beans.xml 
marker file shall get paresed.
      * Default is {@code false}
diff --git 
a/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
 
b/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
index a2ab5e6c2..b8e63f631 100644
--- 
a/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
+++ 
b/webbeans-impl/src/main/java/org/apache/webbeans/context/AbstractContextsService.java
@@ -23,12 +23,15 @@ import java.util.Iterator;
 import java.util.Set;
 
 import jakarta.enterprise.context.ContextException;
+import jakarta.enterprise.context.ConversationScoped;
 import jakarta.enterprise.context.SessionScoped;
 import jakarta.enterprise.context.spi.Context;
+import jakarta.enterprise.inject.spi.Bean;
 
 import org.apache.webbeans.annotation.BeforeDestroyedLiteral;
 import org.apache.webbeans.annotation.DestroyedLiteral;
 import org.apache.webbeans.annotation.InitializedLiteral;
+import org.apache.webbeans.component.OwbBean;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.conversation.ConversationImpl;
 import org.apache.webbeans.conversation.ConversationManager;
@@ -46,8 +49,30 @@ public abstract class AbstractContextsService implements 
ContextsService
     protected AbstractContextsService(WebBeansContext webBeansContext)
     {
         this.webBeansContext = webBeansContext;
-        supportsConversation = 
webBeansContext.getOpenWebBeansConfiguration().supportsConversation();
+        // OWB-1074: enabled after discovery via {@link 
#afterBeanDiscoveryConversationSupport}
+        supportsConversation = false;
+    }
 
+    /**
+     * OWB-1074: enable {@code ConversationScoped} infrastructure when the 
deployment defines at least
+     * one enabled bean with that scope (fast bean scan). Same rule in SE and 
servlet ({@code WebContextsService}) modes.
+     */
+    public void detectConversationSupport(WebBeansContext wbc)
+    {
+        boolean hasConversationScoped = false;
+        for (Bean<?> bean : wbc.getBeanManagerImpl().getBeans())
+        {
+            if (bean instanceof OwbBean && !((OwbBean) bean).isEnabled())
+            {
+                continue;
+            }
+            if (ConversationScoped.class.equals(bean.getScope()))
+            {
+                hasConversationScoped = true;
+                break;
+            }
+        }
+        setSupportConversations(hasConversationScoped);
     }
 
     @Override
diff --git 
a/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 
b/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index 1ecf5fe18..fc15cc253 100644
--- 
a/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ 
b/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -106,10 +106,6 @@ 
org.apache.webbeans.spi.deployer.useEjbMetaDataDiscoveryService=false
 # org.apache.webbeans.forceNoCheckedExceptions=true
 
################################################################################################
 
-################################# Conversation Support 
#########################################
-org.apache.webbeans.application.supportsConversation=false
-################################################################################################
-
 ################################### Default Conversation Service 
###############################
 # Default implementation of org.apache.webbeans.corespi.ConversationService.
 # This one does not support conversation propagation. It's basically a no-op 
implementation
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/conversation/ConversationManagerTest.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/conversation/ConversationManagerTest.java
index 65081cd11..92d9a02fd 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/conversation/ConversationManagerTest.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/conversation/ConversationManagerTest.java
@@ -23,6 +23,7 @@ import static org.apache.webbeans.util.Asserts.assertNotNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 
+import java.io.Serializable;
 import java.util.concurrent.atomic.AtomicReference;
 
 import jakarta.enterprise.context.ConversationScoped;
@@ -45,8 +46,7 @@ public class ConversationManagerTest extends AbstractUnitTest
                 return conversationId.get();
             }
         });
-        
addConfiguration("org.apache.webbeans.application.supportsConversation", 
"true");
-        startContainer();
+        startContainer(ConversationManagerConversationBean.class);
         final ContextsService contextsService = 
getWebBeansContext().getContextsService();
         contextsService.startContext(ConversationScoped.class, null);
         final ConversationContext conversationContext1 = 
ConversationContext.class.cast(
@@ -76,4 +76,10 @@ public class ConversationManagerTest extends AbstractUnitTest
         contextsService.getCurrentContext(ConversationScoped.class); // 
trigger update
         assertNotEquals(beginTime, conversation2.getLastAccessTime());
     }
+
+    @ConversationScoped
+    public static class ConversationManagerConversationBean implements 
Serializable
+    {
+        private static final long serialVersionUID = 1L;
+    }
 }
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
index 75df8cc92..416fbfcaa 100644
--- 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
@@ -23,7 +23,6 @@ import jakarta.enterprise.context.RequestScoped;
 import jakarta.enterprise.context.spi.Context;
 
 import org.junit.Assert;
-import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.junit.Test;
 
@@ -42,7 +41,6 @@ public class ConversationScopedTest extends AbstractUnitTest
     @Test
     public void testTransientConversation() throws Exception
     {
-        
addConfiguration(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION, 
"true");
         startContainer(ConversationScopedBean.class);
 
         ConversationScopedBean instance = 
getInstance(ConversationScopedBean.class);
@@ -64,7 +62,6 @@ public class ConversationScopedTest extends AbstractUnitTest
         ConversationScopedInitBean.gotStarted = false;
         EndConversationObserver.endConversationCalled = false;
 
-        
addConfiguration(OpenWebBeansConfiguration.APPLICATION_SUPPORTS_CONVERSATION, 
"true");
         startContainer(ConversationScopedInitBean.class, 
EndConversationObserver.class);
 
         ConversationScopedInitBean instance = 
getInstance(ConversationScopedInitBean.class);
diff --git 
a/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationSupportAutoModeTest.java
 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationSupportAutoModeTest.java
new file mode 100644
index 000000000..58514e03f
--- /dev/null
+++ 
b/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationSupportAutoModeTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 java.io.Serializable;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.context.ConversationScoped;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.webbeans.context.AbstractContextsService;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.test.AbstractUnitTest;
+
+/**
+ * OWB-1074: conversation support follows deployment (no configuration 
property).
+ */
+public class ConversationSupportAutoModeTest extends AbstractUnitTest
+{
+    @Test
+    public void autoModeWithoutConversationScopedBeanDisablesSupport()
+    {
+        startContainer(OnlyApplicationScoped.class);
+        ContextsService cs = getWebBeansContext().getContextsService();
+        Assert.assertTrue(cs instanceof AbstractContextsService);
+        Assert.assertFalse(((AbstractContextsService) 
cs).isSupportsConversation());
+    }
+
+    @Test
+    public void autoModeWithConversationScopedBeanEnablesSupport()
+    {
+        startContainer(PassivationCapableConversationBean.class);
+        ContextsService cs = getWebBeansContext().getContextsService();
+        Assert.assertTrue(cs instanceof AbstractContextsService);
+        Assert.assertTrue(((AbstractContextsService) 
cs).isSupportsConversation());
+    }
+
+    @ApplicationScoped
+    public static class OnlyApplicationScoped
+    {
+    }
+
+    @ConversationScoped
+    public static class PassivationCapableConversationBean implements 
Serializable
+    {
+        private static final long serialVersionUID = 1L;
+    }
+}
diff --git 
a/webbeans-jsf/src/main/resources/META-INF/openwebbeans/openwebbeans.properties 
b/webbeans-jsf/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index d2fc9fea8..aa21448ad 100644
--- 
a/webbeans-jsf/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ 
b/webbeans-jsf/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -33,7 +33,3 @@ 
org.apache.webbeans.conversation.Conversation.timeoutInterval=1800000
 #Default implementation of org.apache.webbeans.corespi.ConversationService.
 
org.apache.webbeans.spi.ConversationService=org.apache.webbeans.jsf.JsfConversationService
 
################################################################################################
-
-################################# Conversation Support 
#########################################
-org.apache.webbeans.application.supportsConversation=true
-################################################################################################
diff --git 
a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/ScopesExtension.java
 
b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/ScopesExtension.java
index 32bbba66d..6b3fdcc40 100644
--- 
a/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/ScopesExtension.java
+++ 
b/webbeans-junit5/src/main/java/org/apache/openwebbeans/junit5/internal/ScopesExtension.java
@@ -20,6 +20,7 @@ package org.apache.openwebbeans.junit5.internal;
 
 import org.apache.openwebbeans.junit5.Scopes;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.AbstractContextsService;
 import org.apache.webbeans.spi.ContextsService;
 import org.junit.jupiter.api.extension.AfterAllCallback;
 import org.junit.jupiter.api.extension.AfterEachCallback;
@@ -79,9 +80,12 @@ public class ScopesExtension implements BeforeAllCallback, 
AfterAllCallback, Bef
         {
             stopIfNeeded(scopes, contextsService, RequestScoped.class);
             stopIfNeeded(scopes, contextsService, SessionScoped.class);
-            if 
(webBeansContext.getOpenWebBeansConfiguration().supportsConversation())
+            if (contextsService instanceof AbstractContextsService acs)
             {
-                stopIfNeeded(scopes, contextsService, 
ConversationScoped.class);
+                if (acs.isSupportsConversation())
+                {
+                    stopIfNeeded(scopes, contextsService, 
ConversationScoped.class);
+                }
             }
         }
         return Stream.of(scopes)
diff --git 
a/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties 
b/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index bf0ea5f95..9aa73e58b 100644
--- 
a/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ 
b/webbeans-tck/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -33,8 +33,6 @@ org.apache.webbeans.application.supportsProducerInterception 
= false
 org.apache.webbeans.strictDynamicValidation = true
 
 org.apache.webbeans.spi.ConversationService = 
org.apache.openwebbeans.tck.conversation.TckConversationService
-org.apache.webbeans.application.supportsConversation=true
-
 
 # we have to switch back to the un-cached version of the normal scoping handler
 
org.apache.webbeans.proxy.mapping.jakarta.enterprise.context.ApplicationScoped=org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler
diff --git 
a/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties 
b/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
index 7247e0146..f62edf267 100644
--- 
a/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
+++ 
b/webbeans-web/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
@@ -54,9 +54,3 @@ org.apache.webbeans.application.jsp=false
 # This will get overwritten in the JSF plugins
 
org.apache.webbeans.spi.ConversationService=org.apache.webbeans.web.context.WebConversationService
 
################################################################################################
-
-################################## Conversation Support 
########################################
-# Whether conversations are supported or not
-# In webapps we now support conversations by default
-org.apache.webbeans.application.supportsConversation=true
-################################################################################################
diff --git 
a/webbeans-web/src/test/java/org/apache/webbeans/web/tests/ConversationLoggingTest.java
 
b/webbeans-web/src/test/java/org/apache/webbeans/web/tests/ConversationLoggingTest.java
index c33a2f175..1972552f4 100644
--- 
a/webbeans-web/src/test/java/org/apache/webbeans/web/tests/ConversationLoggingTest.java
+++ 
b/webbeans-web/src/test/java/org/apache/webbeans/web/tests/ConversationLoggingTest.java
@@ -105,7 +105,6 @@ public class ConversationLoggingTest
         System.setProperty(ScannerService.class.getName(), 
scannerServiceClass.getName());
         System.setProperty(ContainerLifecycle.class.getName(), 
WebContainerLifecycle.class.getName());
         System.setProperty(ConversationService.class.getName(), 
WebConversationService.class.getName());
-        
System.setProperty("org.apache.webbeans.application.supportsConversation", 
"false");
         try
         {
             final WebBeansConfigurationListener wbcl = new 
WebBeansConfigurationListener();

Reply via email to