Example usage for javax.xml.soap SOAPHeaderElement getElementQName

List of usage examples for javax.xml.soap SOAPHeaderElement getElementQName

Introduction

In this page you can find the example usage for javax.xml.soap SOAPHeaderElement getElementQName.

Prototype

public QName getElementQName();

Source Link

Document

Returns the qname of this SOAPElement object.

Usage

From source file:org.apache.taverna.activities.wsdl.T2WSDLSOAPInvoker.java

@Override
protected void addSoapHeader(SOAPEnvelope envelope) throws SOAPException {
    if (wsrfEndpointReference != null) {

        // Extract elements
        // Add WSA-stuff
        // Add elements

        Document wsrfDoc;/*from  w w w . jav a 2  s  .c  o  m*/
        try {
            wsrfDoc = parseWsrfEndpointReference(wsrfEndpointReference);
        } catch (Exception e) {
            logger.warn("Could not parse endpoint reference, ignoring:\n" + wsrfEndpointReference, e);
            return;
        }

        Element wsrfRoot = wsrfDoc.getDocumentElement();

        Element endpointRefElem = null;
        if (!wsrfRoot.getNamespaceURI().equals(WSA200403NS)
                || !wsrfRoot.getLocalName().equals(ENDPOINT_REFERENCE)) {
            // Only look for child if the parent is not an EPR
            NodeList nodes = wsrfRoot.getChildNodes();
            for (int i = 0, n = nodes.getLength(); i < n; i++) {
                Node node = nodes.item(i);
                if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(ENDPOINT_REFERENCE)
                        && node.getNamespaceURI().equals(WSA200403NS)) {
                    // Support wrapped endpoint reference for backward compatibility
                    // and convenience (T2-677)
                    endpointRefElem = (Element) node;
                    break;
                }
            }
        }

        if (endpointRefElem == null) {
            logger.warn("Unexpected element name for endpoint reference, but inserting anyway: "
                    + wsrfRoot.getTagName());
            endpointRefElem = wsrfRoot;
        }

        Element refPropsElem = null;
        NodeList nodes = endpointRefElem.getChildNodes();
        for (int i = 0, n = nodes.getLength(); i < n; i++) {
            Node node = nodes.item(i);
            if (Node.ELEMENT_NODE == node.getNodeType() && node.getLocalName().equals(REFERENCE_PROPERTIES)
                    && node.getNamespaceURI().equals(WSA200403NS)) {
                refPropsElem = (Element) node;
                break;
            }
        }
        if (refPropsElem == null) {
            logger.warn("Could not find " + REFERENCE_PROPERTIES);
            return;
        }

        SOAPHeader header = envelope.getHeader();
        if (header == null) {
            header = envelope.addHeader();
        }

        NodeList refProps = refPropsElem.getChildNodes();

        for (int i = 0, n = refProps.getLength(); i < n; i++) {
            Node node = refProps.item(i);

            if (Node.ELEMENT_NODE == node.getNodeType()) {
                SOAPElement soapElement = SOAPFactory.newInstance().createElement((Element) node);
                header.addChildElement(soapElement);

                Iterator<SOAPHeaderElement> headers = header.examineAllHeaderElements();
                while (headers.hasNext()) {
                    SOAPHeaderElement headerElement = headers.next();
                    if (headerElement.getElementQName().equals(soapElement.getElementQName())) {
                        headerElement.setMustUnderstand(false);
                        headerElement.setActor(null);
                    }
                }
            }
        }
    }
}