You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by jason <ja...@gmail.com> on 2010/09/17 10:14:23 UTC

ClassCastException while working with Lists

Hi, 

I've created a new service using the following WSDL file and the java2wsdl
tool of cxf: 

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloWorld" targetNamespace="http://www.tum.de/test"
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.tum.de/test"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
	<wsdl:types>
		<xsd:schema targetNamespace="http://www.tum.de/test">
			<xsd:complexType name="CtMessage">
				<xsd:sequence>
					<xsd:element name="x" type="xsd:int" />
					<xsd:element name="y" type="xsd:string" />
				</xsd:sequence>
			</xsd:complexType>

			<xsd:simpleType name="CtItems">
				<xsd:list itemType="xsd:integer" />
			</xsd:simpleType>

			<xsd:element name="Message" type="tns:CtMessage" />
			<xsd:element name="ItemCount" type="xsd:int" />
			<xsd:element name="Items" type="tns:CtItems" />

		</xsd:schema>
	</wsdl:types>

	<wsdl:message name="SayHelloResponse">
		<wsdl:part name="parameter" element="tns:Items">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="SayHelloRequest">
		<wsdl:part name="parameter" element="tns:Message">
		</wsdl:part>
	</wsdl:message>

	<wsdl:portType name="HelloServiceInterface">
		<wsdl:operation name="sayTest">
			<wsdl:input message="tns:SayHelloRequest">
			</wsdl:input>
			<wsdl:output message="tns:SayHelloResponse">
			</wsdl:output>
		</wsdl:operation>

	</wsdl:portType>

	<wsdl:binding name="SayHelloHTTP" type="tns:HelloServiceInterface">
		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="sayTest">
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="HelloService">
		<wsdl:port name="HelloEndpoint" binding="tns:SayHelloHTTP">
			<soap:address location="http://localhost:8080/services/TEST.asmx" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

The service implementation looks like this: 
@WebService(endpointInterface = "de.tum.test.HelloServiceInterface",
serviceName = "HelloTest")
public class Implementation implements HelloServiceInterface {

	@Override
	public BigInteger[] sayTest(CtMessage parameter) {

		System.out.println("Say Test");

		return new BigInteger[] {};
	}

}

Now if i call the sayTest method i get the following error: 
org.apache.cxf.interceptor.Fault: Marshalling Error: [Ljava.math.BigInteger;
cannot be cast to java.util.Collection
	at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:249)
	at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
	at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:111)
	at
org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:244)
	at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:78)
	at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:244)
	at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:110)
	at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:311)
	at
org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:275)
	at
org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
	at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:326)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)
	at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:930)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
	at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
	at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ClassCastException: [Ljava.math.BigInteger; cannot be
cast to java.util.Collection
	at
com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.iterator(Lister.java:265)
	at
com.sun.xml.bind.v2.runtime.reflect.ListTransducedAccessorImpl.print(ListTransducedAccessorImpl.java:107)
	at
com.sun.xml.bind.v2.runtime.reflect.DefaultTransducedAccessor.writeLeafElement(DefaultTransducedAccessor.java:65)
	at
com.sun.xml.bind.v2.runtime.property.ListElementProperty.serializeBody(ListElementProperty.java:111)
	at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:157)
	at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:189)
	at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:316)
	at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:323)
	at
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:72)
	at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
	at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
	at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
	at
javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
	at
org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:532)
	at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:222)
	... 21 more

Does anyone have an Idea whats going wrong here? 

Thanks
-- 
View this message in context: http://cxf.547215.n5.nabble.com/ClassCastException-while-working-with-Lists-tp2843423p2843423.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ClassCastException while working with Lists

Posted by jason <ja...@gmail.com>.
Hi,

here is the requested test case: 
http://cxf.547215.n5.nabble.com/file/n2846274/cxftest.tar.gz cxftest.tar.gz 

Thanks,
Andreas
-- 
View this message in context: http://cxf.547215.n5.nabble.com/ClassCastException-while-working-with-Lists-tp2843423p2846274.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ClassCastException while working with Lists

Posted by jason <ja...@gmail.com>.
Hi, 

Thanks for your reply Dan!

I'm using Apache Axis 2.2.10. It seems like the error has something to do
with the following part of the WSDL file:  

<xsd:simpleType name="CtItems">
   <xsd:list itemType="xsd:integer" />
</xsd:simpleType>

The generated Java code uses BigInteger[] and seems fine but unfortunately
does not work. Now I am using a different approach like this (just want to
transfer a list of integers):

<xsd:complexeType name="CtItems">
   <xsd:sequence>
       <xsd:element name="value" type="xsd:integer" maxOccurs="unbound"
minOccurs="0" />
    </xsd:sequence>
</xsd:complexeType> 

I can send you a fully working test case in form of a HelloWorld program but
it will take until monday. 

-- 
View this message in context: http://cxf.547215.n5.nabble.com/ClassCastException-while-working-with-Lists-tp2843423p2844006.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: ClassCastException while working with Lists

Posted by Daniel Kulp <dk...@apache.org>.

You don't mention what version of CXF.

I just used the latest stuff and it seems to work fine.   I did a wsdl2java -
all  on the wsdl which did create that interface.   I started the server, ran 
the client, and got the empty BigInteger[] back.

Can you package up a fully non-working test case?

Dan



On Friday 17 September 2010 4:14:23 am jason wrote:
> Hi,
> 
> I've created a new service using the following WSDL file and the java2wsdl
> tool of cxf:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions name="HelloWorld"
> targetNamespace="http://www.tum.de/test"
> xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
> xmlns:tns="http://www.tum.de/test"
> 	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
> 	<wsdl:types>
> 		<xsd:schema targetNamespace="http://www.tum.de/test">
> 			<xsd:complexType name="CtMessage">
> 				<xsd:sequence>
> 					<xsd:element name="x" type="xsd:int" />
> 					<xsd:element name="y" type="xsd:string" />
> 				</xsd:sequence>
> 			</xsd:complexType>
> 
> 			<xsd:simpleType name="CtItems">
> 				<xsd:list itemType="xsd:integer" />
> 			</xsd:simpleType>
> 
> 			<xsd:element name="Message" type="tns:CtMessage" />
> 			<xsd:element name="ItemCount" type="xsd:int" />
> 			<xsd:element name="Items" type="tns:CtItems" />
> 
> 		</xsd:schema>
> 	</wsdl:types>
> 
> 	<wsdl:message name="SayHelloResponse">
> 		<wsdl:part name="parameter" element="tns:Items">
> 		</wsdl:part>
> 	</wsdl:message>
> 	<wsdl:message name="SayHelloRequest">
> 		<wsdl:part name="parameter" element="tns:Message">
> 		</wsdl:part>
> 	</wsdl:message>
> 
> 	<wsdl:portType name="HelloServiceInterface">
> 		<wsdl:operation name="sayTest">
> 			<wsdl:input message="tns:SayHelloRequest">
> 			</wsdl:input>
> 			<wsdl:output message="tns:SayHelloResponse">
> 			</wsdl:output>
> 		</wsdl:operation>
> 
> 	</wsdl:portType>
> 
> 	<wsdl:binding name="SayHelloHTTP" type="tns:HelloServiceInterface">
> 		<soap:binding style="document"
> 			transport="http://schemas.xmlsoap.org/soap/http" />
> 		<wsdl:operation name="sayTest">
> 			<wsdl:input>
> 				<soap:body use="literal" />
> 			</wsdl:input>
> 			<wsdl:output>
> 				<soap:body use="literal" />
> 			</wsdl:output>
> 		</wsdl:operation>
> 	</wsdl:binding>
> 	<wsdl:service name="HelloService">
> 		<wsdl:port name="HelloEndpoint" binding="tns:SayHelloHTTP">
> 			<soap:address location="http://localhost:8080/services/TEST.asmx" />
> 		</wsdl:port>
> 	</wsdl:service>
> </wsdl:definitions>
> 
> The service implementation looks like this:
> @WebService(endpointInterface = "de.tum.test.HelloServiceInterface",
> serviceName = "HelloTest")
> public class Implementation implements HelloServiceInterface {
> 
> 	@Override
> 	public BigInteger[] sayTest(CtMessage parameter) {
> 
> 		System.out.println("Say Test");
> 
> 		return new BigInteger[] {};
> 	}
> 
> }
> 
> Now if i call the sayTest method i get the following error:
> org.apache.cxf.interceptor.Fault: Marshalling Error:
> [Ljava.math.BigInteger; cannot be cast to java.util.Collection
> 	at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:249
> ) at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
> at
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(Abs
> tractOutDatabindingInterceptor.java:111) at
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutIntercep
> tor.java:68) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:244) at
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingC
> hainInterceptor.java:78) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:244) at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationO
> bserver.java:110) at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(Jet
> tyHTTPDestination.java:311) at
> org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTT
> PDestination.java:275) at
> org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandle
> r.java:70) at
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
> at
> org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCol
> lection.java:230) at
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
> at org.mortbay.jetty.Server.handle(Server.java:326)
> 	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:536)
> 	at
> org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java
> :930) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
> 	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
> 	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:405)
> 	at
> org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409
> ) at
> org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:58
> 2) Caused by: java.lang.ClassCastException: [Ljava.math.BigInteger; cannot
> be cast to java.util.Collection
> 	at
> com.sun.xml.bind.v2.runtime.reflect.Lister$CollectionLister.iterator(Lister
> .java:265) at
> com.sun.xml.bind.v2.runtime.reflect.ListTransducedAccessorImpl.print(ListTr
> ansducedAccessorImpl.java:107) at
> com.sun.xml.bind.v2.runtime.reflect.DefaultTransducedAccessor.writeLeafElem
> ent(DefaultTransducedAccessor.java:65) at
> com.sun.xml.bind.v2.runtime.property.ListElementProperty.serializeBody(List
> ElementProperty.java:111) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
> InfoImpl.java:157) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
> InfoImpl.java:189) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanIn
> foImpl.java:316) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
> foImpl.java:323) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
> foImpl.java:72) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:49
> 4) at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
> 	at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
> 	at
> javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImp
> l.java:75) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:
> 532) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:222
> ) ... 21 more
> 
> Does anyone have an Idea whats going wrong here?
> 
> Thanks

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog