Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binding XML to Java from SOAP message

 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Iain Emsley
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic