Example usage for javax.xml.soap SOAPElement getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

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

@Validated
@Test/*from  www .j a  v a 2 s. c  om*/
public void testSetValueSingleTextChild() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addTextNode("initial content");
    Text text = (Text) element.getFirstChild();
    String value = "new value";
    element.setValue(value);
    assertEquals(value, text.getValue());
}

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

@Validated
@Test/*from  w  ww . j  av  a  2  s. c  om*/
public void testSetValueNoChildren() {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    String value = "test";
    element.setValue(value);
    assertEquals(value, element.getValue());
    Node child = element.getFirstChild();
    assertTrue(child instanceof Text);
    assertEquals(value, ((Text) child).getValue());
    assertNull(child.getNextSibling());
}

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

@Validated
@Test/*ww w.jav  a2 s .c  o m*/
public void testRemoveContents() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addChildElement(new QName("child1"));
    element.addChildElement(new QName("child2"));
    element.removeContents();
    assertNull(element.getFirstChild());
}

From source file:com.twinsoft.convertigo.engine.translators.WebServiceTranslator.java

private void handleSimpleVariable(Document inputDocument, SOAPElement parameter, String parameterName,
        String parameterValue, Element transactionVariablesElement) {
    Element item = inputDocument.createElement("variable");
    item.setAttribute("name", parameterName);

    // Structured value?
    if (parameter.hasChildNodes() && (parameter.getChildNodes().getLength() > 1
            || parameter.getFirstChild().getNodeType() == Node.ELEMENT_NODE)) {
        appendNodes(parameter.getChildNodes(), item);
        Engine.logBeans.debug("   Adding structured requestable variable '" + parameterName + "'");
    } else {/*  w w w  .j a v  a2s  .  c o  m*/
        item.setAttribute("value", parameterValue);
        Engine.logBeans.debug("   Adding requestable variable '" + parameterName + "' = '"
                + Visibility.maskValue(parameterValue) + "'");
    }
    transactionVariablesElement.appendChild(item);
}

From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java

private void _fixFaultElements(SOAPEnvelope env) {
    try {//from  w  ww .  j a  v  a 2 s.  c om
        // If we have a SOAP 1.2 envelope, then there's nothing to do.
        if (env.getNamespaceURI().equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            return;
        }

        SOAPBody body = env.getBody();
        if (body != null && !body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("No fault found.  No conversion necessary.");
            }
            return;
        } else if (body != null && body.hasFault()) {
            if (log.isDebugEnabled()) {
                log.debug("A fault was found.  Converting the fault child elements to SOAP 1.1 format");
            }

            SOAPFault fault = body.getFault();

            Iterator itr = fault.getChildElements();
            while (itr.hasNext()) {
                SOAPElement se = (SOAPElement) itr.next();
                if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultcode");
                    }
                    // Axis2 SAAJ stores the acutal faultcode text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_CODE_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: detail");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
                } else if (se.getLocalName().equals(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Converting: faultstring");
                    }
                    se.setElementQName(
                            new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                    // Axis2 SAAJ stores the acutal faultstring text under a SOAPFaultValue object, so we have to 
                    // get that and add it as a text node under the original element.
                    Node value = se.getFirstChild();
                    if (value != null && value instanceof org.apache.axis2.saaj.SOAPElementImpl) {
                        org.apache.axis2.saaj.SOAPElementImpl valueElement = (org.apache.axis2.saaj.SOAPElementImpl) value;
                        ElementImpl e = valueElement.getElement();
                        String content = e.getText();

                        SOAPElement child = fault.addChildElement(
                                new QName(se.getNamespaceURI(), SOAP11Constants.SOAP_FAULT_STRING_LOCAL_NAME));
                        child.addTextNode(content);

                        se.detachNode();
                    }
                }
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("An error occured while converting fault elements: " + e.getMessage());
        }
        throw ExceptionFactory.makeWebServiceException(e);
    }
}

From source file:org.olat.modules.vitero.manager.ViteroManager.java

private String extractText(SOAPElement errorCodeEl) {
    for (Node node = errorCodeEl.getFirstChild(); node != null; node = node.getNextSibling()) {
        if (node instanceof Text && StringHelper.containsNonWhitespace(node.getNodeValue())) {
            return node.getNodeValue();
        }//ww  w .j a  v  a2s  .  co  m
    }
    return null;
}