Author: alessio.soldano(a)jboss.com
Date: 2010-10-06 06:30:11 -0400 (Wed, 06 Oct 2010)
New Revision: 13063
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AbstractInvoker.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFNonSpringServletExt.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/config/CXFStackConfigFactory.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/JMSEndpointDeploymentAspectDelegate.java
Log:
[JBWS-3144] Fixes to default bus handling in the integration code
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -21,10 +21,15 @@
*/
package org.jboss.wsf.stack.cxf.client;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceFeature;
+import javax.xml.ws.spi.ServiceDelegate;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxws.ServiceImpl;
import org.jboss.logging.Logger;
/**
@@ -50,4 +55,35 @@
}
return super.createEndpointImpl(bus, bindingId, implementor, features);
}
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ServiceDelegate createServiceDelegate(URL url, QName qname, Class cls)
+ {
+ //we override this method to prevent using the default bus when the current
+ //thread is not already associated to a bus. In those situations we create
+ //a new bus from scratch instead and link that to the thread.
+ Bus bus = BusFactory.getThreadDefaultBus(false);
+ if (bus == null)
+ {
+ bus = BusFactory.newInstance().createBus(); //this also set thread local bus
internally as it's not set yet
+ }
+ return new ServiceImpl(bus, url, qname, cls);
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName
serviceName, Class serviceClass,
+ WebServiceFeature... features)
+ {
+ //we override this method to prevent using the default bus when the current
+ //thread is not already associated to a bus. In those situations we create
+ //a new bus from scratch instead and link that to the thread.
+ Bus bus = BusFactory.getThreadDefaultBus(false);
+ if (bus == null)
+ {
+ bus = BusFactory.newInstance().createBus(); //this also set thread local bus
internally as it's not set yet
+ }
+ return super.createServiceDelegate(wsdlDocumentLocation, serviceName, serviceClass,
features);
+ }
}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ServiceObjectFactory.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -106,10 +106,11 @@
// class instances
final Class<?> serviceClass = this.getClass(serviceImplClass);
final Class<?> targetClass = this.getClass(targetClassName);
- // construct service
- BusFactory.setDefaultBus(null);
+ // clean thread local bus before constructing Service
+ BusFactory.setThreadDefaultBus(null);
try
{
+ // construct service
final Bus bus = this.createNewBus(serviceRef);
final Service serviceInstance = this.instantiateService(serviceRef,
serviceClass);
if (serviceRef.getHandlerChain() != null)
@@ -131,7 +132,7 @@
}
finally
{
- BusFactory.setDefaultBus(null);
+ BusFactory.setThreadDefaultBus(null);
}
}
catch (Exception ex)
@@ -155,8 +156,6 @@
private Bus createNewBus(final UnifiedServiceRefMetaData serviceRefMD)
{
final Bus bus;
- // Always reset bus before constructing Service
-
final URL cxfConfig = this.getCXFConfiguration(serviceRefMD.getVfsRoot());
if (cxfConfig != null)
{
@@ -166,7 +165,8 @@
}
else
{
- bus = BusFactory.getThreadDefaultBus();
+ Bus threadBus = BusFactory.getThreadDefaultBus(false);
+ bus = threadBus != null ? threadBus : BusFactory.newInstance().createBus();
}
//Add extension to configure stub properties using the UnifiedServiceRefMetaData
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -26,6 +26,7 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.jboss.logging.Logger;
import org.jboss.wsf.stack.cxf.client.util.SpringUtils;
/**
@@ -101,18 +102,27 @@
}
/** JBossWSNonSpringBusFactory methods **/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public Bus createBus(Map<Class, Object> extensions)
{
return getNonSpringBusFactory().createBus(extensions);
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public Bus createBus(Map<Class, Object> extensions, Map<String, Object>
properties)
{
return getNonSpringBusFactory().createBus(extensions, properties);
}
+ /**
+ * Makes sure the default bus is initialized
+ */
+ public static void initializeDefaultBus()
+ {
+ long i = System.currentTimeMillis();
+ getDefaultBus();
+ Logger.getLogger(JBossWSBusFactory.class).info("Time taken for
initializeDefaultBus: " + (System.currentTimeMillis() - i));
+ }
public JBossWSSpringBusFactory getSpringBusFactory()
{
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AbstractInvoker.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AbstractInvoker.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/AbstractInvoker.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -158,7 +158,7 @@
inv.setArgs(params);
Object retObj = null;
- Bus threadBus = BusFactory.getThreadDefaultBus();
+ Bus threadBus = BusFactory.getThreadDefaultBus(false);
try
{
invHandler.invoke(ep, inv);
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFNonSpringServletExt.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFNonSpringServletExt.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFNonSpringServletExt.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -70,9 +70,9 @@
private void updateAvailableBusWithServletInfo(ServletConfig servletConfig)
{
BusHolder holder =
endpoint.getService().getDeployment().getAttachment(BusHolder.class);
- //set the bus from deployment into the CXF servlet and assign it to the current
thread
+ //set the bus from deployment into the CXF servlet and assign it to the current
thread (do not touch the default bus!)
bus = holder.getBus();
- BusFactory.possiblySetDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
//update the resource manager adding the ServletContextResourceResolver that was to
be added by CXF servlet
ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
resourceManager.addResourceResolver(new
ServletContextResourceResolver(servletConfig.getServletContext()));
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/CXFServletExt.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -69,9 +69,9 @@
private void updateAvailableBusWithServletInfo(ServletConfig servletConfig)
{
BusHolder holder =
endpoint.getService().getDeployment().getAttachment(BusHolder.class);
- //set the bus from deployment into the CXF servlet and assign it to the current
thread
+ //set the bus from deployment into the CXF servlet and assign it to the current
thread (do not touch the default bus!)
bus = holder.getBus();
- BusFactory.possiblySetDefaultBus(bus);
+ BusFactory.setThreadDefaultBus(bus);
//update the resource manager adding the ServletContextResourceResolver that was to
be added by CXF servlet
ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
resourceManager.addResourceResolver(new
ServletContextResourceResolver(servletConfig.getServletContext()));
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/config/CXFStackConfigFactory.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/config/CXFStackConfigFactory.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/config/CXFStackConfigFactory.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -23,6 +23,7 @@
import org.jboss.wsf.spi.management.StackConfig;
import org.jboss.wsf.spi.management.StackConfigFactory;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory;
/**
*
@@ -44,6 +45,7 @@
public String getImplementationTitle()
{
+ JBossWSBusFactory.initializeDefaultBus();
return getClass().getPackage().getImplementationTitle();
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/BusDeploymentAspect.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -62,7 +62,6 @@
try
{
//start cleaning the BusFactory thread locals
- BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
ArchiveDeployment aDep = (ArchiveDeployment) dep;
@@ -112,7 +111,6 @@
finally
{
//clean threadlocals in BusFactory and restore the original classloader
- BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
SecurityActions.setContextClassLoader(origClassLoader);
}
Modified:
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/JMSEndpointDeploymentAspectDelegate.java
===================================================================
---
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/JMSEndpointDeploymentAspectDelegate.java 2010-10-06
10:29:20 UTC (rev 13062)
+++
stack/cxf/trunk/modules/server/src/main/java/org/jboss/wsf/stack/cxf/deployment/aspect/JMSEndpointDeploymentAspectDelegate.java 2010-10-06
10:30:11 UTC (rev 13063)
@@ -61,7 +61,6 @@
finally
{
- BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
SecurityActions.setContextClassLoader(origClassLoader);
}