You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2007/03/23 04:27:51 UTC
svn commit: r521566 - in /incubator/cxf/trunk:
common/common/src/main/java/org/apache/cxf/common/util/
rt/core/src/main/java/org/apache/cxf/endpoint/
rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/
systests/ systests/src/test/java/or...
Author: ningjiang
Date: Thu Mar 22 20:27:50 2007
New Revision: 521566
URL: http://svn.apache.org/viewvc?view=rev&rev=521566
Log:
[CXF-452] Applied Guillaume's patch, added unitest and systest of the DynamicalClientFactory and made it really workable.
Modified:
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java
incubator/cxf/trunk/systests/pom.xml
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/PrimitiveUtils.java Thu Mar 22 20:27:50 2007
@@ -24,6 +24,35 @@
private PrimitiveUtils() {
}
+
+ public static Class getClass(String value) {
+ Class clz = null;
+ if ("int".equals(value)) {
+ clz = int.class;
+ }
+ if ("byte".equals(value)) {
+ clz = byte.class;
+ }
+ if ("short".equals(value)) {
+ clz = short.class;
+ }
+ if ("long".equals(value)) {
+ clz = long.class;
+ }
+ if ("float".equals(value)) {
+ clz = float.class;
+ }
+ if ("double".equals(value)) {
+ clz = double.class;
+ }
+ if ("boolean".equals(value)) {
+ clz = boolean.class;
+ }
+ if ("char".equals(value)) {
+ clz = char.class;
+ }
+ return clz;
+ }
public static Object read(String value, Class type) {
Object ret = value;
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Thu Mar 22 20:27:50 2007
@@ -89,18 +89,18 @@
}
public ClientImpl(URL wsdlUrl) {
- this(BusFactory.getDefaultBus(), wsdlUrl, null);
+ this(BusFactory.getDefaultBus(), wsdlUrl, null, null);
}
public ClientImpl(URL wsdlUrl, QName port) {
- this(BusFactory.getDefaultBus(), wsdlUrl, port);
+ this(BusFactory.getDefaultBus(), wsdlUrl, null, port);
}
- public ClientImpl(Bus bus, URL wsdlUrl, QName port) {
+ public ClientImpl(Bus bus, URL wsdlUrl, QName service, QName port) {
this.bus = bus;
- WSDLServiceFactory sf = (port == null)
- ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, port));
+ WSDLServiceFactory sf = (service == null)
+ ? (new WSDLServiceFactory(bus, wsdlUrl)) : (new WSDLServiceFactory(bus, wsdlUrl, service));
Service svc = sf.create();
EndpointInfo epfo = findEndpoint(svc.getServiceInfo(), port);
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java Thu Mar 22 20:27:50 2007
@@ -22,6 +22,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collection;
@@ -52,6 +53,7 @@
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientImpl;
+import org.apache.cxf.helpers.FileUtils;
import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.resource.URIResolver;
import org.apache.cxf.service.Service;
@@ -61,6 +63,7 @@
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.types.DirSet;
+import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
/**
@@ -129,18 +132,18 @@
return createClient(wsdlUrl, null, classLoader, null);
}
- public Client createClient(String wsdlUrl, QName wsdlEndpoint) {
- return createClient(wsdlUrl, wsdlEndpoint, null);
+ public Client createClient(String wsdlUrl, QName service) {
+ return createClient(wsdlUrl, service, null);
}
- public Client createClient(String wsdlUrl, QName wsdlEndpoint, QName port) {
- return createClient(wsdlUrl, wsdlEndpoint, Thread.currentThread().getContextClassLoader(), port);
+ public Client createClient(String wsdlUrl, QName service, QName port) {
+ return createClient(wsdlUrl, service, Thread.currentThread().getContextClassLoader(), port);
}
- public Client createClient(String wsdlUrl, QName wsdlEndpoint, ClassLoader classLoader, QName port) {
+ public Client createClient(String wsdlUrl, QName service, ClassLoader classLoader, QName port) {
URL u = composeUrl(wsdlUrl);
- ClientImpl client = new ClientImpl(bus, u, port);
+ ClientImpl client = new ClientImpl(bus, u, service, port);
Service svc = client.getEndpoint().getService();
Collection<SchemaInfo> schemas = svc.getServiceInfo().getSchemas();
@@ -194,7 +197,7 @@
if (!classes.mkdir()) {
throw new IllegalStateException("Unable to create working directory " + src.getPath());
}
- src.deleteOnExit();
+
Project project = new Project();
project.setBaseDir(new File(tmpdir));
@@ -202,6 +205,12 @@
Javac javac = new Javac();
javac.setProject(project);
+ Path classPath = new Path(project);
+
+ setupClasspath(classPath, classLoader);
+ //TODO need to check the tools.jar in the ClassPath and Check for IBM JDK
+ javac.setClasspath(classPath);
+
Path srcPath = new Path(project);
DirSet dirSet = new DirSet();
dirSet.setFile(src);
@@ -209,8 +218,11 @@
javac.setSrcdir(srcPath);
javac.setDestdir(classes);
javac.setTarget("1.5");
+ //javac.setVerbose(true);
javac.execute();
-
+
+ //delete the src dir
+ FileUtils.removeDir(src);
URLClassLoader cl;
try {
cl = new URLClassLoader(new URL[] {classes.toURI().toURL()}, classLoader);
@@ -239,8 +251,42 @@
TypeClassInitializer visitor = new TypeClassInitializer(svcfo, intermediateModel);
visitor.walk();
-
+ // delete the classes files
+ FileUtils.removeDir(classes);
return client;
+ }
+
+ static void setupClasspath(Path classPath, ClassLoader classLoader) {
+ ClassLoader scl = ClassLoader.getSystemClassLoader();
+ ClassLoader tcl = classLoader;
+ do {
+ if (tcl instanceof URLClassLoader) {
+ URL[] urls = ((URLClassLoader)tcl).getURLs();
+ for (URL url : urls) {
+ if (url.getProtocol().startsWith("file")) {
+ try {
+ File file = new File(url.toURI().getPath());
+ if (file.isDirectory()) {
+ DirSet ds = new DirSet();
+ ds.setFile(file);
+ classPath.addDirset(ds);
+ } else {
+ FileSet fs = new FileSet();
+ fs.setFile(file);
+ classPath.addFileset(fs);
+ }
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ tcl = tcl.getParent();
+ if (null == tcl) {
+ break;
+ }
+ } while(!tcl.equals(scl));
}
private URL composeUrl(String s) {
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java Thu Mar 22 20:27:50 2007
@@ -22,12 +22,14 @@
import javax.xml.namespace.QName;
+import com.sun.codemodel.JType;
import com.sun.tools.xjc.api.Mapping;
import com.sun.tools.xjc.api.S2JJAXBModel;
import com.sun.tools.xjc.api.TypeAndAnnotation;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.util.PrimitiveUtils;
import org.apache.cxf.service.ServiceModelVisitor;
import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.MessagePartInfo;
@@ -59,26 +61,34 @@
}
Mapping mapping = model.get(name);
- String clsName = null;
+ //String clsName = null;
+ JType jType = null;
if (mapping != null) {
- clsName = mapping.getType().getTypeClass().fullName();
+
+ jType = mapping.getType().getTypeClass();
+
}
- if (clsName == null) {
- TypeAndAnnotation javaType = model.getJavaType(part.getTypeQName());
-
- if (javaType != null) {
- clsName = javaType.getTypeClass().fullName();
+ if (jType == null) {
+ TypeAndAnnotation typeAndAnnotation = model.getJavaType(part.getTypeQName());
+ if (typeAndAnnotation != null) {
+ jType = typeAndAnnotation.getTypeClass();
}
}
- if (clsName == null) {
+ if (jType == null) {
throw new ServiceConstructionException(new Message("NO_JAXB_CLASS", LOG, name));
}
Class cls;
+
+ //JClass jclass;
try {
- cls = ClassLoaderUtils.loadClass(clsName, getClass());
+ if (!jType.isPrimitive()) {
+ cls = ClassLoaderUtils.loadClass(jType.fullName(), getClass());
+ } else {
+ cls = PrimitiveUtils.getClass(jType.fullName());
+ }
} catch (ClassNotFoundException e) {
throw new ServiceConstructionException(e);
}
Modified: incubator/cxf/trunk/systests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/pom.xml?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/systests/pom.xml (original)
+++ incubator/cxf/trunk/systests/pom.xml Thu Mar 22 20:27:50 2007
@@ -195,6 +195,20 @@
</dependency>
<dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>sun.jdk</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.5.0</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+
+ <dependency>
<groupId>rhino</groupId>
<artifactId>js</artifactId>
<version>1.6R5</version>
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?view=diff&rev=521566&r1=521565&r2=521566
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java Thu Mar 22 20:27:50 2007
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.HttpURLConnection;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
@@ -44,6 +45,8 @@
//import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.Soap11;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
//import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.helpers.XPathUtils;
@@ -699,6 +702,32 @@
assertNotNull("no response received from service", reply);
assertEquals("Bonjour", reply);
+ }
+
+ @Test
+ public void testDynamicClientFactory() {
+ URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
+ assertNotNull(wsdl);
+ String wsdlUrl = null;
+ try {
+ wsdlUrl = wsdl.toURI().toString();
+ } catch (URISyntaxException e) {
+ fail("Can't get the hello_world.wsdl url");
+ e.printStackTrace();
+ }
+ try {
+ //TODO test fault exceptions
+ DynamicClientFactory dcf = DynamicClientFactory.newInstance();
+ Client client = dcf.createClient(wsdlUrl, serviceName, portName);
+ client.invoke("greetMe", "test");
+ Object[] result = client.invoke("sayHi");
+ assertNotNull("no response received from service", result);
+ assertEquals("Bonjour", result[0]);
+ } catch (Exception e) {
+ fail("There is some excpetion happened ");
+ e.printStackTrace();
+ }
+
}
Re: svn commit: r521566 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/
rt/core/src/main/java/org/apache/cxf/endpoint/ rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/
systests/ systests/src/test/java/or...
Posted by Willem Jiang <ni...@iona.com>.
Hi Dan
I am Working on it with forking a Javac process for compiling.
Willem.
Daniel Kulp wrote:
>On Thursday 22 March 2007 23:27, ningjiang@apache.org wrote:
>
>
>>+
>>+ <dependency>
>>+ <groupId>sun.jdk</groupId>
>>+ <artifactId>tools</artifactId>
>>+ <version>1.5.0</version>
>>+ <scope>system</scope>
>>+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
>>+ </dependency>
>>
>>
>
>This will break the build on Mac. PLEASE don't do this. I'm going to
>revert this.
>
>
>
Re: svn commit: r521566 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/common/util/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/ systests/ systests/src/test/java/or...
Posted by Daniel Kulp <dk...@apache.org>.
On Thursday 22 March 2007 23:27, ningjiang@apache.org wrote:
> +
> + <dependency>
> + <groupId>sun.jdk</groupId>
> + <artifactId>tools</artifactId>
> + <version>1.5.0</version>
> + <scope>system</scope>
> + <systemPath>${java.home}/../lib/tools.jar</systemPath>
> + </dependency>
This will break the build on Mac. PLEASE don't do this. I'm going to
revert this.
--
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727 C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog