axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ramaswamy, Muthu" <mramasw...@gers.com>
Subject Help with List De-serializer problem.
Date Sun, 17 Nov 2002 22:21:20 GMT
Hi All-

When the List elements are referenced, I get the ClassCastException.

Overview
=======
Client calls the echoBean method that takes a simple java bean containing
list as parameter. 
The echoBean methods then prints the content of the java bean.
When the method refers the List element, encounters ClassCastException.

The method works when I execute from a a java client.

Following are the sample codes related to service, 2 of the java beans, axis
client rpc call and wsdd entry.

(1) SimpleTest Service:
=================
package samples.userguide.myexample5;

import java.util.ArrayList;
import java.util.List;

public class SimpleTest {

  public SimpleTest() {
  }

  public SimpleTestBean getBean()
  {
     SimpleTestBean myBean = new SimpleTestBean();
     myBean.setPhones(makeBeanList());
     return myBean;
  }

  public void echoBean(SimpleTestBean stb)
  {
     System.out.println("name is" + stb.getName());  //prints okay
     System.out.println("place is" + stb.getPlace()); //prints okay
     List myPhoneList = stb.getPhones();

     for (int i=0; i<myPhoneList.size(); i++)
     {
        SimplePhoneBean spb = (SimplePhoneBean) myPhoneList.get(i);
//Throws ClassCastException ?????
        System.out.println("Printing Phone List");
        System.out.println(spb.getPhoneType() + ":" + spb.getPhoneNum());
     }

  }

  private ArrayList makeBeanList()
  {
     ArrayList myArr = new ArrayList();
     myArr.add(new SimplePhoneBean("Home", "123 456 7890"));
     myArr.add(new SimplePhoneBean("Work", "789 012 3456"));
     myArr.add(new SimplePhoneBean("Cell", "345 012 3456"));
     return myArr;
  }

  public static void main(String[] args) {
    SimpleTest simpleTest1 = new SimpleTest();

    SimpleTestBean stb = simpleTest1.getBean();
    stb.setPhones(simpleTest1.makeBeanList());
    simpleTest1.echoBean(stb);
  }

}

(2) SimpleTextBean java bean code
==========================
package samples.userguide.myexample5;

import java.util.ArrayList;
import java.util.List;

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) SimplePhoneBean java bean code
===========================
package samples.userguide.myexample5;

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;
  }
}

(4) WSDD file
==========
<service name="SimpleTest" provider="java:RPC">
    <parameter name="sendMultiRefs" value="false"/>
    <parameter name="sendXsiTypes" value="false"/>
    <parameter name="className"
value="samples.userguide.myexample5.SimpleTest"/>
    <parameter name="allowedMethods" value="*"/>
    <beanMapping
languageSpecificType="java:samples.userguide.myexample5.SimplePhoneBean"
qname="ns1:SimplePhoneBean" xmlns:ns1="urn:SimpleTest"/>
    <beanMapping
languageSpecificType="java:samples.userguide.myexample5.SimpleTestBean"
qname="ns2:SimpleTestBean" xmlns:ns2="urn:SimpleTest"/>
 </service>

(5) Axis Client rpc call
=================
<?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>

(6) Error Stack
===========
java.lang.ClassCastException:
weblogic.apache.xerces.dom.DeferredElementNSImpl
java.lang.ClassCastException:
weblogic.apache.xerces.dom.DeferredElementNSImpl
        at
samples.userguide.myexample5.SimpleTest.echoBean(SimpleTest.java:42)
        at java.lang.reflect.Method.invoke(Native Method)
        at
org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.
ava:308)


Any help is grealty appreciated.

Thanks.,

-Muthu

Mime
View raw message