Example usage for javax.xml.soap SOAPHeader extractAllHeaderElements

List of usage examples for javax.xml.soap SOAPHeader extractAllHeaderElements

Introduction

In this page you can find the example usage for javax.xml.soap SOAPHeader extractAllHeaderElements.

Prototype

public Iterator<SOAPHeaderElement> extractAllHeaderElements();

Source Link

Document

Returns an Iterator over all the SOAPHeaderElement objects in this SOAPHeader object and detaches them from this SOAPHeader object.

Usage

From source file:cn.com.ttblog.ssmbootstrap_table.webservice.LicenseHandler.java

@SuppressWarnings("unchecked")
@Override/* w  ww.ja v  a  2 s  .c o m*/
public boolean handleMessage(SOAPMessageContext context) {
    try {
        Boolean out = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
        logger.debug("LicenseHandler:{}", out);
        if (!out) {
            SOAPMessage message = context.getMessage();
            logger.debug("SOAPMessage:{}", ToStringBuilder.reflectionToString(message));
            SOAPEnvelope enve = message.getSOAPPart().getEnvelope();
            SOAPHeader header = enve.getHeader();
            SOAPBody body = enve.getBody();
            Node bn = body.getChildNodes().item(0);
            String partname = bn.getLocalName();
            if ("getUser".equals(partname)) {
                if (header == null) {
                    // ?
                    SOAPFault fault = body.addFault();
                    fault.setFaultString("??!");
                    throw new SOAPFaultException(fault);
                }
                Iterator<SOAPHeaderElement> iterator = header.extractAllHeaderElements();
                if (!iterator.hasNext()) {
                    // ?
                    SOAPFault fault = body.addFault();
                    fault.setFaultString("??!");
                    throw new SOAPFaultException(fault);
                }
                while (iterator.hasNext()) {
                    SOAPHeaderElement ele = iterator.next();
                    System.out.println(ele.getTextContent());
                }
            }
        }
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return true;
}