Java Reference
In-Depth Information
Accessing All SOAP Header Elements
Problem
You want to process all of the SOAP elements on an inbound message.
Solution
Use the SOAPHeader.examineAllHeaderElements method to get an iterator. Use the iterator
to inspect the SOAPHeaderElement objects one at a time.
Discussion
Example 5-11 shows how this works.
Example5-11.Shows all headers in a message
package allHeaders;
import java.io.IOException;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPHeaderElement;
import javax.xml.soap.SOAPMessage;
/**
* Loops over headers in a message.
*/
public class AllHeaders {
private static final String NS = "urn:soacookbook.saaj";
public static void main(String args...) {
try {
AllHeaders me = new AllHeaders();
me.showHeaders(me.createMessage());
} catch (SOAPException ex) {
ex.printStackTrace();
}
Search WWH ::




Custom Search