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/17 22:13:45 UTC

RE: Server throws ClassCastException when List member is referenc ed.

Hi All-

Any help to resolve the issue is greatly appreciated. Currently the Axis
Client has got the following
parameters set to false:

service.getEngine().setOption(org.apache.axis.AxisEngine.PROP_DOMULTIREFS,
new Boolean(false));
service.getEngine().setOption(org.apache.axis.AxisEngine.PROP_SEND_XSI, new
Boolean(false));

Here is the code to SimplePhoneBean that I forget to attach.

public class SimplePhoneBean {

  private String phoneType;
  private String phoneNum;

  public SimplePhoneBean()
  {
  }

  public SimplePhoneBean(String phoneType, String phoneNum)
  {
     this.phoneType = phoneType;
     this.phoneNum  = phoneNum;
  }

  public void setPhoneType(String phoneType)
  {
     this.phoneType = phoneType;
  }

  public String getPhoneType()
  {
     return this.phoneType;
  }

  public void setPhoneNum(String phoneNum)
  {
     this.phoneNum = phoneNum;
  }

  public String getPhoneNum()
  {
     return this.phoneNum;
  }
}

Here is the stack trace output:
===============================
AxisFault
 faultCode: {http://xml.apache.org/axis/}Server.userException
 faultString: java.lang.ClassCastException:
weblogic.apache.xerces.dom.DeferredE
lementNSImpl
 faultActor: null
 faultDetail:
        stackTrace: java.lang.ClassCastException:
weblogic.apache.xerces.dom.Def
erredElementNSImpl
        at
samples.userguide.myexample5.SimpleTest.echoBean(SimpleTest.java:41)

Using reflection I tried to print the method and field names of the List,
and I get:
============================================================================
========
getting the fields
field Name is:static final long
weblogic.apache.xerces.dom.DeferredElementNSImpl
serialVersionUID
ield Name is:protected transient int
weblogic.apache.xerces.dom.DeferredElement
SImpl.fNodeIndex

getting the methods
Method Name is:protected final void
weblogic.apache.xerces.dom.DeferredElementNS
mpl.synchronizeData()
ethod Name is:protected final void
weblogic.apache.xerces.dom.DeferredElementNS
mpl.synchronizeChildren()


-----Original Message-----
From: Ramaswamy, Muthu [mailto:mramaswamy@gers.com]
Sent: Friday, November 15, 2002 7:25 PM
To: axis-user@xml.apache.org
Subject: 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