Example usage for javax.xml.soap SOAPElement getChildElements

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

Introduction

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

Prototype

public Iterator<Node> getChildElements();

Source Link

Document

Returns an Iterator over all the immediate child Node s of this element.

Usage

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

/**
 * Returns the first child that are of the SOAPElement
 * type of the given element./*  w w w  .  j  a  va2  s.  c  o  m*/
 * @param element parent for which to retrieve the children
 * @return SOAPElement that is the first child of the given parent or null
 */
public static SOAPElement getFirstChild(SOAPElement element) {
    Iterator<?> it = element.getChildElements();
    while (it.hasNext()) {
        Object o = it.next();
        if (o instanceof SOAPElement) {
            return (SOAPElement) o;
        }
    }

    return null;
}

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

/**
 * Returns all children that are of the SOAPElement
 * type of the given element./*from   w  ww.  j a  v  a 2  s . c o  m*/
 * @param element parent for which to retrieve the children
 * @return List of SOAPElements that can be found
 */
public static List<SOAPElement> getChildElements(SOAPElement element) {
    List<SOAPElement> elements = new ArrayList<>();
    Iterator<?> it = element.getChildElements();
    while (it.hasNext()) {
        Object o = it.next();
        if (o instanceof SOAPElement) {
            elements.add((SOAPElement) o);
        }
    }
    return elements;
}

From source file:com.polivoto.networking.SoapClient.java

public String start() throws SOAPException, IOException {
    String resp = "NaN";
    // Create SOAP Connection
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    // Send SOAP Message to SOAP Server
    String url = "http://" + host
            + "/FistVotingServiceBank/services/ServAvailableVoteProcesses.ServAvailableVoteProcessesHttpSoap11Endpoint/";
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url);

    SOAPBody body = soapResponse.getSOAPBody();
    java.util.Iterator updates = body.getChildElements();
    // El siguiente ciclo funciona slo porque el cuerpo contiene 
    // un elemento y ste a suvez nicamente contiene un elemento.
    while (updates.hasNext()) {
        System.out.println();//from  w w w . j  a v  a 2  s .  co  m
        // The listing and its ID
        SOAPElement update = (SOAPElement) updates.next();
        java.util.Iterator i = update.getChildElements();
        while (i.hasNext()) {
            SOAPElement e = (SOAPElement) i.next();
            String name = e.getLocalName();
            String value = e.getValue();
            resp = value; // Am I getting last response?
            System.out.println(name + ": " + value);
        }
    }
    soapConnection.close();
    return resp;
}

From source file:hk.hku.cecid.corvus.ws.EBMSMessageHistoryQuerySenderTest.java

private String getElementValue(SOAPElement msgBody, String name) {
    Iterator iterator = msgBody.getChildElements();
    while (iterator.hasNext()) {
        SOAPElement current = (SOAPElement) iterator.next();
        if (current.getNodeName().equalsIgnoreCase(name))
            return current.getValue();
    }/*from  w  w  w. j ava2 s . c o m*/
    return null;
}

From source file:it.cnr.icar.eric.common.cms.AbstractService.java

protected SOAPElement getSOAPElementFromBindingObject(Object obj) throws Exception {
    SOAPElement soapElem = null;/*w ww  .ja  v a  2  s  .c o m*/

    SOAPElement parent = SOAPFactory.newInstance().createElement("dummy");

    Marshaller marshaller = getJAXBContext().createMarshaller();
    marshaller.marshal(obj, System.err);
    marshaller.marshal(obj, new DOMResult(parent));
    soapElem = (SOAPElement) parent.getChildElements().next();

    return soapElem;
}

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

/**
 * Tests the behavior of {@link SOAPElement#getChildElements()} when there are text nodes among
 * the children of the element. In contrast to what the name of the method suggests, they will
 * also be returned by the iterator./*from   ww w .j  a  v  a  2 s  .c  o  m*/
 * 
 * @throws Exception
 */
@Validated
@Test
public void testGetChildElementsWithTextNodes() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addTextNode("foo");
    element.addChildElement(new QName("child"));
    element.addTextNode("bar");
    Iterator it = element.getChildElements();
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof Text);
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof SOAPElement);
    assertTrue(it.hasNext());
    assertTrue(it.next() instanceof Text);
    assertFalse(it.hasNext());
}

From source file:it.cnr.icar.eric.common.BindingUtility.java

public SOAPElement getSOAPElementFromBindingObject(Object obj) throws JAXRException {
    SOAPElement soapElem = null;/*from  w ww .ja  va  2 s. c o m*/

    try {
        SOAPElement parent = SOAPFactory.newInstance().createElement("dummy");

        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.marshal(obj, new DOMResult(parent));

        soapElem = (SOAPElement) parent.getChildElements().next();

    } catch (Exception e) {
        throw new JAXRException(e);
    }

    return soapElem;
}

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

public void buildInputDocument(Context context, Object inputData) throws Exception {
    Engine.logBeans.debug("[WebServiceTranslator] Making input document");

    HttpServletRequest request = (HttpServletRequest) inputData;

    SOAPMessage requestMessage = (SOAPMessage) request
            .getAttribute(WebServiceServlet.REQUEST_MESSAGE_ATTRIBUTE);

    SOAPPart sp = requestMessage.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();/*from  w  ww.  ja  va2 s. co m*/

    Iterator<?> iterator = sb.getChildElements();
    SOAPElement method, parameter;
    String methodName;

    InputDocumentBuilder inputDocumentBuilder = new InputDocumentBuilder(context);

    while (iterator.hasNext()) {
        List<RequestableVariable> variableList = null; // jmc 12/06/26

        Object element = iterator.next();
        if (element instanceof SOAPElement) {
            method = (SOAPElement) element;

            methodName = method.getElementName().getLocalName();
            Engine.logBeans.debug("[WebServiceTranslator] Requested web service name: " + methodName);

            int i = methodName.indexOf("__");

            // for statefull transaction, don't replace the project
            if (context.project == null || !context.project.getName().equals(context.projectName)) {
                context.project = Engine.theApp.databaseObjectsManager.getProjectByName(context.projectName);
            }

            String connectorName = null;
            if (i == -1) {
                context.connectorName = null;
                context.sequenceName = methodName;
            } else {
                connectorName = methodName.substring(0, i);
                context.transactionName = methodName.substring(i + 2);
            }

            if ((connectorName != null) && (!connectorName.equals(context.connectorName))) {
                Engine.logBeans.debug("Connector name differs from previous one; requiring new session");
                context.isNewSession = true;
                context.connectorName = connectorName;
                Engine.logBeans.debug("[WebServiceTranslator] The connector is overridden to \""
                        + context.connectorName + "\".");
            }

            Engine.logBeans.debug("[WebServiceTranslator] Connector: "
                    + (context.connectorName == null ? "(default)" : context.connectorName));
            Engine.logBeans.debug("[WebServiceTranslator] Transaction: " + context.transactionName);

            //Connector connector = (context.connectorName == null ? context.project.getDefaultConnector() : context.project.getConnectorByName(context.connectorName));
            //Transaction transaction = (context.transactionName == null ? connector.getDefaultTransaction() : connector.getTransactionByName(context.transactionName));
            RequestableObject requestable = null;
            if (context.sequenceName != null) {
                requestable = context.project.getSequenceByName(context.sequenceName);
                variableList = ((Sequence) requestable).getVariablesList();
            } else if (context.connectorName != null) {
                if (context.transactionName != null) {
                    requestable = context.project.getConnectorByName(context.connectorName)
                            .getTransactionByName(context.transactionName);
                    if (requestable instanceof TransactionWithVariables) {
                        variableList = ((TransactionWithVariables) requestable).getVariablesList();
                    }
                }
            }

            Iterator<?> iterator2 = method.getChildElements();
            String parameterName, parameterValue;

            while (iterator2.hasNext()) {
                element = iterator2.next();
                if (element instanceof SOAPElement) {
                    parameter = (SOAPElement) element;
                    parameterName = parameter.getElementName().getLocalName();
                    parameterValue = parameter.getValue();
                    if (parameterValue == null) {
                        parameterValue = "";
                    }

                    if (variableList != null) { // jmc 12/06/26 hide hidden variables in sequences
                        String str = (String) Visibility.Logs.replaceVariables(variableList,
                                "" + parameterName + "=\"" + parameterValue + "\"");
                        Engine.logBeans.debug("   Parameter: " + str);
                    } else
                        Engine.logBeans.debug("   Parameter: " + parameterName + "=\"" + parameterValue + "\"");

                    // Handle convertigo parameters
                    if (parameterName.startsWith("__")) {
                        webServiceServletRequester.handleParameter(parameterName, parameterValue);
                    }

                    // Common parameter handling
                    if (inputDocumentBuilder.handleSpecialParameter(parameterName, parameterValue)) {
                        // handled
                    }
                    // Compatibility for Convertigo 2.x
                    else if (parameterName.equals("context")) {
                        // Just ignore it
                    } else {
                        SOAPElement soapArrayElement = null;
                        Iterator<?> iterator3;

                        String href = parameter.getAttributeValue(se.createName("href"));

                        String arrayType = parameter.getAttributeValue(se.createName("soapenc:arrayType"));
                        if (arrayType == null) {
                            iterator3 = parameter.getAllAttributes();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof Name) {
                                    String s = ((Name) element).getQualifiedName();
                                    if (s.equals("soapenc:arrayType")) {
                                        arrayType = s;
                                        break;
                                    }
                                }
                            }
                        }

                        // Array (Microsoft .net)
                        if (href != null) {
                            Engine.logBeans.debug("Deserializing Microsoft .net array");
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            iterator3 = soapArrayElement.getChildElements();
                                            while (iterator3.hasNext()) {
                                                element = iterator3.next();
                                                if (element instanceof SOAPElement) {
                                                    break;
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                            }

                            // Find the element with href id
                            iterator3 = sb.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    String elementId = soapArrayElement.getAttributeValue(se.createName("id"));
                                    if (elementId != null) {
                                        if (href.equals("#" + elementId)) {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        // Array (Java/Axis)
                        else if (arrayType != null) {
                            Engine.logBeans.debug("Deserializing Java/Axis array");
                            soapArrayElement = parameter;
                        }
                        // If the node has children nodes, we assume it is an array.
                        else if (parameter.getChildElements().hasNext()) {
                            if (isSoapArray((IVariableContainer) requestable, parameterName)) {
                                Engine.logBeans.debug("Deserializing array");
                                soapArrayElement = parameter;
                            }
                        }

                        // Deserializing array
                        if (soapArrayElement != null) {
                            iterator3 = soapArrayElement.getChildElements();
                            while (iterator3.hasNext()) {
                                element = iterator3.next();
                                if (element instanceof SOAPElement) {
                                    soapArrayElement = (SOAPElement) element;
                                    parameterValue = soapArrayElement.getValue();
                                    if (parameterValue == null)
                                        parameterValue = "";
                                    handleSimpleVariable(context.inputDocument, soapArrayElement, parameterName,
                                            parameterValue, inputDocumentBuilder.transactionVariablesElement);
                                }
                            }
                        }
                        // Deserializing simple variable
                        else {
                            handleSimpleVariable(context.inputDocument, parameter, parameterName,
                                    parameterValue, inputDocumentBuilder.transactionVariablesElement);
                        }
                    }
                }
            }

            if (Engine.logBeans.isDebugEnabled()) {
                String soapMessage = SOAPUtils.toString(requestMessage, request.getCharacterEncoding());

                if (requestable instanceof TransactionWithVariables)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n"
                            + Visibility.Logs.replaceVariables(
                                    ((TransactionWithVariables) (requestable)).getVariablesList(), request));
                else if (requestable instanceof Sequence)
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + Visibility.Logs
                            .replaceVariables(((Sequence) (requestable)).getVariablesList(), request));
                else
                    Engine.logBeans.debug("[WebServiceTranslator] SOAP message received:\n" + soapMessage);
            }

            break;
        }
    }

    Engine.logBeans.debug("[WebServiceTranslator] SOAP message analyzed");

    Engine.logBeans.debug("[WebServiceTranslator] Input document created");
}

From source file:org.apache.axis.handlers.HandlerChainImpl.java

public ArrayList getMessageInfo(SOAPMessage message) {
    ArrayList list = new ArrayList();
    try {/* w w w  . ja  v  a  2s  . c  om*/
        if (message == null || message.getSOAPPart() == null)
            return list;
        SOAPEnvelope env = message.getSOAPPart().getEnvelope();
        SOAPBody body = env.getBody();
        Iterator it = body.getChildElements();
        SOAPElement operation = (SOAPElement) it.next();
        list.add(operation.getElementName().toString());
        for (Iterator i = operation.getChildElements(); i.hasNext();) {
            SOAPElement elt = (SOAPElement) i.next();
            list.add(elt.getElementName().toString());
        }
    } catch (Exception e) {
        log.debug("Exception in getMessageInfo : ", e);
    }
    return list;
}

From source file:org.apache.axis.message.NodeImpl.java

/**
 * The node immediately following this node. If there is no such node,
 * this returns <code>null</code>.
 *///from w  w  w. j  ava 2  s.  c  o m
public Node getNextSibling() {
    SOAPElement parent = getParentElement();
    if (parent == null) {
        return null;
    }
    Iterator iter = parent.getChildElements();
    Node nextSibling = null;
    while (iter.hasNext()) {
        if (iter.next() == this) {
            if (iter.hasNext()) {
                return (Node) iter.next();
            } else {
                return null;
            }
        }
    }
    return nextSibling; // should be null.
}