1

I set up JAXWS handler to validate incoming header from JAXWS client . i wanted to know how to print the headers that are captured in the

handleMessage(SOAPMessageContext context)

what i have here :

Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

        //for response message only, true for outbound messages, false for inbound
        if(!isRequest){

        try{
            SOAPMessage soapMsg = context.getMessage();
            SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
                SOAPHeader soapHeader = soapEnv.getHeader();

                Iterator<?> i = soapHeader.getChildElements();
                System.out.println("Number of header elements:  "
                        + countElements(i)); 

            }catch(SOAPException e){
                System.err.println(e);
            }

        }

how do i extract from the Iterator the headers key and value ?

user63898
  • 29,839
  • 85
  • 272
  • 514

2 Answers2

0

Be aware that in some JAX-WS implementations calls to SOAPMessageContext.getMessage() can result in the entire message being unmarshalled. For web services that rely on streaming MTOM attachments to transfer binary content (especially large binary content) this should be avoided.

See my post that describes a different method for retrieving values of SOAP headers more efficiently : JAXWS Soap Handler Large MTOM Attachments

Community
  • 1
  • 1
Kabron
  • 151
  • 1
  • 11
0
while (i.hasNext()) {
    SOAPElement el = i.next(); // <ns:example>hello</ns:example>
    String tagName = el.getTagName(); // does not include namespace (example)
    String value = el.getValue(); // (hello)
}

SOAPElement supports a lot more methods as well.

Mike M. Lin
  • 9,992
  • 12
  • 53
  • 62