cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cxf git commit: Ensuring CDI Bean<?> are always the CDI context ones. This closes #181.
Date Fri, 21 Oct 2016 02:06:36 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 2e6e9debe -> a2879acdf


Ensuring CDI Bean<?> are always the CDI context ones.
This closes #181.


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2879acd
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2879acd
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2879acd

Branch: refs/heads/master
Commit: a2879acdff6793dfe199ac17877797f894da2ab9
Parents: 2e6e9de
Author: rmannibucau <rmannibucau@apache.org>
Authored: Wed Oct 19 21:40:01 2016 +0200
Committer: reta <drreta@gmail.com>
Committed: Thu Oct 20 21:59:18 2016 -0400

----------------------------------------------------------------------
 .../java/org/apache/cxf/cdi/CXFCdiServlet.java    |  2 +-
 .../apache/cxf/cdi/JAXRSCdiResourceExtension.java | 18 ++++++++----------
 2 files changed, 9 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2879acd/integration/cdi/src/main/java/org/apache/cxf/cdi/CXFCdiServlet.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/CXFCdiServlet.java b/integration/cdi/src/main/java/org/apache/cxf/cdi/CXFCdiServlet.java
index 389f201..7a090e5 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/CXFCdiServlet.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/CXFCdiServlet.java
@@ -51,7 +51,7 @@ public class CXFCdiServlet extends CXFNonSpringServlet {
             final Set< Bean< ? > > candidates = beanManager.getBeans(CdiBusBean.CXF);
             
             if (!candidates.isEmpty()) {
-                final Bean< ? > candidate = candidates.iterator().next();
+                final Bean< ? > candidate = beanManager.resolve(candidates);
                 
                 bus = (Bus)beanManager.getReference(candidate, Bus.class, 
                     beanManager.createCreationalContext(candidate));                

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2879acd/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
----------------------------------------------------------------------
diff --git a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
index 39baee5..50d31c6 100644
--- a/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
+++ b/integration/cdi/src/main/java/org/apache/cxf/cdi/JAXRSCdiResourceExtension.java
@@ -55,7 +55,7 @@ import org.apache.cxf.jaxrs.utils.ResourceUtils;
  * Apache CXF portable CDI extension to support initialization of JAX-RS resources.  
  */
 public class JAXRSCdiResourceExtension implements Extension {
-    private Bean< ? > busBean;
+    private boolean hasBus;
     private Bus bus;
 
     private final List< Bean< ? > > applicationBeans = new ArrayList< Bean<
? > >();
@@ -75,16 +75,16 @@ public class JAXRSCdiResourceExtension implements Extension {
             featureBeans.add((Bean< ? extends Feature >)event.getBean());
         } else if (CdiBusBean.CXF.equals(event.getBean().getName())
                 && Bus.class.isAssignableFrom(event.getBean().getBeanClass())) {
-            busBean = event.getBean();
+            hasBus = true;
         }
     }
 
     public void load(@Observes final AfterDeploymentValidation event, final BeanManager beanManager)
{
+        // no need of creational context, it only works for app scoped instances anyway
+        final Bean<?> busBean = beanManager.resolve(beanManager.getBeans(CdiBusBean.CXF));
         bus = (Bus)beanManager.getReference(
-            busBean,
-            busBean.getBeanClass(),
-            beanManager.createCreationalContext(busBean)
-        );
+                busBean, Bus.class,
+                beanManager.createCreationalContext(busBean));
 
         for (final Bean< ? > application: applicationBeans) {
             final Application instance = (Application)beanManager.getReference(
@@ -113,15 +113,13 @@ public class JAXRSCdiResourceExtension implements Extension {
     }
 
     public void injectBus(@Observes final AfterBeanDiscovery event, final BeanManager beanManager)
{
-        if (busBean == null) {
+        if (!hasBus) {
             final AnnotatedType< ExtensionManagerBus > busAnnotatedType =
                 beanManager.createAnnotatedType(ExtensionManagerBus.class);
 
             final InjectionTarget<ExtensionManagerBus> busInjectionTarget =
                 beanManager.createInjectionTarget(busAnnotatedType);
-
-            busBean = new CdiBusBean(busInjectionTarget);
-            event.addBean(busBean);
+            event.addBean(new CdiBusBean(busInjectionTarget));
         }
     }
 


Mime
View raw message