• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

Unmarshalling soap and ElementNSImpl

Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm following a pre-defined WSDL (and xsd) to send and recive web service calls. The sending web service sends the object of type Any. I'm able to send it fine. When I receive the reply, we get a list of Any elements. Below is the code we use:

List<Object> list = academicRecordBatch.getBatchContent().getAny();
if (list != null && list.size() > 0) {
Log.debug("got : "+ list.get(0).getClass().getName());
K12StudentType k12StudentType = (K12StudentType) list.get(0); //error on this line

This produces the following error:
[java] 2011-05-10 09:52:53,707 DEBUG [com.mycompany.is.Test] main(line 42): Object returned: org.pesc.message.academicrecordbatch.v2_0.AcademicRecordBatch@483bead5
[java] java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to org.pesc.sector.academicrecord.v1_4.K12StudentType

Looks like what is returned is the list of ElementNSImpl. How can I extract my K12StudentType object from it?
I would appreciate any suggestion.
Thank you in advance,
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to re-iterate this question though original post is quite old but I am in similar situation where as I don't have any control on WSDL. It's been provided by third party.

I also don't have very tight control on change the CXF objects because it could be overridden by any developer next time if there is any update in WSDL and developer is creating stubs out of it. DO we have any other clear solution idea for this problem?
Shaan Shar
Ranch Hand
Posts: 1252
Spring Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I understand from Web Services.

Apache CXF(I am using Apache CXF) will unmarshal data it receives from Server(Service Provider) and convert it into already stubbed CXF Objects(from WSDL). Typically after that we transform these CXF objects into user defined objects to use it within our application. Now as originally problem has been depicted, since element type was "anyType", CXF objects(converted from WSDL) are by default java.lang.Object and in runtime(when I put my debugger on) it becomes instance of ElementNSImpl which I guess is from xerces.jar.

From the response, I can see that this tag can have multiple tags inside it and as of now, I am looking specifically 1 tag to use in my application. How to get to that tag in JAVA World, that's what my question is?

If my understanding is not correct, please let me know as I am newbie for Web Services.

+++++++++++++++++FURTHER UPDATE+++++++++++++++++++

After googling further, found following way to Read this object in String(though it's still not plain String, it's actually in XML format String) but still not getting any clear way to convert this String conversion into a hashtable with Key/Value pair. I am asking for Hashtable because as original problem depicts, it's "anyType" so I can't have pre-planned Java objects. Hashtable is the only way to get all tags under "Key" and value of those tags under "value" pair of hashtable.

Here is the snippet of WSDL defining this variable.

<xsd:element name="AnySampleObject" type="xsd:anyType" minOccurs="0" maxOccurs="1"/>

Here is the sysout for above code.

<?xml version="1.0" encoding="UTF-8"?>
<anySampleObject >
</anySampleObject >
</AnySampleObject >

Any help will be highly appreciated.
    Bookmark Topic Watch Topic
  • New Topic