Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

any element and jax-ws  RSS feed

 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a web service with a predefined wsdl. Here's the part of the wsdl definition:
<s:element name="Send">
<s:complexType>
<s:sequence>
<s:element maxOccurs="1" minOccurs="1" name="Transmission">
<s:complexType>
<s:sequence>
<s:any />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
note the "any" element. I got the host up and running and I wrote a client against it for testing purposes. here's some client code:

Send.Transmission trans = new org.streamlinedsalestax.efile.Send.Transmission();
JAXBElement<String> element = new JAXBElement<String>(new QName("SSTSimplifiedReturnTransmission"), String.class, myTestString);
trans.setAny(element);
System.out.println("trans.getAny = " + ((JAXBElement) trans.getAny()).getValue());
java.lang.Object result = port.send(trans);

myTestString is just an xml String that actually validates against a detached schema (xsd). So I know that myTestString is good xml. I also print the xml out to the console right before I invoke the host and it looks great.
The thing is, by the time I get to my host, the class seems to have been altered somehow. I've looked all over for code examples that handle marshaling an "any" element in the client and then in the host unmarshaling into an object. But I've had no luck. Here's some code in my host.

log.debug("tranmisssion class = " + transmission.getAny().getClass().getName());
log.debug("transmission getAny casted = " + ((JAXBElement)transmission.getAny()).getValue().toString());
log.debug("transmission.getAny = " + transmission.getAny().toString() );

what I get in my log is this:
2010-02-24 16:27:09,373 DEBUG [streamline.efile.EFileServiceSoap] transmission = wsdlgenerated.org.streamlinedsalestax.efile.Send$Transmission@4c230
2010-02-24 16:27:09,373 DEBUG [streamline.efile.EFileServiceSoap] tranmisssion class = com.sun.org.apache.xerces.internal.dom.ElementNSImpl

what I get in my console output is this:
Exception is = javax.xml.ws.soap.SOAPFaultException: com.sun.org.apache.xerces.internal.dom.ElementNSImpl cannot be cast to javax.xml.bind.JAXBElement

It's dying on the second debug statement in the host. But How am I supposed to pull the data from the any element? I thought it would be the same as the client statement that prints out the value.

Please Help!
 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin Eddy wrote:

I've looked all over for code examples that handle marshaling an "any" element in the client and then in the host unmarshaling into an object. But I've had no luck.

Please Help!



What I really meant there was how to use the setAny() method in the client, and then in the host how do I use the getAny() method. From what I've read jaxws maps the any element to a java.util.object. Is that correct? Am I misunderstanding something?
 
Kevin Eddy
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh. I figured it out. Finally. whew. Apparently, I had read something that was wrong or misunderstood whatever it was that I read. I guess jax-ws/jaxb unmarshals the any element into the following class type.
com.sun.org.apache.xerces.internal.dom.ElementNSImpl
That implements the Node interface. So I put the following in my host:
final Node node = (Node) transmission.getAny()
Interestingly enough, that actually allows me to utilize xmlBean generated objects by passing the node to the Factory.parse(node) method.
This will make for a good blog somewhere.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!