• 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Binding XML to Java from SOAP message

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
     
    pie. tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic