You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Ramaswamy, Muthu" <mr...@gers.com> on 2002/11/16 04:24:35 UTC
Server throws ClassCastException when List member is referenced.
Hi All-
I am able to return an object that contains List, from a service.
When I return the same object to the Server and then refer the objects in
the list, I get java.lang.ClassCastException.
The echoBean method takes the SimpleTestBean object as an argument. It then
prints the List members.
(1) Following is the RPC call issued by the Axis Client.
========================================
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<soapenv:Body>
<ns1:echoBean xmlns:ns1="SimpleTest">
<SimpleTestBean>
<name>Your Name</name>
<phones SOAP-ENC:arrayType="xsd:any[3]">
<item>
<phoneType>Home</phoneType>
<phoneNum>123 456 7890</phoneNum>
</item>
<item>
<phoneType>Work</phoneType>
<phoneNum>789 012 3456</phoneNum>
</item>
<item>
<phoneType>Cell</phoneType>
<phoneNum>345 012 3456</phoneNum>
</item>
</phones>
<place>Your Place</place>
</SimpleTestBean>
</ns1:echoBean>
</soapenv:Body>
</soapenv:Envelope>
(2) Here is the Code for SimpleTestBean.
=============================
public class SimpleTestBean {
private String name;
private String place;
private List phones;
public SimpleTestBean() {
name = "Your Name";
place = "Your Place";
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setPlace(String place)
{
this.place = place;
}
public String getPlace()
{
return this.place;
}
public List getPhones()
{
return this.phones;
}
public void setPhones(List phones)
{
this.phones = phones;
}
}
(3) Here is the code for the echoBean method in the SimpleTest service
====================================================
public void echoBean(SimpleTestBean stb)
{
System.out.println("name is" + stb.getName());
System.out.println("place is" + stb.getPlace());
List myPhoneList = stb.getPhones();
for (int i=0; i<myPhoneList.size(); i++)
{
SimplePhoneBean spb = (SimplePhoneBean) myPhoneList.get(i); //this
line throws the ClassCastException.
System.out.println("Printing Phone List");
System.out.println(spb.getPhoneType() + ":" + spb.getPhoneNum());
}
}
Question:
=======
I get the ClassCastException when I try to refer the List member.
When I tested the function from a Java client it works fine. Problem is
after de-serialization by Axis.
The myPhoneList.size() returns three, which is correct as I send three
arrays.
Problem is when I try to cast it to the SimplePhoneBean object, I get the
error.
Appreciate your input to solve my problem.
Thanks.,
-Muthu