Author: dkulp
Date: Tue Aug 28 11:23:46 2007
New Revision: 570517
URL: http://svn.apache.org/viewvc?rev=570517&view=rev
Log:
[CXF-925] Fix for issues with primitive arrays when using Wrapped/Doc/Lit code
first without wrapper types
Modified:
incubator/cxf/trunk/pom.xml
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.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
Modified: incubator/cxf/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/pom.xml?rev=570517&r1=570516&r2=570517&view=diff
==============================================================================
--- incubator/cxf/trunk/pom.xml (original)
+++ incubator/cxf/trunk/pom.xml Tue Aug 28 11:23:46 2007
@@ -50,7 +50,7 @@
<snapshotRepository>
<id>apache.snapshots</id>
<name>Apache SNAPSHOT Repository</name>
-
<url>scp://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+
<url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
</snapshotRepository>
<repository>
<id>apache.incubating</id>
Modified:
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=570517&r1=570516&r2=570517&view=diff
==============================================================================
---
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
(original)
+++
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
Tue Aug 28 11:23:46 2007
@@ -139,18 +139,21 @@
&& (mObj.getClass().isArray() || mObj instanceof List)
&& el.getMaxOccurs() != 1) {
//Have to handle this ourselves.... which really
sucks.... but what can we do?
- Object objArray[];
+ Object objArray;
if (mObj instanceof List) {
List l = (List)mObj;
objArray = l.toArray(new Object[l.size()]);
cls = null;
} else {
- objArray = (Object[])mObj;
- cls = cls.getComponentType();
+ objArray = mObj;
+ cls = objArray.getClass().getComponentType();
}
- for (Object o : objArray) {
+ int len = Array.getLength(objArray);
+ for (int x = 0; x < len; x++) {
+ Object o = Array.get(objArray, x);
writeObject(u, source,
- new JAXBElement(elName, cls == null ?
o.getClass() : cls , o));
+ new JAXBElement(elName, cls == null ?
o.getClass() : cls ,
+ o));
}
} else {
writeObject(u, source, new JAXBElement(elName, cls,
mObj));
@@ -253,14 +256,23 @@
} else if (part.getMessageInfo().getOperation().isUnwrapped()
&& el.getMaxOccurs() != 1) {
//must read ourselves....
- Collection<Object> ret = unmarshallArray(context, schema,
source,
+ List<Object> ret = unmarshallArray(context, schema, source,
elName,
clazz.getComponentType(),
au, createList(part));
- if (isList(part)) {
- return ret;
- }
- return
ret.toArray((Object[])java.lang.reflect.Array.newInstance(clazz.getComponentType(),
+ Object o = ret;
+ if (!isList(part)) {
+ if (clazz.getComponentType().isPrimitive()) {
+ o =
java.lang.reflect.Array.newInstance(clazz.getComponentType(),
+
ret.size());
+ for (int x = 0; x < ret.size(); x++) {
+ Array.set(o, x, ret.get(x));
+ }
+ } else {
+ o =
ret.toArray((Object[])Array.newInstance(clazz.getComponentType(),
ret.size()));
+ }
+ }
+ return o;
}
} else if (byte[].class == clazz
&& part != null
@@ -275,23 +287,23 @@
if (o != null
&& o.getClass().isArray()
&& isList(part)) {
- Collection<Object> ret = createList(part);
+ List<Object> ret = createList(part);
ret.addAll(Arrays.asList((Object[])o));
o = ret;
}
return o;
}
- private static Collection<Object> createList(MessagePartInfo part) {
+ private static List<Object> createList(MessagePartInfo part) {
Type genericType = (Type)part.getProperty("generic.type");
if (genericType instanceof ParameterizedType) {
Type tp2 = ((ParameterizedType)genericType).getRawType();
if (tp2 instanceof Class) {
Class<?> cls = (Class)tp2;
if (!cls.isInterface()
- && Collection.class.isAssignableFrom((Class<?>)cls)) {
+ && List.class.isAssignableFrom((Class<?>)cls)) {
try {
- return CastUtils.cast((Collection)cls.newInstance());
+ return CastUtils.cast((List)cls.newInstance());
} catch (Exception e) {
//ignore, just return an ArrayList
}
@@ -402,13 +414,13 @@
throw new IllegalArgumentException("Cannot get Class object from
unknown Type");
}
- public static Collection<Object> unmarshallArray(JAXBContext context,
+ public static List<Object> unmarshallArray(JAXBContext context,
Schema schema,
Object source,
QName elName,
Class<?> clazz,
AttachmentUnmarshaller au,
- Collection<Object> ret) {
+ List<Object> ret) {
try {
Unmarshaller u = createUnmarshaller(context, clazz);
u.setSchema(schema);
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?rev=570517&r1=570516&r2=570517&view=diff
==============================================================================
---
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
Tue Aug 28 11:23:46 2007
@@ -58,7 +58,7 @@
@BeforeClass
public static void startServers() throws Exception {
- assertTrue("server did not launch correctly",
launchServer(ServerMisc.class));
+ assertTrue("server did not launch correctly",
launchServer(ServerMisc.class, true));
}
@Test
@@ -258,6 +258,9 @@
assertEquals(2, foos2.get(0).length);
assertEquals(2, foos2.get(1).length);
+ int ints[] = port.echoIntArray(new int[] {1, 2 , 3});
+ assertEquals(3, ints.length);
+ assertEquals(1, ints[0]);
/* CXF-926 test case - this should work, but doesn't right now
try {
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?rev=570517&r1=570516&r2=570517&view=diff
==============================================================================
---
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
Tue Aug 28 11:23:46 2007
@@ -48,6 +48,9 @@
Vector<String> listOutput();
@WebMethod
+ int[] echoIntArray(int[] ar);
+
+ @WebMethod
String listInput(List<String> inputs);
@WebMethod
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?rev=570517&r1=570516&r2=570517&view=diff
==============================================================================
---
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
Tue Aug 28 11:23:46 2007
@@ -51,6 +51,11 @@
}
return buf.toString();
}
+
+ public int[] echoIntArray(int[] ar) {
+ return ar;
+ }
+
public String listInput(List<String> inputs) {
StringBuffer buf = new StringBuffer();