Example usage for javax.xml.soap SOAPElement getElementQName

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

Introduction

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

Prototype

public QName getElementQName();

Source Link

Document

Returns the qname of this SOAPElement object.

Usage

From source file:ee.ria.xroad.common.message.SoapParserImpl.java

/**
 * Checks SOAP header for duplicate fields.
 * @param soapHeader the SOAP header/*from ww  w .  j  a v  a 2 s.  c o m*/
 */
public static void validateSOAPHeader(SOAPHeader soapHeader) {
    // Check for duplicate fields
    Set<QName> fields = new HashSet<>();
    Iterator<?> it = soapHeader.getChildElements();
    while (it.hasNext()) {
        Object next = it.next();
        if (next instanceof SOAPElement) {
            SOAPElement soapElement = (SOAPElement) next;
            if (!fields.add(soapElement.getElementQName())) {
                throw new CodedException(X_DUPLICATE_HEADER_FIELD, "SOAP header contains duplicate field '%s'",
                        soapElement.getElementQName());
            }
        }
    }
}

From source file:ee.ria.xroad.common.message.SoapUtils.java

private static String getServiceCode(SOAPMessage soap, QName requestElementQName) throws SOAPException {
    for (SOAPElement eachHeaderElement : getChildElements(soap.getSOAPHeader())) {
        QName headerElementQName = eachHeaderElement.getElementQName();

        if (!"service".equals(headerElementQName.getLocalPart())) {
            continue;
        }// w ww . j ava 2  s.c o m

        for (SOAPElement eachServicePart : getChildElements(eachHeaderElement)) {
            QName headerPartQName = eachServicePart.getElementQName();

            if (headerPartQName.getLocalPart().equals("serviceCode")) {
                return eachServicePart.getValue();
            }
        }
    }

    return requestElementQName.getLocalPart();
}

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.  j  av  a 2 s.  c  om
        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);
                    }
                }
            }
        }
    }
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from   w w w. ja v  a2  s.  co  m*/
public void testGetElementQNameWithoutNamespace() {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    assertEquals(new QName("test"), element.getElementQName());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test//from  w  w  w.  j av a 2s .c  o m
public void testGetElementQNameWithDefaultNamespace() {
    SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", null);
    assertEquals(new QName("urn:test", "test"), element.getElementQName());
}

From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java

@Validated
@Test/*from w ww .j a v  a  2s  .  c o m*/
public void testGetElementQNameWithNamespace() {
    SOAPElement element = saajUtil.createSOAPElement("urn:test", "test", "p");
    assertEquals(new QName("urn:test", "test", "p"), element.getElementQName());
}

From source file:org.apache.axis2.saaj.SOAPFactoryTest.java

@Validated
@Test//  w  w  w  .jav a 2 s  . c  om
public void testCreateElement() {
    try {
        //SOAPFactory sf = SOAPFactory.newInstance();
        SOAPFactory sf = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        if (sf == null) {
            fail("createElementTest4() could not create SOAPFactory object");
        }
        //Create QName object with localName=MyName1,prefix=MyPrefix1, uri=MyUri1
        QName name = new QName("MyUri1", "MyName1", "MyPrefix1");
        SOAPElement se = sf.createElement(name);
        assertNotNull(se);
        name = se.getElementQName();
        String localName = name.getLocalPart();
        String prefix = name.getPrefix();
        String uri = name.getNamespaceURI();
        if (localName == null) {
            fail("localName is null (expected MyName1)");
        } else if (!localName.equals("MyName1")) {
            fail("localName is wrong (expected MyName1)");
        } else if (prefix == null) {
            fail("prefix is null (expected MyPrefix1)");
        } else if (!prefix.equals("MyPrefix1")) {
            fail("prefix is wrong (expected MyPrefix1)");
        } else if (uri == null) {
            fail("uri is null (expected MyUri1)");
        } else if (!uri.equals("MyUri1")) {
            fail("uri is wrong (expected MyUri1)");
        }
    } catch (Exception e) {
        fail();
    }
}