Author: dkulp
Date: Wed Jul 25 13:56:59 2007
New Revision: 559602
URL: http://svn.apache.org/viewvc?view=rev&rev=559602
Log:
Walk jaxb types to find other types that may be in other packages to help with
various inheritance cases
Fix issue of complex types in a list not having their schema generated
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
(with props)
incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl (with
props)
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
incubator/cxf/trunk/testutils/pom.xml
incubator/cxf/trunk/tools/wsdlto/misc/src/test/java/org/apache/cxf/tools/misc/processor/WSDLToSoapProcessorTest.java
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
(original)
+++
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Wed Jul 25 13:56:59 2007
@@ -22,9 +22,11 @@
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Set;
import org.apache.cxf.common.util.PackageUtils;
@@ -38,10 +40,12 @@
class JAXBContextInitializer extends ServiceModelVisitor {
private Set<Class<?>> classes;
+ private Set<String> packages;
public JAXBContextInitializer(ServiceInfo serviceInfo, Set<Class<?>>
classes) {
super(serviceInfo);
this.classes = classes;
+ this.packages = new HashSet<String>();
}
@Override
@@ -87,6 +91,9 @@
Array.newInstance((Class)
pt.getActualTypeArguments()[0], 0).getClass();
clazz = arrayCls;
part.setTypeClass(clazz);
+ if (isFromWrapper) {
+ addType(clazz.getComponentType());
+ }
}
}
if (isFromWrapper && isList) {
@@ -134,19 +141,48 @@
// The object factory stuff doesn't work for enums
classes.add(cls);
}
- String name = PackageUtils.getPackageName(cls) +
".ObjectFactory";
- try {
- cls = Class.forName(name, false, cls.getClassLoader());
- if (cls != null) {
- classes.add(cls);
+ classes.add(cls);
+ walkReferences(cls);
+
+ String pname = PackageUtils.getPackageName(cls);
+ if (!packages.contains(pname)) {
+ packages.add(pname);
+ String name = pname + ".ObjectFactory";
+ try {
+ Class ocls = Class.forName(name, false,
cls.getClassLoader());
+ if (!classes.contains(ocls)) {
+ classes.add(ocls);
+ }
+ } catch (ClassNotFoundException ex) {
+ // cannot add factory, just add the class
}
- } catch (ClassNotFoundException ex) {
- // cannot add factory, just add the class
- classes.add(cls);
}
}
}
}
+ private void walkReferences(Class<?> cls) {
+ if (cls.getName().startsWith("java.")
+ || cls.getName().startsWith("javax.")) {
+ return;
+ }
+ //walk the public fields/methods to try and find all the classes.
JAXB will only load the
+ //EXACT classes in the fields/methods if they are in a different
package. Thus,
+ //subclasses won't be found and the xsi:type stuff won't work at all.
+ //We'll grab the public field/method types and then add the
ObjectFactory stuff
+ //as well as look for jaxb.index files in those packages.
+
+ Field fields[] = cls.getFields();
+ for (Field f : fields) {
+ addType(f.getGenericType());
+ }
+ Method methods[] = cls.getMethods();
+ for (Method m : methods) {
+ addType(m.getGenericReturnType());
+ for (Type t : m.getGenericParameterTypes()) {
+ addType(t);
+ }
+ }
+ }
}
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Wed Jul 25 13:56:59 2007
@@ -325,6 +325,12 @@
}
} catch (Exception e) {
//ignore
+ } finally {
+ try {
+ entry.getValue().close();
+ } catch (Exception e) {
+ //ignore
+ }
}
}
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerMiscTest.java
Wed Jul 25 13:56:59 2007
@@ -43,6 +43,12 @@
import org.apache.cxf.ordered_param_holder.ComplexStruct;
import org.apache.cxf.ordered_param_holder.OrderedParamHolder;
import org.apache.cxf.ordered_param_holder.OrderedParamHolder_Service;
+import org.apache.cxf.systest.jaxws.DocLitWrappedCodeFirstService.Foo;
+import org.apache.cxf.tests.inherit.Inherit;
+import org.apache.cxf.tests.inherit.InheritService;
+import org.apache.cxf.tests.inherit.objects.SubTypeA;
+import org.apache.cxf.tests.inherit.objects.SubTypeB;
+import org.apache.cxf.tests.inherit.types.ObjectInfo;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -237,6 +243,11 @@
assertEquals("e", e.value);
assertEquals("f", f.value);
assertEquals("g", g.value);
+
+ List<Foo> foos = port.listObjectOutput();
+ assertEquals(2, foos.size());
+ assertEquals("a", foos.get(0).getName());
+ assertEquals("b", foos.get(1).getName());
}
@Test
public void testRpcLitNoWsdl() throws Exception {
@@ -351,5 +362,22 @@
assertEquals("f", f.value);
assertEquals("g", g.value);
}
-
+
+ @Test
+ public void testInheritedTypesInOtherPackage() throws Exception {
+ InheritService serv = new InheritService();
+ Inherit port = serv.getInheritPort();
+ ObjectInfo obj = port.getObject(0);
+ assertNotNull(obj);
+ assertNotNull(obj.getBaseObject());
+ assertEquals("A", obj.getBaseObject().getName());
+ assertTrue(obj.getBaseObject() instanceof SubTypeA);
+
+ obj = port.getObject(1);
+ assertNotNull(obj);
+ assertNotNull(obj.getBaseObject());
+ assertEquals("B", obj.getBaseObject().getName());
+ assertTrue(obj.getBaseObject() instanceof SubTypeB);
+
+ }
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstService.java
Wed Jul 25 13:56:59 2007
@@ -65,4 +65,21 @@
@WebParam(mode = WebParam.Mode.OUT)
Holder<String> g);
+
+ @WebMethod
+ List<Foo> listObjectOutput();
+
+ static class Foo {
+ String name;
+
+ public Foo() {
+ }
+
+ public void setName(String n) {
+ name = n;
+ }
+ public String getName() {
+ return name;
+ }
+ }
}
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/DocLitWrappedCodeFirstServiceImpl.java
Wed Jul 25 13:56:59 2007
@@ -91,6 +91,14 @@
g.value = "g";
return ret;
}
+
+ public List<Foo> listObjectOutput() {
+ Foo a = new Foo();
+ a.setName("a");
+ Foo b = new Foo();
+ b.setName("b");
+ return Arrays.asList(a, b);
+ }
}
Added:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java?view=auto&rev=559602
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
(added)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
Wed Jul 25 13:56:59 2007
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxws;
+
+import org.apache.cxf.tests.inherit.Inherit;
+import org.apache.cxf.tests.inherit.objects.BaseType;
+import org.apache.cxf.tests.inherit.objects.SubTypeA;
+import org.apache.cxf.tests.inherit.objects.SubTypeB;
+import org.apache.cxf.tests.inherit.types.ObjectInfo;
+
+public class InheritImpl implements Inherit {
+
+ public ObjectInfo getObject(int type) {
+ ObjectInfo info = new ObjectInfo();
+ info.setType("Type: " + type);
+ BaseType ba = null;
+ switch (type) {
+ case 0:
+ ba = new SubTypeA();
+ ba.setName("A");
+ ((SubTypeA)ba).setAvalue("A");
+ break;
+ case 1:
+ ba = new SubTypeB();
+ ba.setName("B");
+ ((SubTypeB)ba).setBvalue("B");
+ break;
+ default:
+ }
+ info.setBaseObject(ba);
+ return info;
+ }
+
+}
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/InheritImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
(original)
+++
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ServerMisc.java
Wed Jul 25 13:56:59 2007
@@ -52,6 +52,9 @@
Object implementor5 = new RpcLitCodeFirstServiceImpl();
Endpoint.publish(RPCLIT_CODEFIRST_URL, implementor5);
+
+ Endpoint.publish("http://localhost:9000/InheritContext/InheritPort",
+ new InheritImpl());
}
public static void main(String[] args) {
Modified: incubator/cxf/trunk/testutils/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/pom.xml?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
--- incubator/cxf/trunk/testutils/pom.xml (original)
+++ incubator/cxf/trunk/testutils/pom.xml Wed Jul 25 13:56:59 2007
@@ -363,6 +363,9 @@
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/test_chars.wsdl</wsdl>
</wsdlOption>
+ <wsdlOption>
+
<wsdl>${basedir}/src/main/resources/wsdl/inherit.wsdl</wsdl>
+ </wsdlOption>
</wsdlOptions>
</configuration>
Added: incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl?view=auto&rev=559602
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl (added)
+++ incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl Wed Jul
25 13:56:59 2007
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://apache.org/cxf/tests/inherit"
+ xmlns:x1="http://apache.org/cxf/tests/inherit/types"
+ targetNamespace="http://apache.org/cxf/tests/inherit" name="Inherit">
+ <wsdl:types>
+ <schema targetNamespace="http://apache.org/cxf/tests/inherit/objects"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:x1="http://apache.org/cxf/tests/inherit/objects"
+ elementFormDefault="qualified">
+ <complexType name="BaseType">
+ <sequence>
+ <element name="name" type="string"/>
+ </sequence>
+ </complexType>
+ <complexType name="SubTypeA">
+ <complexContent>
+ <extension base="x1:BaseType">
+ <sequence>
+ <element name="avalue" type="string"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ <complexType name="SubTypeB">
+ <complexContent>
+ <extension base="x1:BaseType">
+ <sequence>
+ <element name="bvalue" type="string"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+ </schema>
+ <schema targetNamespace="http://apache.org/cxf/tests/inherit/types"
+ xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:x1="http://apache.org/cxf/tests/inherit/types"
+ xmlns:x2="http://apache.org/cxf/tests/inherit/objects"
+ elementFormDefault="qualified">
+ <complexType name="ObjectInfo">
+ <sequence>
+ <element name="baseObject" type="x2:BaseType"/>
+ <element name="type" type="string"/>
+ </sequence>
+ </complexType>
+ <element name="getObject">
+ <complexType>
+ <sequence>
+ <element name="type" type="int"/>
+ </sequence>
+ </complexType>
+ </element>
+ <element name="getObjectResponse">
+ <complexType>
+ <sequence>
+ <element name="return" type="x1:ObjectInfo"/>
+ </sequence>
+ </complexType>
+ </element>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="getObject">
+ <wsdl:part name="in" element="x1:getObject"/>
+ </wsdl:message>
+ <wsdl:message name="getObjectResponse">
+ <wsdl:part name="out" element="x1:getObjectResponse"/>
+ </wsdl:message>
+
+ <wsdl:portType name="Inherit">
+ <wsdl:operation name="getObject">
+ <wsdl:input name="getObjectRequest" message="tns:getObject"/>
+ <wsdl:output name="getObjectResponse"
message="tns:getObjectResponse"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="InheritSOAPBinding" type="tns:Inherit">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="getObject">
+ <soap:operation style="document"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+
+ <wsdl:service name="InheritService">
+ <wsdl:port name="InheritPort" binding="tns:InheritSOAPBinding">
+ <soap:address
location="http://localhost:9000/InheritContext/InheritPort"/>
+ </wsdl:port>
+ </wsdl:service>
+
+</wsdl:definitions>
+
Propchange: incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/testutils/src/main/resources/wsdl/inherit.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
incubator/cxf/trunk/tools/wsdlto/misc/src/test/java/org/apache/cxf/tools/misc/processor/WSDLToSoapProcessorTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/misc/src/test/java/org/apache/cxf/tools/misc/processor/WSDLToSoapProcessorTest.java?view=diff&rev=559602&r1=559601&r2=559602
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/misc/src/test/java/org/apache/cxf/tools/misc/processor/WSDLToSoapProcessorTest.java
(original)
+++
incubator/cxf/trunk/tools/wsdlto/misc/src/test/java/org/apache/cxf/tools/misc/processor/WSDLToSoapProcessorTest.java
Wed Jul 25 13:56:59 2007
@@ -374,8 +374,10 @@
processor.process();
fail("Do not catch expected tool exception for Part Reference
illegal!");
} catch (Exception e) {
+
if (!(e instanceof ToolException && e.toString()
- .indexOf("does not use type reference not confirm to RPC
style") >= 0)) {
+ .indexOf("does not use type reference (does not conform to RPC
style)") >= 0)) {
+
fail("Do not catch tool exception for Part Reference illegal, "
+ "catch other unexpected exception: " + e.getMessage());
}