Author: asoldano
Date: 2014-10-01 08:23:59 -0400 (Wed, 01 Oct 2014)
New Revision: 18959
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SpringCustomClientBusSelector.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/client/ClientBusSelector.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-3832] Factor out jaxws client bus creation into client bus selector; add system
property based mechanism to setup custom client bus selector; provide a client bus
selector for reading a different spring bus descriptor.
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 2014-10-01
10:51:22 UTC (rev 18958)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/Loggers.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -232,4 +232,8 @@
@LogMessage(level = DEBUG)
@Message(id = 24103, value = "Could not load BouncyCastle security provider;
either setup your classpath properly or prevent loading by using the '%s' system
property.")
void cannotLoadBouncyCastleProvider(String property, @Cause Throwable cause);
+
+ @LogMessage(level = WARN)
+ @Message(id = 24105, value = "Could not create instance of specified
ClientBusSelector: %s")
+ void couldNotLoadClientBusSelector(String selector, @Cause Throwable cause);
}
Modified:
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 2014-10-01
10:51:22 UTC (rev 18958)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ClientBusSelector.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -1,6 +1,6 @@
/*
* JBoss, Home of Professional Open Source.
- * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * Copyright 2014, 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.
*
@@ -21,6 +21,7 @@
*/
package org.jboss.wsf.stack.cxf.client;
+import static
org.jboss.wsf.stack.cxf.client.Constants.JBWS_CXF_JAXWS_CLIENT_BUS_SELECTOR;
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;
@@ -28,9 +29,11 @@
import javax.xml.ws.WebServiceFeature;
+import org.apache.cxf.Bus;
import org.jboss.wsf.spi.classloading.ClassLoaderProvider;
import org.jboss.wsf.stack.cxf.Loggers;
import org.jboss.wsf.stack.cxf.Messages;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory;
/**
* A class selecting the proper bus to be used for creating a
@@ -40,8 +43,9 @@
* @since 03-Oct-2013
*
*/
-public abstract class ClientBusSelector
+public class ClientBusSelector
{
+ private static final ClientBusSelector instance;
private static final String sysPropStrategy;
static {
final String propValue =
SecurityActions.getSystemProperty(JBWS_CXF_JAXWS_CLIENT_BUS_STRATEGY,
ClassLoaderProvider.isSet() ? TCCL_BUS_STRATEGY : THREAD_BUS_STRATEGY);
@@ -54,9 +58,23 @@
Loggers.ROOT_LOGGER.unknownJAXWSClientBusStrategy(propValue);
sysPropStrategy = THREAD_BUS_STRATEGY;
}
+ final String selectorPropValue =
SecurityActions.getSystemProperty(JBWS_CXF_JAXWS_CLIENT_BUS_SELECTOR,
ClientBusSelector.class.getName());
+ ClientBusSelector cbs;
+ try {
+ Class<?> clazz = Class.forName(selectorPropValue);
+ cbs = (ClientBusSelector)clazz.newInstance();
+ } catch (Exception e) {
+ Loggers.ROOT_LOGGER.couldNotLoadClientBusSelector(selectorPropValue, e);
+ cbs = new ClientBusSelector();
+ }
+ instance = cbs;
}
- public static String selectStrategy(WebServiceFeature... features) {
+ public static ClientBusSelector getInstance() {
+ return instance;
+ }
+
+ public String selectStrategy(WebServiceFeature... features) {
boolean createNewBus = false;
boolean tcclBoundBus = false;
boolean threadBus = false;
@@ -104,6 +122,10 @@
return featureStrategy != null ? featureStrategy : sysPropStrategy;
}
+ public Bus createNewBus() {
+ return new JBossWSBusFactory().createBus();
+ }
+
public static String getDefaultStrategy() {
return sysPropStrategy;
}
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 2014-10-01
10:51:22 UTC (rev 18958)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/Constants.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -50,4 +50,6 @@
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";
+ public static final String JBWS_CXF_JAXWS_CLIENT_BUS_SELECTOR =
"org.jboss.ws.cxf.jaxws-client.bus.selector";
+ public static final String JBWS_CXF_JAXWS_CLIENT_BUS_SPRING_DESCRIPTOR =
"org.jboss.ws.cxf.jaxws-client.bus.spring.descriptor";
}
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 2014-10-01
10:51:22 UTC (rev 18958)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/ProviderImpl.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -236,7 +236,7 @@
@Override
public ServiceDelegate createServiceDelegate(URL url, QName qname, Class cls)
{
- final String busStrategy = ClientBusSelector.selectStrategy();
+ final String busStrategy = ClientBusSelector.getInstance().selectStrategy();
ClassLoader origClassLoader = getContextClassLoader();
boolean restoreTCCL = false;
Bus orig = null;
@@ -267,7 +267,7 @@
}
}
- final String busStrategy = ClientBusSelector.selectStrategy(features);
+ final String busStrategy =
ClientBusSelector.getInstance().selectStrategy(features);
ClassLoader origClassLoader = getContextClassLoader();
boolean restoreTCCL = false;
Bus orig = null;
@@ -285,15 +285,15 @@
}
}
- private static Bus getOrCreateBus(String strategy, ClassLoader
threadContextClassLoader) {
+ private Bus getOrCreateBus(String strategy, ClassLoader threadContextClassLoader) {
Bus bus = null;
if (THREAD_BUS_STRATEGY.equals(strategy))
{
- bus = ProviderImpl.setValidThreadDefaultBus();
+ bus = setValidThreadDefaultBus();
}
else if (NEW_BUS_STRATEGY.equals(strategy))
{
- bus = new JBossWSBusFactory().createBus();
+ bus = ClientBusSelector.getInstance().createNewBus();
//to prevent issues with CXF code using the default thread bus instead of the
one returned here,
//set the new bus as thread one, given the line above could have not done this
if the current
//thread is already assigned a bus
@@ -301,7 +301,7 @@
}
else if (TCCL_BUS_STRATEGY.equals(strategy))
{
- bus = JBossWSBusFactory.getClassLoaderDefaultBus(threadContextClassLoader);
+ bus = JBossWSBusFactory.getClassLoaderDefaultBus(threadContextClassLoader,
ClientBusSelector.getInstance());
//to prevent issues with CXF code using the default thread bus instead of the
one returned here,
//set the bus as thread one, given the line above could have not done this if we
already had a
//bus for the classloader and hence we did not create a new one
@@ -310,7 +310,7 @@
return bus;
}
- private static void restoreThreadDefaultBus(final String busStrategy, final Bus
origBus) {
+ private void restoreThreadDefaultBus(final String busStrategy, final Bus origBus) {
if (origBus != null || !busStrategy.equals(Constants.THREAD_BUS_STRATEGY))
{
BusFactory.setThreadDefaultBus(origBus);
@@ -352,7 +352,7 @@
return false;
}
- static Bus setValidThreadDefaultBus()
+ private Bus setValidThreadDefaultBus()
{
//we need to prevent using the default bus when the current
//thread is not already associated to a bus. In those situations we create
@@ -360,7 +360,7 @@
Bus bus = BusFactory.getThreadDefaultBus(false);
if (bus == null)
{
- bus = new JBossWSBusFactory().createBus(); //this also set thread local bus
internally as it's not set yet
+ bus = ClientBusSelector.getInstance().createNewBus(); //this also set thread
local bus internally as it's not set yet
}
return bus;
}
Added:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SpringCustomClientBusSelector.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SpringCustomClientBusSelector.java
(rev 0)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SpringCustomClientBusSelector.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2014, 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_SPRING_DESCRIPTOR;
+
+import org.apache.cxf.Bus;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory;
+
+/**
+ * A ClientBusSelector extension to be used with Spring integration for processing
+ * a different (cxf-client.xml) Bus descriptor when building JAX-WS clients.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 01-Oct-2014
+ *
+ */
+public class SpringCustomClientBusSelector extends ClientBusSelector
+{
+ private static final String clientBusDescriptor =
SecurityActions.getSystemProperty(JBWS_CXF_JAXWS_CLIENT_BUS_SPRING_DESCRIPTOR,
"cxf-client.xml");
+
+ @Override
+ public Bus createNewBus() {
+ return new JBossWSBusFactory().createBus(clientBusDescriptor);
+ }
+
+}
Property changes on:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/SpringCustomClientBusSelector.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 2014-10-01
10:51:22 UTC (rev 18958)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/JBossWSBusFactory.java 2014-10-01
12:23:59 UTC (rev 18959)
@@ -30,6 +30,7 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.buslifecycle.BusLifeCycleListener;
import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+import org.jboss.wsf.stack.cxf.client.ClientBusSelector;
import org.jboss.wsf.stack.cxf.client.util.SpringUtils;
/**
@@ -166,6 +167,29 @@
}
/**
+ * Gets the default bus for the given classloader; if a new Bus is needed,
+ * the creation is delegated to the specified ClientBusSelector instance.
+ *
+ * @param classloader
+ * @param clientBusSelector
+ * @return
+ */
+ public static Bus getClassLoaderDefaultBus(final ClassLoader classloader, final
ClientBusSelector clientBusSelector) {
+ Bus classLoaderBus;
+ synchronized (classLoaderBusses) {
+ classLoaderBus = classLoaderBusses.get(classloader);
+ if (classLoaderBus == null) {
+ classLoaderBus = clientBusSelector.createNewBus();
+ //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;
+ }
+
+ /**
* Gets the default bus for the given classloader
*
* @param classloader