aspose file tools*
The moose likes Web Services and the fly likes Binding XML to Java from SOAP message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Binding XML to Java from SOAP message" Watch "Binding XML to Java from SOAP message" New topic
Author

Binding XML to Java from SOAP message

Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
I'm trying to implement a callback handler in JAAS which uses SOAP to get the user details from a site written in Perl. The SOAP client is comfortably reading the message coming back from the server but I've run aground slightly on try to bind the xml back to a Java opject (in this case username) so that JAAS can take the name and do the processing.

To start with am I better off using JAXB (presumably unmarshall to go from XML to Java) or am I currently barking up the wrong tree? If so, I'd be grateful for some pointers in the right direction

Thanks.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
If you just want one or two items out of the entire envelope then using JAXB may be taking a howitzer on a sparrow hunt.
You may be better off by using XPath to extract the pieces of information that you need from the response.

Example


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
Thanks Peer, howitzer safely stored

Relooking over the code with a slightly more awake set of eyes, this parses out the data that I want but I'm unsure of the method to conver the node to a string which the Java can read.

Iterator iter = body.getChildElements();
Node resultOuter = ((Node) iter.next()).getFirstChild();
Node result = resultOuter.getFirstChild();
System.out.println("\nContents are:\n" + result);

Apologies if a daft question, but first time putting with web services and SOAP.

If that fails as quote, I've also been trying

but keeping getting:

The XML that I'm receiving back from the server is:


[ January 24, 2008: Message edited by: Iain Emsley ]

[ January 24, 2008: Message edited by: Iain Emsley ]

[ UD: added linebreaks to preserve layout ]
[ January 24, 2008: Message edited by: Ulf Dittmer ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Iain Emsley:
I'm unsure of the method to conver the node to a string which the Java can read.




If that fails as quote, I've also been trying

  • SOAP always uses fully qualified names (i.e. namespaces). Your XPath expression doesn't specify any namespaces. Example: {http://schemas.xmlsoap.org/soap/envelope/}Envelope doesn't match {}Envelope.
  • Your XPath expression is not selecting the text of the text node under {}s-gensym3. Your expression needs to end with ".../s-gensym3/child::text()"


  • Ronald Bourret's XML Namespaces FAQ
    James Clark: XML Namespaces

    [ January 28, 2008: Message edited by: Peer Reynders ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Binding XML to Java from SOAP message
     
    Similar Threads
    Output as null
    Servlet using SAAJ and HTTP Authorization Header
    Encrypting a SOAP message
    Servlet using SAAJ and HTTP Authorization Header
    Combining JAAS and SOAP in a log on system