Hi all,
I recently tried to get at work a Castor and Axis webservice, following
This article
http://www-106.ibm.com/developerworks/webservices/library/ws-castor
The schema for webservice was as following:
<xsd:element name="quote">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="symbol" type="xsd:string"/>
<xsd:element name="volume" type="xsd:integer"/>
<xsd:element name="lastTrade" type="lastTradeType"/>
<xsd:element name="change" type="changeType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="changeType">
<xsd:sequence>
<xsd:element name="dollar" type="xsd:float"/>
<xsd:element name="percent" type="xsd:float"/>
<xsd:element name="positive" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="lastTradeType">
<xsd:sequence>
<xsd:element name="price" type="xsd:float"/>
<xsd:element name="date" type="xsd:long"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="getStockQuote">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="symbol" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="getStockQuoteResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="quote" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
in castorbuilder.properties I have set the javaclassmapping property
to 'element'
after running Castor for generating classes, Castor generated a
'LastTrade' class and a 'LastTradeType' abstract class.
The Quote class has a 'setLastTrade' method, which accepts a LastTrade
class.
When I write following code on the server
Quote quote = new Quote();
quote.setVolume(9499999);
quote.setSymbol(getStockQuoteSymbol);
Change type = new Change();
type.setDollar(678F);
type.setPercent(300F);
type.setPositive(true);
quote.setChange(petype);
LastTrade lastTrade = new LastTrade();
lastTrade.setDate(new java.util.Date().getTime());
lastTrade.setPrice(678F);
quote.setLastTrade(lastTrade);
the server outputs
<quote xmlns="http://w3.ibm.com/schemas/services/2002/11/15/stockquote">
<symbol xmlns="">IBM</symbol>
<volume xmlns="">9499999</volume>
<lastTrade xmlns="">
<price>678.0</price>
<date>1093885918937</date>
</lastTrade>
<change xmlns="">
<dollar>678.0</dollar>
<percent>300.0</percent>
<positive>true</positive>
</change>
</quote>
but when I m about to marshal It on the client, I got following
exception :
org.xml.sax.SAXException: Unable to create JavaBean of type
com.ibm.w3.services.
stockquote.LastTradeType. Missing default constructor? Error was:
java.lang.In
stantiationException.
at
org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeseri
alizer.java:124)
at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:1014)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:159)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:1050)
at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:196)
at
org.apache.axis.message.RPCElement.getParams(RPCElement.java:310)
at org.apache.axis.client.Call.invoke(Call.java:2381)
at org.apache.axis.client.Call.invoke(Call.java:2280)
at org.apache.axis.client.Call.invoke(Call.java:1741)
at
com.ibm.w3.services.stockquote.StockQuoteSOAPBindingStub.getStockQuot
e(Unknown Source)
at StockQuoteClient.main(Unknown Source)
Exception in thread "main" AxisFault
faultCode:
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXException: Unable to create JavaBean of
type com.ib
m.w3.services.stockquote.LastTradeType. Missing default constructor?
Error was
: java.lang.InstantiationException.
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:org.xml.sax.SAXException: Unable
to create JavaBean of type
com.ibm.w3.services.stockquote.LastTradeType. Missi
ng default constructor? Error was: java.lang.InstantiationException.
at
org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeseri
alizer.java:124)
at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:1014)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:159)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:1050)
at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:196)
at
org.apache.axis.message.RPCElement.getParams(RPCElement.java:310)
at org.apache.axis.client.Call.invoke(Call.java:2381)
at org.apache.axis.client.Call.invoke(Call.java:2280)
at org.apache.axis.client.Call.invoke(Call.java:1741)
at
com.ibm.w3.services.stockquote.StockQuoteSOAPBindingStub.getStockQuot
e(Unknown Source)
at StockQuoteClient.main(Unknown Source)
org.xml.sax.SAXException: Unable to create JavaBean of type
com.ibm.w3.services.
stockquote.LastTradeType. Missing default constructor? Error was:
java.lang.In
stantiationException.
at org.apache.axis.AxisFault.makeFault(AxisFault.java:98)
at org.apache.axis.client.Call.invoke(Call.java:2384)
at org.apache.axis.client.Call.invoke(Call.java:2280)
at org.apache.axis.client.Call.invoke(Call.java:1741)
at
com.ibm.w3.services.stockquote.StockQuoteSOAPBindingStub.getStockQuot
e(Unknown Source)
at StockQuoteClient.main(Unknown Source)
Caused by: org.xml.sax.SAXException: Unable to create JavaBean of type
com.ibm.w
3.services.stockquote.LastTradeType. Missing default constructor?
Error was: j
ava.lang.InstantiationException.
at
org.apache.axis.encoding.ser.BeanDeserializer.startElement(BeanDeseri
alizer.java:124)
at
org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:1014)
at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.ja
va:159)
at
org.apache.axis.message.MessageElement.publishToHandler(MessageElemen
t.java:1050)
at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:196)
at
org.apache.axis.message.RPCElement.getParams(RPCElement.java:310)
at org.apache.axis.client.Call.invoke(Call.java:2381)
well, it looks to me that LastTradeType cannot be instantiated, being an
abstract class.
As far as I can see, the problem could be this part of the schema
<xsd:complexType>
<xsd:sequence>
<xsd:element name="symbol" type="xsd:string"/>
<xsd:element name="volume" type="xsd:integer"/>
<xsd:element name="lastTrade" type="lastTradeType"/>
<xsd:element name="change" type="changeType"/>
</xsd:sequence>
</xsd:complexType>
having seen examples, this looks to work if lastTradeType is a
simpleType and not a complex one..
can anyone help me in figuring out the problem?
Shall I replace the above code with this one instead ?
<xsd:complexType>
<xsd:sequence>
<xsd:element name="symbol" type="xsd:string"/>
<xsd:element name="volume" type="xsd:integer"/>
<xsd:element ref="lastTradeType"/>
<xsd:element ref="changeType" "/>
</xsd:sequence>
</xsd:complexType>
thanx in advance and regards
marco
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user