users@jax-rpc.java.net

Re: Soap with attachments using Java SAAJ problem

From: Mike Woinoski <news_at_pineneedleconsulting.com>
Date: Mon, 18 Apr 2005 12:17:40 -0400

Frank,
The output you included seems fine:
com.sun.xml.messaging.saaj.soap.impl.ElementImpl implements
SOAPBodyElement, so there is no surprise there. However, the output from
the if/else in your sample code seems to be missing. Do you get the
element's value or the "not a SOAPBodyElement" message?

BTW, that tutorial you are looking at is ancient. Take a look at a newer
version at http://java.sun.com/webservices/docs/1.3/tutorial/doc/ (this
version is still pretty old, but many of the chapters were removed in
later versions of the tutorial.)

Regards,
Mike

Frank wrote:

> Not entirely sure this is the best users group for java SAAJ questions
> but did not see a better one.
>
> I have Been trying to learn how to create and receive soap messages
> using java's SAAJ API. I have been having a problem after reading in
> a soap message being ale to parse it out into it's pieces parts. I
> see some code that allows me to do it from a file but I have a
> SOAPMessage type that was read in from the network and it would be
> silly to save to a file too read back in. But I did find some other
> example code that seems to do what I want it to do. I want to get the
> values of any given element in the document, should be no big deal right?
>
> I got the exampl from here:
> http://web2.java.sun.com/webservices/docs/ea1/tutorial/doc/JAXM.ws4.html
>
> the code snipit is below
>
> SOAPPart sp = reply.getSOAPPart();
> SOAPEnvelope se = sp.getEnvelope();
> SOAPBody sb = se.getBody();
>
>
> System.out.println("\n\ndisplaySoapReplyDOM");
> System.out.println("-------------------");
>
>
> Name name = se.createName("SECRET");
> java.util.Iterator it = sb.getChildElements(name);
>
> while (it.hasNext())
> {
> Object o = it.next();
> System.out.println("The class of " + o +
> " is " + o.getClass().getName());
>
> if (o instanceof SOAPBodyElement)
> {
> SOAPBodyElement bodyElement = (SOAPBodyElement) o;
> String ele = bodyElement.getValue();
> System.out.print("Element: ");
> System.out.println(ele);
> }
> else
> {
> System.out.println("\n not a SOAPBodyElement");
> }
> }
>
> The soap Message is as follows:
> <?xml version="1.0" encoding="UTF-8"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
> <soap:Body>
> <UNCLAS>
> /1/1
> /1/2/1/1/1
> /1/2/1/1/2
> /1/2/1/1/3
> /1/2/1/1/6
> /1/2/1/2
> </UNCLAS>
> <SECRET>/1/2/1/1/4</SECRET>
> <TOP_SECRET>
> /1
> /1/2
> /1/2/1
> /1/2/1/1
> /1/2/1/1/5
> </TOP_SECRET>
> </soap:Body>
> </soap:Envelope>
>
> The output is as follows:
>
> displaySoapReplyDOM
> -------------------
> The class of [SECRET: null] is
> com.sun.xml.messaging.saaj.soap.impl.ElementImpl