[jbossws-commits] JBossWS SVN: r12847 - stack/cxf/branches/cxf-2.3/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Tue Aug 24 18:43:19 EDT 2010


Author: alessio.soldano at jboss.com
Date: 2010-08-24 18:43:19 -0400 (Tue, 24 Aug 2010)
New Revision: 12847

Modified:
   stack/cxf/branches/cxf-2.3/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
Log:
[JBWS-3112] Ensure clean BusFactory threadlocals at deployment


Modified: stack/cxf/branches/cxf-2.3/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
===================================================================
--- stack/cxf/branches/cxf-2.3/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java	2010-08-24 20:25:46 UTC (rev 12846)
+++ stack/cxf/branches/cxf-2.3/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java	2010-08-24 22:43:19 UTC (rev 12847)
@@ -49,63 +49,74 @@
  */
 public class BusDeploymentAspect extends AbstractDeploymentAspect
 {
+   
    @SuppressWarnings("unchecked")
    @Override
    public void start(Deployment dep)
    {
-      ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
-      try
+      //synchronize as this assumes nothing deals with the BusFactory threadlocals associated with the system daemon
+      //thread doing the deployments, iow multiple concurrent deployment are not supported in this deployment aspect
+      synchronized (this)
       {
-         ArchiveDeployment aDep = (ArchiveDeployment)dep;
-         //set the runtime classloader (pointing to the deployment unit) to allow CXF accessing to the classes
-         SecurityActions.setContextClassLoader(dep.getRuntimeClassLoader());
-         
-         ResourceResolver deploymentResolver = aDep.getResourceResolver();
-         org.apache.cxf.resource.ResourceResolver resolver = new JBossWSResourceResolver(deploymentResolver);
-         Map<String, String> contextParams = (Map<String, String>)dep.getProperty(WSConstants.STACK_CONTEXT_PARAMS);
-         String jbosswsCxfXml =  contextParams == null ? null : contextParams.get(BusHolder.PARAM_CXF_BEANS_URL);
-         BusHolder holder = null;
-         
-         if (jbosswsCxfXml != null) // Spring available
+         ClassLoader origClassLoader = SecurityActions.getContextClassLoader();
+         try
          {
-            URL cxfServletURL = null;
-            try
+            //start cleaning the BusFactory thread locals
+            BusFactory.setDefaultBus(null);
+            BusFactory.setThreadDefaultBus(null);
+
+            ArchiveDeployment aDep = (ArchiveDeployment) dep;
+            //set the runtime classloader (pointing to the deployment unit) to allow CXF accessing to the classes
+            SecurityActions.setContextClassLoader(dep.getRuntimeClassLoader());
+
+            ResourceResolver deploymentResolver = aDep.getResourceResolver();
+            org.apache.cxf.resource.ResourceResolver resolver = new JBossWSResourceResolver(deploymentResolver);
+            Map<String, String> contextParams = (Map<String, String>) dep.getProperty(WSConstants.STACK_CONTEXT_PARAMS);
+            String jbosswsCxfXml = contextParams == null ? null : contextParams.get(BusHolder.PARAM_CXF_BEANS_URL);
+            BusHolder holder = null;
+
+            if (jbosswsCxfXml != null) // Spring available
             {
-               cxfServletURL = deploymentResolver.resolve("WEB-INF/cxf-servlet.xml");
+               URL cxfServletURL = null;
+               try
+               {
+                  cxfServletURL = deploymentResolver.resolve("WEB-INF/cxf-servlet.xml");
+               }
+               catch (IOException e)
+               {
+               } //ignore, cxf-servlet.xml is optional, we might even decide not to support this
+
+               try
+               {
+                  holder = new SpringBusHolder(cxfServletURL, deploymentResolver.resolve(jbosswsCxfXml));
+                  Configurer configurer = holder.createServerConfigurer(dep.getAttachment(BindingCustomization.class),
+                        new WSDLFilePublisher(aDep), dep.getService().getEndpoints());
+                  holder.configure(new SoapTransportFactoryExt(), resolver, configurer);
+               }
+               catch (Exception e)
+               {
+                  throw new RuntimeException(e); //re-throw, jboss-cxf.xml is required
+               }
             }
-            catch (IOException e)
+            else
+            //Spring not available
             {
-            } //ignore, cxf-servlet.xml is optional, we might even decide not to support this
-   
-            try
-            {
-               holder = new SpringBusHolder(cxfServletURL, deploymentResolver.resolve(jbosswsCxfXml));
-               Configurer configurer = holder.createServerConfigurer(dep.getAttachment(BindingCustomization.class), new WSDLFilePublisher(aDep),
-            		                                                 dep.getService().getEndpoints());
+               DDBeans metadata = dep.getAttachment(DDBeans.class);
+               holder = new NonSpringBusHolder(metadata);
+               Configurer configurer = holder.createServerConfigurer(dep.getAttachment(BindingCustomization.class),
+                     new WSDLFilePublisher(aDep), dep.getService().getEndpoints());
                holder.configure(new SoapTransportFactoryExt(), resolver, configurer);
             }
-            catch (Exception e)
-            {
-               throw new RuntimeException(e); //re-throw, jboss-cxf.xml is required
-            }
+            dep.addAttachment(BusHolder.class, holder);
          }
-         else //Spring not available
+         finally
          {
-            DDBeans metadata = dep.getAttachment(DDBeans.class);
-            holder = new NonSpringBusHolder(metadata);
-            Configurer configurer = holder.createServerConfigurer(dep.getAttachment(BindingCustomization.class), new WSDLFilePublisher(aDep),
-            		                                              dep.getService().getEndpoints());
-            holder.configure(new SoapTransportFactoryExt(), resolver, configurer);
+            //clean threadlocals in BusFactory and restore the original classloader
+            BusFactory.setDefaultBus(null);
+            BusFactory.setThreadDefaultBus(null);
+            SecurityActions.setContextClassLoader(origClassLoader);
          }
-         dep.addAttachment(BusHolder.class, holder);
       }
-      finally
-      {
-         //clean threadlocals in BusFactory and restore the original classloader
-         BusFactory.setDefaultBus(null);
-         BusFactory.setThreadDefaultBus(null);
-         SecurityActions.setContextClassLoader(origClassLoader);
-      }
    }
    
    @Override



More information about the jbossws-commits mailing list