Example usage for javax.xml.soap SOAPBody getFirstChild

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

Introduction

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

Prototype

public Node getFirstChild();

Source Link

Document

The first child of this node.

Usage

From source file:com.hiperium.commons.client.soap.AthenticationDispatcherTest.java

/**
 * /*w ww.ja va 2 s  .  c  o m*/
 * @param response
 */
public static void readSOAPMessageResponse(SOAPMessage response) {
    SOAPBody authBodyResponse;
    try {
        authBodyResponse = response.getSOAPBody();
        Node authNode = authBodyResponse.getFirstChild();
        NodeList authNodeList = authNode.getChildNodes();
        String responseString = authNodeList.item(0).getFirstChild().getNodeValue();
        LOGGER.debug("RESPONSE: " + responseString);
    } catch (SOAPException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:com.betfair.testing.utils.cougar.helpers.CougarHelpers.java

public Node extractResponseNode(SOAPMessage response) throws SOAPException {

    Node responseNode;/*from   w  w w  . j  a v a2  s .  c o m*/

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    try {
        response.writeTo(outStream);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    //      logger.LogBetfairDebugEntry("SOAP Response: " + outStream.toString());

    if (response.getSOAPBody().hasFault()) {
        responseNode = response.getSOAPBody().getFault();
    } else if (response.getSOAPBody().getFirstChild() == null) { // Response type is void
        responseNode = response.getSOAPBody();
    } else {
        // extract the body
        SOAPBody respBody = response.getSOAPBody();
        // First child should be the service name object
        Node serviceResponseNode = respBody.getFirstChild();

        // second child
        responseNode = serviceResponseNode.getFirstChild();
    }

    return responseNode;
}

From source file:org.apache.axis2.jaxws.client.dispatch.BaseDispatch.java

/**
 * Given a JAXWS Message Context which contains an outbound service-requester Message for a Dispatch client,
 * determine the QName of the first body element contained in that message.
 * /*w w w  . j  a va 2 s .  co  m*/
 * @param requestMessageCtx requestMessageCtx JAXWS Message Context containing the outbound Dispatch message
 * @return the QName of the first body element contained in the outbound Dispatch message, or null if it 
 * can not be determined.
 */
QName getBodyElementQNameFromDispatchMessage(MessageContext requestMessageCtx) {
    QName bodyElementQName = null;
    Message dispatchMessage = requestMessageCtx.getMessage();
    SOAPMessage soapMessage = dispatchMessage.getAsSOAPMessage();
    try {
        SOAPBody soapBody = soapMessage.getSOAPBody();
        Node firstElement = soapBody.getFirstChild();
        // A Doc/Lit/Bare message may not have a firsElement.  The soap:Body element may be empty if there 
        // are no arguments to the operation.
        if (firstElement != null) {
            String ns = firstElement.getNamespaceURI();
            String lp = firstElement.getLocalName();
            // A Doc/Lit/Bare message may not have a localPart on the element.  That can happen if the first element
            // is the argument value and there is no wrapper element surrounding it.
            if (lp != null) {
                bodyElementQName = new QName(ns, lp);
            }
        }
    } catch (SOAPException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unabled to get the first body element from the outbound dispatch message", e);
        }
    }
    return bodyElementQName;
}

From source file:org.libreplan.importers.TimSoapClient.java

/**
 * Unmarshals the specified paramter <code>soapBody</code> to the specified
 * <code>clazz</code>/* w  ww .j  a va2 s  . c  om*/
 *
 * @param clazz
 *            object to hold unmarashal result
 * @param soapBody
 *            the soap body to be unmarshalled
 * @return the unmarashalled object
 * @throws JAXBException
 *             if unmarshal failed
 */
@SuppressWarnings("unchecked")
private static <T> T unmarshal(Class<T> clazz, SOAPBody soapBody) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(clazz);

    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    Node bindElement = (Node) soapBody.getFirstChild();

    while (bindElement.getNodeType() != Node.ELEMENT_NODE) {
        bindElement = (Node) bindElement.getNextSibling();
    }

    return unmarshaller.unmarshal(bindElement, clazz).getValue();
}