[wise-commits] wise SVN: r554 - in core/trunk: core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder and 3 other directories.

wise-commits at lists.jboss.org wise-commits at lists.jboss.org
Mon Jun 10 18:59:32 EDT 2013


Author: alessio.soldano at jboss.com
Date: 2013-06-10 18:59:31 -0400 (Mon, 10 Jun 2013)
New Revision: 554

Added:
   core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/
   core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClient.java
   core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClientBuilder.java
   core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.client.builder.WSDynamicClientBuilder
Modified:
   core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSDynamicClientImpl.java
   core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSServiceImpl.java
   core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java
Log:
[WISE-202] Adding core-cxf flavour of the WSDynamicClient to set thread Bus


Modified: core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSDynamicClientImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSDynamicClientImpl.java	2013-05-16 04:34:52 UTC (rev 553)
+++ core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSDynamicClientImpl.java	2013-06-10 22:59:31 UTC (rev 554)
@@ -70,9 +70,9 @@
     @GuardedBy("this")
     private ClassLoader classLoader;
 
-    private final String userName;
+    protected final String userName;
 
-    private final String password;
+    protected final String password;
 
     private final EnablerDelegate wsExtensionEnablerDelegate;
 
@@ -84,7 +84,7 @@
 
     private final String tmpDir;
 
-    private final int maxThreadPoolSize;
+    protected final int maxThreadPoolSize;
 
     /**
      * @param builder
@@ -114,6 +114,11 @@
 	wsExtensionEnablerDelegate = EnablerDelegateProvider.newEnablerDelegate(builder.getSecurityConfigFileURL(), builder
 		.getSecurityConfigName());
 	this.tmpDir = builder.getClientSpecificTmpDir();
+	
+	this.prepare(builder, consumer);
+    }
+    
+    protected void prepare(WSDynamicClientBuilder builder, WSConsumer consumer) {
 	final File outputDir = new File(new StringBuilder(tmpDir).append(File.separator).append("classes").append(File.separator).toString());
 	final File sourceDir = new File(new StringBuilder(tmpDir).append(File.separator).append("src").append(File.separator).toString());
 
@@ -170,8 +175,7 @@
 		    Class<?> clazz = JavaUtils.loadJavaType(className, this.getClassLoader());
 		    Annotation annotation = clazz.getAnnotation(WebServiceClient.class);
 		    if (annotation != null) {
-			WSService service = new WSServiceImpl(clazz, this.getClassLoader(), clazz.newInstance(), userName,
-				password, this.maxThreadPoolSize);
+			WSService service = createService(clazz);
 			servicesMap.put(((WebServiceClient) annotation).name(), service);
 		    }
 		} catch (Exception e) {
@@ -187,6 +191,10 @@
 	}
 	return servicesMap;
     }
+    
+    protected WSService createService(Class<?> clazz) throws InstantiationException, IllegalAccessException {
+	return new WSServiceImpl(clazz, this.getClassLoader(), clazz.newInstance(), userName, password, this.maxThreadPoolSize);
+    }
 
     /**
      * {@inheritDoc}

Modified: core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSServiceImpl.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSServiceImpl.java	2013-05-16 04:34:52 UTC (rev 553)
+++ core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSServiceImpl.java	2013-06-10 22:59:31 UTC (rev 554)
@@ -46,7 +46,7 @@
     private final String userName;
     private final String password;
     private final Map<String, WSEndpoint> endpoints = Collections.synchronizedMap(new HashMap<String, WSEndpoint>());
-    private final int maxThreadPoolSize;
+    protected final int maxThreadPoolSize;
 
     /**
      * @param serviceClass
@@ -110,7 +110,7 @@
     private WSEndpoint getWiseEndpoint( Method method,
                                         String name ) throws WiseRuntimeException {
         ClassLoader oldLoader = SecurityActions.getContextClassLoader();
-        WSEndpointImpl ep = new WSEndpointImpl(this.maxThreadPoolSize);
+        WSEndpointImpl ep = createEndpoint();
         try {
             SecurityActions.setContextClassLoader(this.getClassLoader());
             ep.setClassLoader(this.getClassLoader());
@@ -132,6 +132,10 @@
         }
         return ep;
     }
+    
+    protected WSEndpointImpl createEndpoint() {
+	return new WSEndpointImpl(this.maxThreadPoolSize);
+    }
 
     private synchronized final Class<?> getServiceClass() {
         return serviceClass;

Modified: core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java	2013-05-16 04:34:52 UTC (rev 553)
+++ core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java	2013-06-10 22:59:31 UTC (rev 554)
@@ -140,9 +140,13 @@
 	    throw new IllegalStateException("wsdlURL cannot be null");
 	}
 
-	return new WSDynamicClientImpl(this);
+	return createClient();
 
     }
+    
+    protected WSDynamicClient createClient() {
+	return new WSDynamicClientImpl(this);
+    }
 
     /**
      * {@inheritDoc}

Added: core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClient.java
===================================================================
--- core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClient.java	                        (rev 0)
+++ core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClient.java	2013-06-10 22:59:31 UTC (rev 554)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.wise.core.client.impl;
+
+import java.util.Map;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.jboss.wise.core.client.WSService;
+import org.jboss.wise.core.client.builder.WSDynamicClientBuilder;
+import org.jboss.wise.core.client.impl.reflection.WSDynamicClientImpl;
+import org.jboss.wise.core.consumer.WSConsumer;
+import org.jboss.wise.core.exception.WiseRuntimeException;
+import org.jboss.wsf.stack.cxf.client.configuration.JBossWSBusFactory;
+import org.milyn.Smooks;
+
+/**
+ * A cxf specific version of the wise-core WSDynamicClient
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 10-Jun-2013
+ * 
+ */
+public class CXFDynamicClient extends WSDynamicClientImpl {
+    
+    private Bus bus;
+
+    public CXFDynamicClient(WSDynamicClientBuilder builder) throws WiseRuntimeException {
+	super(builder);
+    }
+    
+    protected CXFDynamicClient(WSDynamicClientBuilder builder, WSConsumer consumer) throws WiseRuntimeException {
+	super(builder, consumer);
+    }
+    
+    public CXFDynamicClient(WSDynamicClientBuilder builder, WSConsumer consumer, Smooks smooks) throws WiseRuntimeException {
+	super(builder, consumer, smooks);
+    }
+    
+    @Override
+    protected void prepare(WSDynamicClientBuilder builder, WSConsumer consumer) {
+	this.bus = JBossWSBusFactory.newInstance().createBus();
+	final Bus prevBus = BusFactory.getThreadDefaultBus(false);
+	try {
+	    BusFactory.setThreadDefaultBus(bus);
+	    super.prepare(builder, consumer);
+	} finally {
+	    BusFactory.setThreadDefaultBus(prevBus);
+	}
+    }
+    
+    @Override
+    public synchronized Map<String, WSService> processServices() throws IllegalStateException {
+	final Bus prevBus = BusFactory.getThreadDefaultBus(false);
+	try {
+	    if (bus != prevBus) {
+		BusFactory.setThreadDefaultBus(bus);
+	    }
+	    return super.processServices();
+	} finally {
+	    if (bus != prevBus) {
+		BusFactory.setThreadDefaultBus(prevBus);
+	    }
+	}
+    }
+    
+    @Override
+    public synchronized void close() {
+	try {
+	    super.close();
+	} finally {
+	    bus.shutdown(true);
+	}
+    }
+}

Added: core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClientBuilder.java
===================================================================
--- core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClientBuilder.java	                        (rev 0)
+++ core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/impl/CXFDynamicClientBuilder.java	2013-06-10 22:59:31 UTC (rev 554)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., 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.wise.core.client.impl;
+
+import org.jboss.wise.core.client.WSDynamicClient;
+import org.jboss.wise.core.client.impl.reflection.builder.ReflectionBasedWSDynamicClientBuilder;
+
+/**
+ * A cxf specific version of the wise-core ReflectionBasedWSDynamicClientBuilder
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 10-Jun-2013
+ */
+public class CXFDynamicClientBuilder extends ReflectionBasedWSDynamicClientBuilder {
+    
+    @Override
+    protected WSDynamicClient createClient() {
+	return new CXFDynamicClient(this);
+    }
+}

Added: core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.client.builder.WSDynamicClientBuilder
===================================================================
--- core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.client.builder.WSDynamicClientBuilder	                        (rev 0)
+++ core/trunk/core-cxf/src/main/resources/META-INF/services/org.jboss.wise.client.builder.WSDynamicClientBuilder	2013-06-10 22:59:31 UTC (rev 554)
@@ -0,0 +1 @@
+org.jboss.wise.core.client.impl.CXFDynamicClientBuilder
\ No newline at end of file



More information about the wise-commits mailing list