Example usage for javax.xml.soap SOAPElement addChildElement

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

Introduction

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

Prototype

public SOAPElement addChildElement(String localName, String prefix) throws SOAPException;

Source Link

Document

Creates a new SOAPElement object initialized with the specified local name and prefix and adds the new element to this SOAPElement object.

Usage

From source file:au.com.ors.rest.controller.AutoCheckController.java

private SOAPMessage createSOAPRequest(String driverLicenseNumber, String fullName, String postCode)
        throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://soap.ors.com.au/pdv";

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("pdv", serverURI);

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapElement = soapBody.addChildElement("PDVCheckRequestMsg", "pdv");
    SOAPElement soapElementChild1 = soapElement.addChildElement("driverLicenseNumber", "pdv");
    soapElementChild1.addTextNode(driverLicenseNumber);
    SOAPElement soapElementChild2 = soapElement.addChildElement("fullName", "pdv");
    soapElementChild2.addTextNode(fullName);
    SOAPElement soapElementChild3 = soapElement.addChildElement("postCode", "pdv");
    soapElementChild3.addTextNode(postCode);

    // MimeHeaders headers = soapMessage.getMimeHeaders();
    // headers.addHeader(S, value);
    soapMessage.saveChanges();/*from  ww w  .j av  a 2 s  . c  o m*/

    System.out.println("Request SOAP Message:");
    soapMessage.writeTo(System.out);
    return soapMessage;
}

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

private SOAPMessage createSOAPRequest() throws SOAPException, IOException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://votingservice.develops.capiz.org";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);

    /* El siguiente es un ejemplo tomado de donde me bas para armar la solicitud.
    Constructed SOAP Request Message://from w  w w.j  a v  a2 s  .  com
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:example="http://ws.cdyne.com/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <example:VerifyEmail>
            <example:email>mutantninja@gmail.com</example:email>
            <example:LicenseKey>123</example:LicenseKey>
        </example:VerifyEmail>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("serviceChooser", "example");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("json", "example");
    soapBodyElem1.addTextNode(json.toString());
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "serviceChooser");
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:be.agiv.security.handler.WSTrustHandler.java

private void handleOutboundMessage(SOAPMessageContext context) throws SOAPException {
    if (null == this.secondaryParametersNodeList) {
        return;//from  www .  j  a  va 2  s .com
    }
    SOAPMessage soapMessage = context.getMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPBody soapBody = soapMessage.getSOAPBody();
    NodeList nodeList = soapBody.getElementsByTagNameNS(WSConstants.WSTRUST_NAMESPACE, "RequestSecurityToken");
    if (0 == nodeList.getLength()) {
        return;
    }
    SOAPElement requestSecurityTokenElement = (SOAPElement) nodeList.item(0);
    String prefix = requestSecurityTokenElement.getPrefix();
    SOAPElement secondaryParametersElement = requestSecurityTokenElement.addChildElement("SecondaryParameters",
            prefix);
    for (int idx = 0; idx < this.secondaryParametersNodeList.getLength(); idx++) {
        Node node = this.secondaryParametersNodeList.item(idx);
        Node importedNode = soapPart.importNode(node, true);
        secondaryParametersElement.appendChild(importedNode);
    }
}

From source file:com.konakart.bl.modules.ordertotal.thomson.HeaderSecrityHandler.java

public boolean handleMessage(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    if (outboundProperty.booleanValue()) {
        SOAPMessage message = smc.getMessage();

        if (log.isInfoEnabled()) {
            log.info("Adding Credentials : " + getUName() + "/" + getPWord());
        }/*from   w  w w .j a  v  a  2  s. com*/

        try {
            SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
            envelope.setPrefix("soapenv");
            envelope.getBody().setPrefix("soapenv");

            SOAPHeader header = envelope.addHeader();
            SOAPElement security = header.addChildElement("Security", "wsse",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

            SOAPElement usernameToken = security.addChildElement("UsernameToken", "wsse");
            usernameToken.addAttribute(new QName("wsu:Id"), "UsernameToken-1");
            usernameToken.setAttribute("wsu:Id", "UsernameToken-1");

            usernameToken.addAttribute(new QName("xmlns:wsu"),
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

            SOAPElement username = usernameToken.addChildElement("Username", "wsse");
            username.addTextNode(getUName());

            SOAPElement password = usernameToken.addChildElement("Password", "wsse");
            password.setAttribute("Type",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
            password.addTextNode(getPWord());

            SOAPElement encodingType = usernameToken.addChildElement("Nonce", "wsse");
            encodingType.setAttribute("EncodingType",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
            encodingType.addTextNode("Encoding");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return outboundProperty;
}

From source file:edu.unc.lib.dl.services.TripleStoreManagerMulgaraImpl.java

private String sendTQL(String query) {
    log.info(query);//from w ww .  j a v  a2  s  .  c  o  m
    String result = null;
    try {
        // First create the connection
        SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = soapConnFactory.createConnection();

        // Next, create the actual message
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        message.getMimeHeaders().setHeader("SOAPAction", "itqlbean:executeQueryToString");
        SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody();
        soapBody.addNamespaceDeclaration("xsd", JDOMNamespaceUtil.XSD_NS.getURI());
        soapBody.addNamespaceDeclaration("xsi", JDOMNamespaceUtil.XSI_NS.getURI());
        soapBody.addNamespaceDeclaration("itqlbean", this.getItqlEndpointURL());
        SOAPElement eqts = soapBody.addChildElement("executeQueryToString", "itqlbean");
        SOAPElement queryStr = eqts.addChildElement("queryString", "itqlbean");
        queryStr.setAttributeNS(JDOMNamespaceUtil.XSI_NS.getURI(), "xsi:type", "xsd:string");
        CDATASection queryCDATA = message.getSOAPPart().createCDATASection(query);
        queryStr.appendChild(queryCDATA);
        message.saveChanges();
        SOAPMessage reply = connection.call(message, this.getItqlEndpointURL());

        if (reply.getSOAPBody().hasFault()) {
            reportSOAPFault(reply);
            if (log.isDebugEnabled()) {
                // log the full soap body response
                DOMBuilder builder = new DOMBuilder();
                org.jdom.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument());
                log.info(new XMLOutputter().outputString(jdomDoc));
            }
        } else {
            NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*",
                    "executeQueryToStringReturn");
            if (nl.getLength() > 0) {
                result = nl.item(0).getTextContent();
            }
            log.debug(result);
        }
    } catch (SOAPException e) {
        throw new Error("Cannot query triple store at " + this.getItqlEndpointURL(), e);
    }
    return result;
}

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

/**
 * Tests the behavior of {@link SOAPElement#addChildElement(String, String)} when the given
 * prefix is not bound in the context of the parent element.
 * // w  w w .j av  a 2 s  .  co  m
 * @throws Exception
 */
@Validated
@Test(expected = SOAPException.class)
public void testAddChildElementFromLocalNameAndPrefixWithUnboundPrefix() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addChildElement("child", "p");
}

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

@Validated
@Test//from   w  ww.  j  a v a2s.c  o m
public void testAddChildElementFromLocalNameAndPrefix() throws Exception {
    SOAPElement element = saajUtil.createSOAPElement(null, "test", null);
    element.addNamespaceDeclaration("p", "urn:test");
    SOAPElement child = element.addChildElement("child", "p");
    assertEquals("urn:test", child.getNamespaceURI());
    assertEquals("p", child.getPrefix());
    assertEquals("child", child.getLocalName());
}

From source file:edu.unc.lib.dl.util.TripleStoreQueryServiceMulgaraImpl.java

private String sendTQL(String query) {
    log.debug(query);/*from   w  w w  .ja  v  a 2 s. co  m*/
    String result = null;
    SOAPMessage reply = null;
    SOAPConnection connection = null;
    try {
        // Next, create the actual message
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage message = messageFactory.createMessage();
        message.getMimeHeaders().setHeader("SOAPAction", "itqlbean:executeQueryToString");
        SOAPBody soapBody = message.getSOAPPart().getEnvelope().getBody();
        soapBody.addNamespaceDeclaration("xsd", JDOMNamespaceUtil.XSD_NS.getURI());
        soapBody.addNamespaceDeclaration("xsi", JDOMNamespaceUtil.XSI_NS.getURI());
        soapBody.addNamespaceDeclaration("itqlbean", this.getItqlEndpointURL());
        SOAPElement eqts = soapBody.addChildElement("executeQueryToString", "itqlbean");
        SOAPElement queryStr = eqts.addChildElement("queryString", "itqlbean");
        queryStr.setAttributeNS(JDOMNamespaceUtil.XSI_NS.getURI(), "xsi:type", "xsd:string");
        CDATASection queryCDATA = message.getSOAPPart().createCDATASection(query);
        queryStr.appendChild(queryCDATA);
        message.saveChanges();

        // First create the connection
        SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
        connection = soapConnFactory.createConnection();
        reply = connection.call(message, this.getItqlEndpointURL());

        if (reply.getSOAPBody().hasFault()) {
            reportSOAPFault(reply);
            if (log.isDebugEnabled()) {
                // log the full soap body response
                DOMBuilder builder = new DOMBuilder();
                org.jdom2.Document jdomDoc = builder.build(reply.getSOAPBody().getOwnerDocument());
                log.debug(new XMLOutputter().outputString(jdomDoc));
            }
        } else {
            NodeList nl = reply.getSOAPPart().getEnvelope().getBody().getElementsByTagNameNS("*",
                    "executeQueryToStringReturn");
            if (nl.getLength() > 0) {
                result = nl.item(0).getFirstChild().getNodeValue();
            }
            log.debug(result);
        }
    } catch (SOAPException e) {
        log.error("Failed to prepare or send iTQL via SOAP", e);
        throw new RuntimeException("Cannot query triple store at " + this.getItqlEndpointURL(), e);
    } finally {
        try {
            connection.close();
        } catch (SOAPException e) {
            log.error("Failed to close SOAP connection", e);
            throw new RuntimeException(
                    "Failed to close SOAP connection for triple store at " + this.getItqlEndpointURL(), e);
        }
    }
    return result;
}

From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java

private static SOAPMessage createSOAPRequest(String date) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    String serverURI = "http://ws.i-em.eu/v4/";

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", serverURI);

    // SOAP Body/*from   w ww.j  a va  2s  .c o  m*/
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("Get72hPlantForecast", "example");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("plantID", "example");
    soapBodyElem1.addTextNode("telecom_02");
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("quantityID", "example");
    soapBodyElem2.addTextNode("frc_pac");
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("timestamp", "example");
    soapBodyElem3.addTextNode(date);
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("langID", "example");
    soapBodyElem4.addTextNode("en");

    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "Get72hPlantForecast");

    soapMessage.saveChanges();

    return soapMessage;
}

From source file:org.mule.modules.paypal.util.PayPalAPIHelper.java

private static SOAPMessage createGetPalDetailsSOAPRequest(@NotNull String username, @NotNull String password,
        @NotNull String appId, String signature) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();

    envelope.addNamespaceDeclaration(PREFIX_1, SOAP_HEADER_CREDENTIAL_NAMESPACE_1);
    envelope.addNamespaceDeclaration(PREFIX_2, SOAP_HEADER_CREDENTIAL_NAMESPACE_2);

    SOAPHeader soapHeader = envelope.getHeader();
    if (soapHeader == null)
        soapHeader = envelope.addHeader();

    SOAPElement soapReqElement = soapHeader.addChildElement(rootStringValue, PREFIX_1);
    SOAPElement soapCredElement = soapReqElement.addChildElement(subRootStringValue, PREFIX_2);
    soapCredElement.addChildElement(appIdStringValue, PREFIX_2).addTextNode(appId);
    soapCredElement.addChildElement(usernameStringValue, PREFIX_2).addTextNode(username);
    soapCredElement.addChildElement(passwordStringValue, PREFIX_2).addTextNode(password);
    soapCredElement.addChildElement("Signature", PREFIX_2).addTextNode(signature);

    // SOAP Body/*from w  ww .  ja  v  a2 s.c om*/
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetPalDetailsReq", PREFIX_1);
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("GetPalDetailsRequest", PREFIX_1);
    soapBodyElem1.addChildElement("Version", PREFIX_2).addTextNode("51");
    soapMessage.saveChanges();

    return soapMessage;
}