wood burning stoves 2.0*
The moose likes Web Services and the fly likes How to return ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to return ArrayList" Watch "How to return ArrayList" New topic
Author

How to return ArrayList

Andy Barky
Greenhorn

Joined: Sep 17, 2005
Posts: 16
Hi Friends...

I am again stuck at the problem with web services.

I want to return an arraylist containing simple java beans that holds business data from webservice. I am able to populate the arrayList but while returning the arraylist JAXB throws exception like below:

2011-02-10 17:17:30,699 ERROR [STDERR] Feb 10, 2011 5:17:30 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate doGet
SEVERE: caught throwable
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class com.drw.services.vo.DbValsVO nor any of its super class is known to this context.]
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:322)
at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:142)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:108)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:258)
at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:320)
at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:93)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:454)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:244)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:135)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:129)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:160)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:75)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class com.drw.services.vo.DbValsVO nor any of its super class is known to this context.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:282)
at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:100)
at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:141)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:315)
... 31 more


I tried google for solutions but seems nothing is working, specially like @xmlseealso ...

Can anybody throw a light how it can be done?

Thanks guyz

- Andy


SCJP, SCWCD/OCPJWCD, OCUP-100,OCUP-200, OCPJBCD-In Process
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
SOAP does not have ArrayList as a standard data type -thats because there is absolutely no reason for it and every reason not to.

Think about it - what in the world does your client need an ArrayList for and what would a C# or Perl or etc etc client know about Java ArrayLists.

Instead send an array - a common SOAP type - there is a very fast conversion from ArrayList to an array.

Bill
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hi William,

I understand that, to promote interoperability between different environments, java collection objects are not recommended to be used. Here we have a good way of converting an ArrayList to Arrays, but how do we handle other complex collections like Maps, Trees, Sets etc. What is the recommended approach to be used, if the java based service has to return similar to Maps, Trees, Sets etc, which may or may not be understood by clients.


Regards
KumarRaja

Andy Barky
Greenhorn

Joined: Sep 17, 2005
Posts: 16
ok William,

I did get your point. May be there is no reason to send arraylist to client ..just because old legacy clients won't understand new datatypes etc etc..

It was definitely a good point to convert arraylist into array and send to WS client.

But there is one more solution which is more simple than this. I am not talking abt old legacy technologies here. Since I do not have any of them...

I created a custom object like a wrapper and passed this custom object to WS client. Now all they have to is, exact arraylist from this custom object and use arraylist for exacting data from value object that was embedded in that....isn't that a perfect solution to quickly get around the problem? May be this is not a hard core techie solution but it did solve my problem...

what ya say?

- AB

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
If I had to communicate complex objects that don't fit the regular SOAP types I would send them as attachments.

Nothing to be gained by trying to cram complex objects into SOAP if nobody will be able to create a SOAP client from your WSDL.

A RESTful approach would likely be easier anyway unless you need WS-* security/authentication/encryption etc.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to return ArrayList