tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1557573 - /tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
Date Sun, 12 Jan 2014 17:58:37 GMT
Author: rmannibucau
Date: Sun Jan 12 17:58:37 2014
New Revision: 1557573

URL: http://svn.apache.org/r1557573
Log:
allowing to deactivate jaxws endpoint as cdi beans + correct cleanup

Modified:
    tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java

Modified: tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java?rev=1557573&r1=1557572&r2=1557573&view=diff
==============================================================================
--- tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
(original)
+++ tomee/tomee/trunk/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/pojo/PojoEndpoint.java
Sun Jan 12 17:58:37 2014
@@ -29,9 +29,9 @@ import org.apache.cxf.transport.http.HTT
 import org.apache.openejb.Injection;
 import org.apache.openejb.InjectionProcessor;
 import org.apache.openejb.assembler.classic.util.ServiceConfiguration;
-import org.apache.openejb.cdi.CdiAppContextsService;
 import org.apache.openejb.core.webservices.JaxWsUtils;
 import org.apache.openejb.core.webservices.PortData;
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.server.cxf.CxfEndpoint;
 import org.apache.openejb.server.cxf.CxfServiceConfiguration;
 import org.apache.openejb.server.cxf.JaxWsImplementorInfoImpl;
@@ -41,6 +41,7 @@ import org.apache.webbeans.component.Abs
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.context.creational.CreationalContextImpl;
+import org.apache.webbeans.inject.OWBInjector;
 import org.apache.webbeans.util.WebBeansUtil;
 
 import javax.enterprise.context.Dependent;
@@ -61,8 +62,10 @@ import static org.apache.openejb.Injecti
 public class PojoEndpoint extends CxfEndpoint {
     private static final Logger LOGGER = Logger.getInstance(LogCategory.CXF, PojoEndpoint.class);
     private static final WebServiceContextResourceResolver WEB_SERVICE_CONTEXT_RESOURCE_RESOLVER
= new WebServiceContextResourceResolver();
+    private static final boolean JAXWS_AS_CDI_BEANS = SystemInstance.get().getOptions().get("openejb.cxf.cdi",
true);
 
     private final ResourceInjector injector;
+    private CreationalContextImpl toClean = null;
 
     public PojoEndpoint(ClassLoader loader, Bus bus, PortData port, Context context, Class<?>
instance,
                         HTTPTransportFactory httpTransportFactory,
@@ -106,40 +109,42 @@ public class PojoEndpoint extends CxfEnd
             final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
             final BeanManagerImpl bm = webBeansContext.getBeanManagerImpl();
             if (bm.isInUse()) { // try cdi bean
-                try {
-                    final Set<Bean<?>> beans = bm.getBeans(instance);
-                    final Bean<?> bean = bm.resolve(beans);
-                    CreationalContextImpl creationalContext = bm.createCreationalContext(bean);
-                    if (bean != null) {
-                        Bean<?> oldBean = creationalContext.putBean(bean);
-                        try {
-                            if (AbstractOwbBean.class.isInstance(bean)) {
-                                final AbstractOwbBean<?> aob = AbstractOwbBean.class.cast(bean);
-
-                                final Producer producer = aob.getProducer();
-                                implementor = producer.produce(creationalContext);
-                                if (producer instanceof InjectionTarget) {
-                                    final InjectionTarget injectionTarget = (InjectionTarget)
producer;
-                                    injectionTarget.inject(implementor, creationalContext);
-                                    injector = injectCxfResources(implementor); // we need
it before postconstruct
-                                    injectionTarget.postConstruct(implementor);
-                                }
-                                if (aob.getScope().equals(Dependent.class)) {
-                                    creationalContext.addDependent(aob, instance);
+                if (JAXWS_AS_CDI_BEANS) {
+                    try {
+                        final Set<Bean<?>> beans = bm.getBeans(instance);
+                        final Bean<?> bean = bm.resolve(beans);
+                        CreationalContextImpl creationalContext = bm.createCreationalContext(bean);
+                        if (bean != null) {
+                            Bean<?> oldBean = creationalContext.putBean(bean);
+                            try {
+                                if (AbstractOwbBean.class.isInstance(bean)) {
+                                    final AbstractOwbBean<?> aob = AbstractOwbBean.class.cast(bean);
+
+                                    final Producer producer = aob.getProducer();
+                                    implementor = producer.produce(creationalContext);
+                                    if (producer instanceof InjectionTarget) {
+                                        final InjectionTarget injectionTarget = (InjectionTarget)
producer;
+                                        injectionTarget.inject(implementor, creationalContext);
+                                        injector = injectCxfResources(implementor); // we
need it before postconstruct
+                                        injectionTarget.postConstruct(implementor);
+                                    }
+                                    if (aob.getScope().equals(Dependent.class)) {
+                                        creationalContext.addDependent(aob, instance);
+                                    }
                                 }
+                            } finally {
+                                creationalContext.putBean(oldBean);
                             }
-                        } finally {
-                            creationalContext.putBean(oldBean);
+                        } else {
+                            implementor = bm.getReference(bean, instance, creationalContext);
+                            injector = injectCxfResources(implementor);
                         }
-                    } else {
-                        implementor = bm.getReference(bean, instance, creationalContext);
-                        injector = injectCxfResources(implementor);
-                    }
-                    if (WebBeansUtil.isDependent(bean)) { // should be isPseudoScope but
should be ok for jaxws
-                        CdiAppContextsService.pushRequestReleasable(new RealeaseCreationalContextRunnable(creationalContext));
+                        if (WebBeansUtil.isDependent(bean)) { // should be isPseudoScope
but should be ok for jaxws
+                            toClean = creationalContext;
+                        }
+                    } catch (final Exception ie) {
+                        LOGGER.info("Can't use cdi to create " + instance + " webservice:
" + ie.getMessage());
                     }
-                } catch (final Exception ie) {
-                    LOGGER.info("Can't use cdi to create " + instance + " webservice: " +
ie.getMessage());
                 }
             }
             if (implementor == null) { // old pojo style
@@ -147,6 +152,11 @@ public class PojoEndpoint extends CxfEnd
                 injectionProcessor.createInstance();
                 implementor = injectionProcessor.getInstance();
                 injector = injectCxfResources(implementor);
+                if (!JAXWS_AS_CDI_BEANS && bm.isInUse()) {
+                    final CreationalContextImpl creationalContext = bm.createCreationalContext(null);
+                    OWBInjector.inject(bm, implementor, null);
+                    toClean = creationalContext;
+                }
                 injector.invokePostConstruct();
             }
         } catch (final Exception e) {
@@ -198,20 +208,11 @@ public class PojoEndpoint extends CxfEnd
             injector.invokePreDestroy();
         }
 
-        // shutdown server
-        super.stop();
-    }
-
-    private static class RealeaseCreationalContextRunnable implements Runnable {
-        private final CreationalContextImpl<?> cc;
-
-        public RealeaseCreationalContextRunnable(final CreationalContextImpl<?> creationalContext)
{
-            this.cc = creationalContext;
+        if (toClean != null) {
+            toClean.release();
         }
 
-        @Override
-        public void run() {
-            cc.release();
-        }
+        // shutdown server
+        super.stop();
     }
 }



Mime
View raw message