aspose file tools*
The moose likes Web Services and the fly likes Get java.util.List from webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Get java.util.List from webservice" Watch "Get java.util.List from webservice" New topic
Author

Get java.util.List from webservice

A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
I am using axis2 / webservice using Eclipse IDE. My webservice method returns a List (java.util).

When my client is calling the webservice method I am getting following error:

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Any type element type has not been given



Then I checked the WSDL of webservice and I found that for the response I am seeking the following:

<xs:element name="getDocumentClassificationResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
</xs:element>


I am pretty sure it has something to do with this. Could you please help how I am get List or any other java Collection as return from my webservice method.

Also, the only way I can access the WSDL is through web browser by typing:
http://localhost:8080/TestWebService3/services/Testing?wsdl

I could not find any WSDL file in my project directory. If I have to edit the WSDL how can I do that.


Any help is appreciated.

Thanks a bunch.

SCJP 5.0
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Standard SOAP doesn't know about List or any other collection class and there is no reason to. What you want is to return an array.

Fortunately the toArray() method makes it easy for a method to return an array.

Bill


Java Resources at www.wbrogden.com
A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
Thanks Bill.

I tried to make Array from list.toArray() which return array of objects (Object[]).

Actually I have to return Array of custom objects.

But when I am returning Object[], I get the error.

My WSDL shows for
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="xs:anyType" />

How can I get Array of custom objects.

Thanks.
cnivas redy
Greenhorn

Joined: Apr 19, 2008
Posts: 17
suppose if you have a list of persons :: List<Persons> list; and want to convert this to Persons array.


your method signature will look like

public Persons[] Methodname(Query Param){

List<Persons> list (your list object)
Persons [] sr = new Persons[list.size()];
list.toArray(sr);

}

if you can provide the exception details that will help to provide more information.
A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
Redy, Thanks. I got that.

My issue is I have to send the array of objects of custom class. Apart of literal poperties of that custom class, there is a 3rd party API instance as well.




I want to send the array of objects of DAO class. And when I try to do that I get following error:

Any suggestions. ??

Thanks.

java.lang.NullPointerException
org.apache.axiom.om.OMException: java.lang.NullPointerException
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:260)
at org.apache.axiom.om.impl.llom.OMNodeImpl.build(OMNodeImpl.java:335)
at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:737)
at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:706)
at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:124)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:297)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:213)
at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
at org.apache.axis2.rpc.receivers.RPCUtil.processResponseAsDocLitWrapped(RPCUtil.java:381)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:138)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at org.apache.axis2.databinding.typemapping.SimpleTypeMapper.isSimpleType(SimpleTypeMapper.java:202)
at org.apache.axis2.databinding.utils.BeanUtil.getPropertyQnameList(BeanUtil.java:141)
at org.apache.axis2.databinding.utils.BeanUtil.getPullParser(BeanUtil.java:67)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.processProperties(ADBXMLStreamReaderImpl.java:998)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.next(ADBXMLStreamReaderImpl.java:835)
at org.apache.axis2.databinding.utils.reader.WrappingXMLStreamReader.next(WrappingXMLStreamReader.java:49)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.next(ADBXMLStreamReaderImpl.java:857)
at org.apache.axis2.util.StreamWrapper.next(StreamWrapper.java:71)
at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:60)
at org.apache.axiom.om.impl.builder.SafeXMLStreamReader.next(SafeXMLStreamReader.java:183)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:597)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
... 28 more
[ERROR] java.lang.NullPointerException
org.apache.axis2.AxisFault: java.lang.NullPointerException
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:161)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.axiom.om.OMException: java.lang.NullPointerException
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:260)
at org.apache.axiom.om.impl.llom.OMNodeImpl.build(OMNodeImpl.java:335)
at org.apache.axiom.om.impl.llom.OMElementImpl.build(OMElementImpl.java:737)
at org.apache.axiom.om.impl.llom.OMElementImpl.detach(OMElementImpl.java:706)
at org.apache.axiom.om.impl.llom.OMNodeImpl.setParent(OMNodeImpl.java:124)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:297)
at org.apache.axiom.om.impl.llom.OMElementImpl.addChild(OMElementImpl.java:213)
at org.apache.axiom.soap.impl.llom.SOAPBodyImpl.addChild(SOAPBodyImpl.java:231)
at org.apache.axis2.rpc.receivers.RPCUtil.processResponseAsDocLitWrapped(RPCUtil.java:381)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:138)
... 19 more
Caused by: java.lang.NullPointerException
at org.apache.axis2.databinding.typemapping.SimpleTypeMapper.isSimpleType(SimpleTypeMapper.java:202)
at org.apache.axis2.databinding.utils.BeanUtil.getPropertyQnameList(BeanUtil.java:141)
at org.apache.axis2.databinding.utils.BeanUtil.getPullParser(BeanUtil.java:67)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.processProperties(ADBXMLStreamReaderImpl.java:998)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.next(ADBXMLStreamReaderImpl.java:835)
at org.apache.axis2.databinding.utils.reader.WrappingXMLStreamReader.next(WrappingXMLStreamReader.java:49)
at org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl.next(ADBXMLStreamReaderImpl.java:857)
at org.apache.axis2.util.StreamWrapper.next(StreamWrapper.java:71)
at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:60)
at org.apache.axiom.om.impl.builder.SafeXMLStreamReader.next(SafeXMLStreamReader.java:183)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:597)
at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:172)
... 28 more
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
My issue is I have to send the array of objects of custom class.


Standard SOAP does NOT know about Java objects, it only knows about variables such as strings, numbers, etc.

If you really need to send Java objects, you could serialize them to an object stream and send the resulting binary as a SOAP attachment. See SAAJ - the SOAP with Attachments API for Java. This of course would require that your client side have access to the 3rd party library as well as your own custom class library.

Is there some particular reason that SOAP is required at all?

Bill


A Thakur
Greenhorn

Joined: Apr 06, 2010
Posts: 20
Bill,

Thanks.

SOAP is not a requirement. I have flexibility to use any web/app server /SOAP. But only requirement is to pass 3rd party API object back to client. and unfortunately that 3rd object is not a serialized object .

Adding more to the mess, I cannot read all properties of 3rd party object on server and then send them to client as it adds significant amount of delay before client receives a response.

So I am exploring different options how I can achieve that.

If you have any suggestions, please let me know. I'll really appreciated.
Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
But only requirement is to pass 3rd party API object back to client. and unfortunately that 3rd object is not a serialized object.


Well, that is an impossible requirement - time to find a new architecture.

Why does your server have one of these 3rd party classes in the first place? Why does the client side need these 3rd party objects?

I cannot read all properties of 3rd party object on server and then send them to client as it adds significant amount of delay before client receives a response.


I find it really hard to believe that extracting values you have in an in-memory object is slow compared to the network connections.

What sort of application is the client side using to make the request?

Bill
 
 
subject: Get java.util.List from webservice
 
Similar Threads
Schema help
Support string array in wsdl
Creating a JMS TextMessage From XML
Axis2 POJO web service - wsdl generating xs:anyType
Automatically gen. code from WSDL results in XML with same tag for array and array elements