Soap with attachments SAAJ question

F

frank

Not entirely sure this is the best news 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top