SOAP messaging with SAAJ

Discussion in 'Java' started by Phil Wilkinson, Jun 8, 2006.

  1. A newb question really that I hope someone can help me with.

    I am experimenting with SOAP using a standalone Java application, built
    along the lines of this tutorial
    http://www-128.ibm.com/developerworks/xml/library/x-jaxmsoap/ but using
    Google's API so that I can at least send and get a response from
    something. As in the tutorial I have dowloaded and set up Java Web
    Services Developer Pack and I am using Eclipse. (Yes I know there are
    easier ways like using Google's Java client library but I'm using SAAJ,
    as the SOAP service/environment I will eventually be using means that
    this is all that I will have available to me).

    I can send and receive the SOAP message OK using the Transformer object
    and can dump out the response tree. I really need to obtain the
    individual elements value only (in this case a correct spelling
    suggestion) but when I modify my code to try to access the individual
    elements as in the Sun tutorial here
    http://java.sun.com/j2ee/1.4/docs/tutorial/doc/SAAJ3.html I get an
    error message related to the iterator, in particular it seems unable to
    access the individual element (see below).

    java.util.NoSuchElementException
    at
    com.sun.xml.messaging.saaj.soap.impl.ElementImpl$3.next(ElementImpl.java:723)
    at Request.main(Request.java:56)

    Iterator code below:

    SOAPBody soapBody = response.getSOAPBody();
    System.out.println("\nRESPONSE:\n");
    Iterator iterator = soapBody.getChildElements(bodyName);
    SOAPBodyElement ReturnedBodyElement =
    (SOAPBodyElement)iterator.next();
    String returned = ReturnedBodyElement.getValue();
    System.out.print("The Response from the server is ");
    System.out.println(returned);

    Using Transformer object I get this (so I know I can get a response!):

    <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">
    <SOAP-ENV:Body>
    <ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <return xsi:type="xsd:string">half</return>
    </ns1:doSpellingSuggestionResponse>

    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    Any suggestions as to how I can get the iterator to work so I can
    access the returned value would be much appreciated.
     
    Phil Wilkinson, Jun 8, 2006
    #1
    1. Advertising

  2. Phil Wilkinson

    Oliver Wong Guest

    "Phil Wilkinson" <> wrote in message
    news:...
    > I get an
    > error message related to the iterator, in particular it seems unable to
    > access the individual element (see below).
    >
    > java.util.NoSuchElementException
    > at
    > com.sun.xml.messaging.saaj.soap.impl.ElementImpl$3.next(ElementImpl.java:723)
    > at Request.main(Request.java:56)
    >
    > Iterator code below:
    >
    > SOAPBody soapBody = response.getSOAPBody();
    > System.out.println("\nRESPONSE:\n");
    > Iterator iterator = soapBody.getChildElements(bodyName);
    > SOAPBodyElement ReturnedBodyElement =
    > (SOAPBodyElement)iterator.next();
    > String returned = ReturnedBodyElement.getValue();
    > System.out.print("The Response from the server is ");
    > System.out.println(returned);


    Did you check the value of bodyName?

    - Oliver
     
    Oliver Wong, Jun 8, 2006
    #2
    1. Advertising

  3. Phil Wilkinson

    Guest

    Phil Wilkinson wrote:
    > A newb question really that I hope someone can help me with.
    >
    > I am experimenting with SOAP using a standalone Java application, built
    > along the lines of this tutorial
    > http://www-128.ibm.com/developerworks/xml/library/x-jaxmsoap/ but using
    > Google's API so that I can at least send and get a response from
    > something. As in the tutorial I have dowloaded and set up Java Web
    > Services Developer Pack and I am using Eclipse. (Yes I know there are
    > easier ways like using Google's Java client library but I'm using SAAJ,
    > as the SOAP service/environment I will eventually be using means that
    > this is all that I will have available to me).
    >
    > I can send and receive the SOAP message OK using the Transformer object
    > and can dump out the response tree.

    [...]

    If you're willing to post it, I'd like to see your source code, as I'm
    also interested in the Google API :)


    -Thufir
     
    , Jun 8, 2006
    #3
  4. "Phil Wilkinson" <> wrote in message
    news:...
    >A newb question really that I hope someone can help me with.
    >
    > I am experimenting with SOAP using a standalone Java application, built
    > along the lines of this tutorial
    > http://www-128.ibm.com/developerworks/xml/library/x-jaxmsoap/ but using
    > Google's API so that I can at least send and get a response from
    > something. As in the tutorial I have dowloaded and set up Java Web
    > Services Developer Pack and I am using Eclipse. (Yes I know there are
    > easier ways like using Google's Java client library but I'm using SAAJ,
    > as the SOAP service/environment I will eventually be using means that
    > this is all that I will have available to me).
    >
    > I can send and receive the SOAP message OK using the Transformer object
    > and can dump out the response tree. I really need to obtain the
    > individual elements value only (in this case a correct spelling
    > suggestion) but when I modify my code to try to access the individual
    > elements as in the Sun tutorial here
    > http://java.sun.com/j2ee/1.4/docs/tutorial/doc/SAAJ3.html I get an
    > error message related to the iterator, in particular it seems unable to
    > access the individual element (see below).
    >
    > java.util.NoSuchElementException
    > at
    > com.sun.xml.messaging.saaj.soap.impl.ElementImpl$3.next(ElementImpl.java:723)
    > at Request.main(Request.java:56)
    >
    > Iterator code below:
    >
    > SOAPBody soapBody = response.getSOAPBody();
    > System.out.println("\nRESPONSE:\n");
    > Iterator iterator = soapBody.getChildElements(bodyName);
    > SOAPBodyElement ReturnedBodyElement =
    > (SOAPBodyElement)iterator.next();
    > String returned = ReturnedBodyElement.getValue();
    > System.out.print("The Response from the server is ");
    > System.out.println(returned);
    >
    > Using Transformer object I get this (so I know I can get a response!):
    >
    > <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
    > xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    > xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/1999/XMLSchema">
    > <SOAP-ENV:Body>
    > <ns1:doSpellingSuggestionResponse xmlns:ns1="urn:GoogleSearch"
    > SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    > <return xsi:type="xsd:string">half</return>
    > </ns1:doSpellingSuggestionResponse>
    >
    > </SOAP-ENV:Body>
    > </SOAP-ENV:Envelope>
    >
    > Any suggestions as to how I can get the iterator to work so I can
    > access the returned value would be much appreciated.



    My WAG is that you're leaving out the namespace of
    doSpellingSuggestionResponse.
     
    Mike Schilling, Jun 9, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sunil

    to saaj or not to saaj

    Sunil, Jan 12, 2004, in forum: Java
    Replies:
    0
    Views:
    333
    Sunil
    Jan 12, 2004
  2. M. Turner
    Replies:
    0
    Views:
    603
    M. Turner
    Jun 25, 2004
  3. Jannar Molden

    SAAJ XML SOAP and element parameters

    Jannar Molden, Sep 2, 2004, in forum: Java
    Replies:
    1
    Views:
    992
    iksrazal
    Sep 3, 2004
  4. frank
    Replies:
    0
    Views:
    397
    frank
    Apr 16, 2005
  5. chris_isima

    SOAP/SAAJ error

    chris_isima, Mar 1, 2007, in forum: Java
    Replies:
    1
    Views:
    680
    chris_isima
    Mar 1, 2007
Loading...

Share This Page