Hello. I'm having a problem with the bean-like class that is generated
from my wsdl file. First, I would like to offer some comparisons. I
created the following class:
public class MyResponse
private int[] data;
private java.util.Calendar date;
private int requestID;
public MyResponse() {
}
public int[] getData() {
return data;
}
public void setData(int[] data) {
this.data = data;
}
public java.util.Calendar getDate() {
return date;
}
public void setDate(java.util.Calendar date) {
this.date = date;
}
public int getRequestID() {
return requestID;
}
public void setRequestID(int requestID) {
this.requestID = requestID;
}
}
Inside of my deploy.wsdd, I have the following:
<isd:beanMapping qname="myNS:MyResponse" xmlns:myNS="urn:MyService"
languageSpecificType="java:com.test.MyResponse"/>
The following is what the WSDL looks like (when viewing through the web
browser):
<element name="requestResponse">
<complexType>
<sequence>
<element name="requestReturn" type="impl:MyResponse"/>
</sequence>
</complexType>
</element>
<complexType name="ArrayOf_xsd_int">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]"/>
</restriction>
</complexContent>
</complexType>
<complexType name="MyResponse">
<sequence>
<element name="data" type="impl:ArrayOf_xsd_int"/>
<element name="date" type="xsd:dateTime"/>
<element name="requestID" type="xsd:int"/>
</sequence>
</complexType>
When I run my client, I don't have any problems at all receiving the
int[]. Now, if I let Java2WSDL generate the WSDL, the same wsdl as
above is generated, but the following is generated for the bean class
MyResponse:
public class MyResponse implements java.io.Serializable {
private int[] data;
private java.util.Calendar date;
private int requestID;
public MyResponse() {
}
public int[] getData() {
return data;
}
public void setData(int[] data) {
this.data = data;
}
public java.util.Calendar getDate() {
return date;
}
public void setDate(java.util.Calendar date) {
this.date = date;
}
public int getRequestID() {
return requestID;
}
public void setRequestID(int requestID) {
this.requestID = requestID;
}
....
static {
typeDesc.setXmlType(new
javax.xml.namespace.QName("urn:myService.test.com", "MyResponse"));
org.apache.axis.description.ElementDesc elemField = new
org.apache.axis.description.ElementDesc();
elemField.setFieldName("data");
elemField.setXmlName(new javax.xml.namespace.QName("", "data"));
elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"));
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("date");
elemField.setXmlName(new javax.xml.namespace.QName("", "date"));
elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema",
"dateTime"));
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("requestID");
elemField.setXmlName(new javax.xml.namespace.QName("",
"requestID"));
elemField.setXmlType(new
javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"));
typeDesc.addFieldDesc(elemField);
}
The deploy that is generated does not have the bean mapping but has a
type mapping:
<typeMapping
xmlns:ns="urn:myService.test.com"
qname="ns:MyResponse"
type="java:com.test.MyResponse"
serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
encodingStyle=""
/>
<typeMapping
xmlns:ns="urn:myService.test.com"
qname="ns:ArrayOf_xsd_int"
type="java:int[]"
serializer="org.apache.axis.encoding.ser.ArraySerializerFactory"
deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory"
encodingStyle=""
/>
When I run the client code, I get the following exception:
- Could not convert java.lang.Integer to bean field 'data', type [I
- Exception:
java.lang.IllegalArgumentException: argument type mismatch
at
org.apache.axis.encoding.ser.BeanPropertyTarget.set(BeanPropertyTarget.j
ava:181)
at
org.apache.axis.encoding.DeserializerImpl.valueComplete(DeserializerImpl
.java:282)
at
org.apache.axis.encoding.DeserializerImpl.endElement(DeserializerImpl.ja
va:541)
at
org.apache.axis.encoding.DeserializationContextImpl.endElement(Deseriali
zationContextImpl.java:1015)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:
204)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.j
ava:722)
at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:233)
at
org.apache.axis.message.RPCElement.getParams(RPCElement.java:347)
at org.apache.axis.client.Call.invoke(Call.java:2272)
at org.apache.axis.client.Call.invoke(Call.java:2171)
at org.apache.axis.client.Call.invoke(Call.java:1691)
How do I properly return a bean object that contains a primitive array?
Why does WSDL2Java generate the bean implementing Serializable? I
didn't do this originally and everything worked? In the static
initializer that is generated in the bean class, the XML type for the
data field is specified as "int", not "int[]" or something like that.
If this has been answered previously, I apologize in advance. Also, I
have renamed some stuff to remove some company-proprietary code, but the
samples above should be decently complete. Thanks.