axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhou Jian Han" <z...@ariodata.com>
Subject RE: Does Axis support polymorphism (dynamic send back the derived class)
Date Thu, 21 Oct 2004 19:07:35 GMT
Hi Christophe,
According to your suggestion, I took out the inherited fileds. and I
checked my PolymorphStub.java, it does include both Shape and Square,
see below:

public PolymorphStub(javax.xml.rpc.Service service) throws
org.apache.axis.AxisFault {
        if (service == null) {
            super.service = new org.apache.axis.client.Service();
        } else {
            super.service = service;
        }
            java.lang.Class cls;
            javax.xml.namespace.QName qName;
            java.lang.Class beansf =
org.apache.axis.encoding.ser.BeanSerializerFactory.class;
            java.lang.Class beandf =
org.apache.axis.encoding.ser.BeanDeserializerFactory.class;
            java.lang.Class enumsf =
org.apache.axis.encoding.ser.EnumSerializerFactory.class;
            java.lang.Class enumdf =
org.apache.axis.encoding.ser.EnumDeserializerFactory.class;
            java.lang.Class arraysf =
org.apache.axis.encoding.ser.ArraySerializerFactory.class;
            java.lang.Class arraydf =
org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;
            java.lang.Class simplesf =
org.apache.axis.encoding.ser.SimpleSerializerFactory.class;
            java.lang.Class simpledf =
org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;
            qName = new javax.xml.namespace.QName("urn:copy", "Shape");
            cachedSerQNames.add(qName);
            cls = copy.Shape.class;
            cachedSerClasses.add(cls);
            cachedSerFactories.add(beansf);
            cachedDeserFactories.add(beandf);

            qName = new javax.xml.namespace.QName("urn:copy", "Square");
            cachedSerQNames.add(qName);
            cls = copy.Square.class;
            cachedSerClasses.add(cls);
            cachedSerFactories.add(beansf);
            cachedDeserFactories.add(beandf);

    }

But when I run it, it still throw following:
SEVERE: Exception:
org.xml.sax.SAXException: Invalid element in copy.Shape - size
        at
org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeseri
alizer.java:260)
        at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:963)
        at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:198)
        at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java: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)
        at copy.PolymorphStub.getPoly(PolymorphStub.java:143)
        at copy.Tester.main(Tester.java:18)
Exception in thread "main" AxisFault
 ...

I saw your first reply mail, you have abstract="true", so I add this to
.wsdl, see below:
<complexType abstract="true" name="Shape">
   <sequence>
     <element name="name" type="xsd:string" minOccurs="0" maxOccurs="1"
nillable="true"/>
     <element name="sides" type="xsd:int" minOccurs="1" maxOccurs="1"/>
   </sequence>
  </complexType>
  <complexType name="Square">
   <complexContent>
    <extension base="ns:Shape">
     <sequence>
     <element name="size" type="xsd:int" minOccurs="1" maxOccurs="1"/>
     </sequence>
    </extension>
   </complexContent>
  </complexType>

This time after I run it, it throws different exception:
SEVERE: Exception:
org.xml.sax.SAXException: Unable to create JavaBean of type copy.Shape.
Missing
 default constructor?  Error was: java.lang.InstantiationException.
        at
org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeseri
alizer.java:159)
        at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:976)
        at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:198)
        at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java: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)
        at copy.PolymorphStub.getPoly(PolymorphStub.java:143)
        at copy.Tester.main(Tester.java:18)
Exception in thread "main" AxisFault

I checked both Square.java and Shape.java, they do have default
constructor, any idea?
I don't know how to run tcpmonitor because every time my client open a
random port, and I have no idea  which port should I specify to
listening when using tcpmonitor, so I use different tools to get the
packet sending from the server, here are the sever reply xml:
HTTP/1.1 200 OK
Server: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 538
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2000/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2000/XMLSchema" xmlns:ns="urn:copy">
<SOAP-ENV:Body
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<ns:polytestResponse>
<out xsi:type="ns:Square">
<name>Cubicle</name>
<sides>4</sides>
<size>40</size>
</out>
</ns:polytestResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>


Do you have any idea, why the axis still try to build "Shape" object
instead of "Square"? and why it complain Missing default constructor at
second time?

Thanks,
Georgia

-----Original Message-----
From: Christophe Roudet [mailto:croudet@activia.net]
Sent: Thursday, October 21, 2004 11:07 AM
To: axis-user@ws.apache.org
Subject: RE: Does Axis support polymorphism (dynamic send back the
derived class)


I don't think you have to declare the inherited fields sides and size in
the
derived type Square.

Check if you have a serializer declared for Square in your generated
stub.

public XxxxxStub(javax.xml.rpc.Service service) throws
org.apache.axis.AxisFault {
     if (service == null) {
        super.service = new org.apache.axis.client.Service();
     } else {
        super.service = service;
     }
     ...
     qName = new javax.xml.namespace.QName("...", "Square");
     cachedSerQNames.add(qName);
     cls = xxx.Square.class;
     cachedSerClasses.add(cls);
     cachedSerFactories.add(beansf);
     cachedDeserFactories.add(beandf);
    ....
}


Then check with the tcpmonitor what was send back by the server.

Christophe




Mime
View raw message