This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Services and the fly likes Unmarshalling soap and ElementNSImpl Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Unmarshalling soap and ElementNSImpl" Watch "Unmarshalling soap and ElementNSImpl" New topic
Author

Unmarshalling soap and ElementNSImpl

Nadia Kunkov
Greenhorn

Joined: Dec 03, 2004
Posts: 7
Hello,
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,
Nadia
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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?


The Best way to predict your future is to create it - Every great individual common man
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

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 >
<sampleKey1>301441</sampleKey1>
<sampleKey1>02840005842</sampleKey1>
<sampleKey1>299894</sampleKey1>
<sampleKey2>02840000717</sampleKey2>
<sampleKey2>02840000026</sampleKey2>
<sampleKey3>300102</sampleKey3>
<sampleKey3>02840004922</sampleKey3>
<sampleKey3>301733</sampleKey3>
</anySampleObject >
</AnySampleObject >


Any help will be highly appreciated.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Unmarshalling soap and ElementNSImpl