Author: asoldano
Date: 2013-10-03 13:23:35 -0400 (Thu, 03 Oct 2013)
New Revision: 17976
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseTCCLBusFeature.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseThreadBusFeature.java
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Loggers.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Messages.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java
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/configuration/JBossWSBusFactory.java
Log:
[JBWS-3713] Adding client bus selector and jaxws features for controlling bus creation
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Loggers.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Loggers.java 2013-10-03
09:00:55 UTC (rev 17975)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Loggers.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -204,4 +204,8 @@
@LogMessage(level = INFO)
@Message(id = 24092, value = "Adding %s policy attachment with id='%s'
to honor requirement from %s.")
void addingPolicyAttachment(Object placement, String refId, Class<?> cls);
+
+ @LogMessage(level = WARN)
+ @Message(id = 24095, value = "Unknown strategy '%s' requested for
selecting the Apache CXF Bus to be used for building JAXWS clients; default strategy will
be used.")
+ void unknownJAXWSClientBusStrategy(String strategy);
}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Messages.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Messages.java 2013-10-03
09:00:55 UTC (rev 17975)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Messages.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -217,4 +217,7 @@
@Message(id = 24094, value = "Authorization failed, principal=%s")
SecurityException authorizationFailed(String principal);
+ @Message(id = 24096, value = "Multiple incompatible JAXWS client Bus features
provided")
+ IllegalArgumentException incompatibleJAXWSClientBusFeatureProvided();
+
}
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import static
org.jboss.wsf.stack.cxf.client.Constants.JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.Constants.NEW_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.Constants.TCCL_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.Constants.THREAD_BUS_STRATEGY;
+
+import javax.xml.ws.WebServiceFeature;
+
+import org.jboss.wsf.stack.cxf.Loggers;
+import org.jboss.wsf.stack.cxf.Messages;
+
+/**
+ * A class selecting the proper bus to be used for creating a
+ * JAXWS client.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Oct-2013
+ *
+ */
+public abstract class ClientBusSelector
+{
+ private static final String sysPropStrategy;
+ static {
+ final String propValue =
SecurityActions.getSystemProperty(JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY,
THREAD_BUS_STRATEGY);
+ if (THREAD_BUS_STRATEGY.equals(propValue) || NEW_BUS_STRATEGY.equals(propValue) ||
TCCL_BUS_STRATEGY.equals(propValue))
+ {
+ sysPropStrategy = propValue;
+ }
+ else
+ {
+ Loggers.ROOT_LOGGER.unknownJAXWSClientBusStrategy(propValue);
+ sysPropStrategy = THREAD_BUS_STRATEGY;
+ }
+ }
+
+ public static String selectStrategy(WebServiceFeature... features) {
+ boolean createNewBus = false;
+ boolean tcclBoundBus = false;
+ boolean threadBus = false;
+ int count = 0;
+ if (features != null)
+ {
+ for (WebServiceFeature f : features)
+ {
+ final String className = f.getClass().getName();
+ if (UseNewBusFeature.class.getName().equals(className))
+ {
+ createNewBus = f.isEnabled();
+ count++;
+ }
+ else if (UseTCCLBusFeature.class.getName().equals(className))
+ {
+ tcclBoundBus = f.isEnabled();
+ count++;
+ }
+ else if (UseThreadBusFeature.class.getName().equals(className))
+ {
+ threadBus = f.isEnabled();
+ count++;
+ }
+ }
+ }
+ if (count > 1)
+ {
+ throw Messages.MESSAGES.incompatibleJAXWSClientBusFeatureProvided();
+ }
+
+ String featureStrategy = null;
+ if (createNewBus)
+ {
+ featureStrategy = NEW_BUS_STRATEGY;
+ }
+ else if (tcclBoundBus)
+ {
+ featureStrategy = TCCL_BUS_STRATEGY;
+ }
+ else if (threadBus)
+ {
+ featureStrategy = THREAD_BUS_STRATEGY;
+ }
+ return featureStrategy != null ? featureStrategy : sysPropStrategy;
+ }
+}
Property changes on:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java 2013-10-03
09:00:55 UTC (rev 17975)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -43,4 +43,9 @@
public static final String CXF_MANAGEMENT_ENABLED =
"cxf.management.enabled";
public static final String CXF_MANAGEMENT_INSTALL_RESPONSE_TIME_INTERCEPTORS =
"cxf.management.installResponseTimeInterceptors";
public static final String CXF_WS_DISCOVERY_ENABLED =
"cxf.ws-discovery.enabled";
+
+ public static final String JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY =
"org.jboss.ws.cxf.jaxws-client.bus.strategy";
+ public static final String THREAD_BUS_STRATEGY = "THREAD_BUS";
+ public static final String NEW_BUS_STRATEGY = "NEW_BUS";
+ public static final String TCCL_BUS_STRATEGY = "TCCL_BUS";
}
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 2013-10-03
09:00:55 UTC (rev 17975)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -21,6 +21,12 @@
*/
package org.jboss.wsf.stack.cxf.client;
+import static org.jboss.wsf.stack.cxf.client.Constants.NEW_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.Constants.TCCL_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.Constants.THREAD_BUS_STRATEGY;
+import static org.jboss.wsf.stack.cxf.client.SecurityActions.getContextClassLoader;
+import static org.jboss.wsf.stack.cxf.client.SecurityActions.setContextClassLoader;
+
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -37,8 +43,8 @@
import javax.xml.ws.Endpoint;
import javax.xml.ws.EndpointContext;
import javax.xml.ws.EndpointReference;
-import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.Service.Mode;
+import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.spi.Invoker;
import javax.xml.ws.spi.ServiceDelegate;
@@ -158,16 +164,19 @@
@Override
public ServiceDelegate createServiceDelegate(URL url, QName qname, Class cls)
{
+ final String busStrategy = ClientBusSelector.selectStrategy();
ClassLoader origClassLoader = getContextClassLoader();
boolean restoreTCCL = false;
+ Bus orig = null;
try
{
restoreTCCL = checkAndFixContextClassLoader(origClassLoader);
- Bus bus = setValidThreadDefaultBus();
- return new JBossWSServiceImpl(bus, url, qname, cls);
+ orig = BusFactory.getThreadDefaultBus(false);
+ return new JBossWSServiceImpl(getOrCreateBus(busStrategy, origClassLoader), url,
qname, cls);
}
finally
{
+ restoreThreadDefaultBus(busStrategy, orig);
if (restoreTCCL)
setContextClassLoader(origClassLoader);
}
@@ -178,44 +187,56 @@
public ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName
serviceName, Class serviceClass,
WebServiceFeature... features)
{
+ //check feature types
+ for (WebServiceFeature f : features) {
+ final String fName = f.getClass().getName();
+ if (!fName.startsWith("javax.xml.ws") &&
!fName.startsWith("org.jboss.ws")) {
+ throw Messages.MESSAGES.unknownFeature(f.getClass().getName());
+ }
+ }
+
+ final String busStrategy = ClientBusSelector.selectStrategy(features);
ClassLoader origClassLoader = getContextClassLoader();
boolean restoreTCCL = false;
+ Bus orig = null;
try
{
restoreTCCL = checkAndFixContextClassLoader(origClassLoader);
- boolean createNewBus = false;
- for (WebServiceFeature f : features) {
- final String fName = f.getClass().getName();
- if (!fName.startsWith("javax.xml.ws") &&
!fName.startsWith("org.jboss.ws")) {
- throw Messages.MESSAGES.unknownFeature(f.getClass().getName());
- }
- if (fName.equals(UseNewBusFeature.class.getName())) {
- createNewBus = f.isEnabled();
- }
- }
- if (!createNewBus) {
- Bus bus = setValidThreadDefaultBus();
- return new JBossWSServiceImpl(bus, wsdlDocumentLocation, serviceName,
serviceClass, features);
- } else { //honor the UseNewBusFeature
- Bus orig = null;
- try {
- orig = BusFactory.getThreadDefaultBus(false);
- Bus bus = BusFactory.newInstance().createBus();
- return new JBossWSServiceImpl(bus, wsdlDocumentLocation, serviceName,
serviceClass, features);
- } finally {
- if (orig != null) {
- BusFactory.setThreadDefaultBus(orig);
- }
- }
- }
+ orig = BusFactory.getThreadDefaultBus(false);
+ return new JBossWSServiceImpl(getOrCreateBus(busStrategy, origClassLoader),
wsdlDocumentLocation, serviceName, serviceClass, features);
}
finally
{
+ restoreThreadDefaultBus(busStrategy, orig);
if (restoreTCCL)
setContextClassLoader(origClassLoader);
}
}
+ private static Bus getOrCreateBus(String strategy, ClassLoader
threadContextClassLoader) {
+ Bus bus = null;
+ if (THREAD_BUS_STRATEGY.equals(strategy))
+ {
+ bus = ProviderImpl.setValidThreadDefaultBus();
+ }
+ else if (NEW_BUS_STRATEGY.equals(strategy))
+ {
+ bus = new JBossWSBusFactory().createBus();
+ }
+ else if (TCCL_BUS_STRATEGY.equals(strategy))
+ {
+ bus = JBossWSBusFactory.getClassLoaderDefaultBus(threadContextClassLoader);
+ }
+ return bus;
+ }
+
+ private static void restoreThreadDefaultBus(final String busStrategy, final Bus
origBus) {
+ if (origBus != null && !busStrategy.equals(Constants.THREAD_BUS_STRATEGY))
+ {
+ BusFactory.setThreadDefaultBus(origBus);
+ }
+ }
+
/**
* Ensure the current context classloader can load this ProviderImpl class.
*
@@ -259,7 +280,7 @@
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
+ bus = new JBossWSBusFactory().createBus(); //this also set thread local bus
internally as it's not set yet
}
return bus;
}
@@ -282,56 +303,8 @@
});
}
}
-
- /**
- * Get context classloader.
- *
- * @return the current context classloader
- */
- static ClassLoader getContextClassLoader()
- {
- SecurityManager sm = System.getSecurityManager();
- if (sm == null)
- {
- return Thread.currentThread().getContextClassLoader();
- }
- else
- {
- return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
- }
- }
/**
- * Set context classloader.
- *
- * @param classLoader the classloader
- */
- static void setContextClassLoader(final ClassLoader classLoader)
- {
- if (System.getSecurityManager() == null)
- {
- Thread.currentThread().setContextClassLoader(classLoader);
- }
- else
- {
- AccessController.doPrivileged(new PrivilegedAction<Object>()
- {
- public Object run()
- {
- Thread.currentThread().setContextClassLoader(classLoader);
- return null;
- }
- });
- }
- }
-
- /**
* A javax.xml.ws.Endpoint implementation delegating to a provided one
* that sets the TCCL before doing publish.
*
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Oct-2013
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Set context classloader.
+ *
+ * @param classLoader the classloader
+ */
+ static void setContextClassLoader(final ClassLoader classLoader)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
+ }
+
+ /**
+ * Return the current value of the specified system property
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty(final String name, final String defaultValue)
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+}
Property changes on:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SecurityActions.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseTCCLBusFeature.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseTCCLBusFeature.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseTCCLBusFeature.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import javax.xml.ws.WebServiceFeature;
+
+/**
+ * A JBossWS-CXF custom WebServiceFeature to be used for building the
+ * JAXWS Service using the Bus associated with the current thread
+ * context classloader.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Oct-2013
+ *
+ */
+public class UseTCCLBusFeature extends WebServiceFeature
+{
+ public UseTCCLBusFeature() {
+ this.enabled = true;
+ }
+
+ public UseTCCLBusFeature(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public String getID()
+ {
+ return this.getClass().getName();
+ }
+
+}
Property changes on:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseTCCLBusFeature.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseThreadBusFeature.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseThreadBusFeature.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseThreadBusFeature.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.client;
+
+import javax.xml.ws.WebServiceFeature;
+
+/**
+ * A JBossWS-CXF custom WebServiceFeature to be used for building the
+ * JAXWS Service using the Bus associated with the current thread.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Oct-2013
+ *
+ */
+public class UseThreadBusFeature extends WebServiceFeature
+{
+ public UseThreadBusFeature() {
+ this.enabled = true;
+ }
+
+ public UseThreadBusFeature(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public String getID()
+ {
+ return this.getClass().getName();
+ }
+
+}
Property changes on:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/UseThreadBusFeature.java
___________________________________________________________________
Added: svn:keywords
+ Rev Date
Added: svn:eol-style
+ native
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 2013-10-03
09:00:55 UTC (rev 17975)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java 2013-10-03
17:23:35 UTC (rev 17976)
@@ -22,10 +22,14 @@
package org.jboss.wsf.stack.cxf.client.configuration;
import java.net.URL;
+import java.util.Iterator;
import java.util.Map;
+import java.util.WeakHashMap;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
import org.jboss.wsf.stack.cxf.client.util.SpringUtils;
/**
@@ -43,6 +47,8 @@
*/
public class JBossWSBusFactory extends BusFactory
{
+ private static final Map<ClassLoader, Bus> classLoaderBusses = new
WeakHashMap<ClassLoader, Bus>();
+
private JBossWSSpringBusFactory springBusFactory;
private JBossWSNonSpringBusFactory nonSpringBusFactory;
@@ -118,7 +124,7 @@
return getNonSpringBusFactory().createBus(extensions, properties);
}
- public JBossWSSpringBusFactory getSpringBusFactory()
+ public synchronized JBossWSSpringBusFactory getSpringBusFactory()
{
if (springBusFactory == null)
{
@@ -127,7 +133,7 @@
return springBusFactory;
}
- public JBossWSNonSpringBusFactory getNonSpringBusFactory()
+ public synchronized JBossWSNonSpringBusFactory getNonSpringBusFactory()
{
if (nonSpringBusFactory == null)
{
@@ -158,4 +164,69 @@
SecurityActions.setContextClassLoader(origClassLoader);
}
}
+
+ /**
+ * Gets the default bus for the given classloader
+ *
+ * @param classloader
+ * @return
+ */
+ public static Bus getClassLoaderDefaultBus(final ClassLoader classloader) {
+ Bus classLoaderBus;
+ synchronized (classLoaderBusses) {
+ classLoaderBus = classLoaderBusses.get(classloader);
+ if (classLoaderBus == null) {
+ classLoaderBus = new JBossWSBusFactory().createBus();
+ //register a listener for cleaning up the bus from the classloader
association in the JBossWSBusFactory
+ BusLifeCycleListener listener = new
ClassLoaderDefaultBusLifeCycleListener(classLoaderBus);
+
classLoaderBus.getExtension(BusLifeCycleManager.class).registerLifeCycleListener(listener);
+ classLoaderBusses.put(classloader, classLoaderBus);
+ }
+ }
+ return classLoaderBus;
+ }
+
+ /**
+ * Removes a bus from being the default bus for any classloader
+ *
+ * @param bus
+ */
+ public static void clearDefaultBusForAnyClassLoader(final Bus bus) {
+ synchronized (classLoaderBusses) {
+ for (final Iterator<Bus> iterator =
classLoaderBusses.values().iterator();
+ iterator.hasNext();) {
+ Bus itBus = iterator.next();
+ if (bus == null || itBus == null|| bus.equals(itBus)) {
+ iterator.remove();
+ }
+ }
+ }
+ }
+
+ private static class ClassLoaderDefaultBusLifeCycleListener implements
BusLifeCycleListener {
+
+ private final Bus bus;
+
+ public ClassLoaderDefaultBusLifeCycleListener(final Bus bus) {
+ this.bus = bus;
+ }
+
+ @Override
+ public void initComplete()
+ {
+ // NOOP
+ }
+
+ @Override
+ public void preShutdown()
+ {
+ // NOOP
+ }
+
+ @Override
+ public void postShutdown()
+ {
+ JBossWSBusFactory.clearDefaultBusForAnyClassLoader(this.bus);
+ }
+ }
}