Example usage for javax.xml.soap SOAPElement addTextNode

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

Introduction

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

Prototype

public SOAPElement addTextNode(String text) throws SOAPException;

Source Link

Document

Creates a new Text object initialized with the given String and adds it to this SOAPElement object.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = sfc.createConnection();

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage sm = mf.createMessage();

    SOAPHeader sh = sm.getSOAPHeader();
    SOAPBody sb = sm.getSOAPBody();
    sh.detachNode();/*from ww  w. ja va2  s. c  o m*/
    QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d");
    SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);
    QName qn = new QName("aName");
    SOAPElement quotation = bodyElement.addChildElement(qn);

    quotation.addTextNode("TextMode");

    System.out.println("\n Soap Request:\n");
    sm.writeTo(System.out);
    System.out.println();

    URL endpoint = new URL("http://yourServer.com");
    SOAPMessage response = connection.call(sm, endpoint);
    System.out.println(response.getContentDescription());
}

From source file:SOAPRequest.java

public static void main(String[] args) {
    try {/*from  w w w . ja  va  2  s .c  o  m*/
        SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = sfc.createConnection();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage sm = mf.createMessage();

        SOAPHeader sh = sm.getSOAPHeader();
        SOAPBody sb = sm.getSOAPBody();
        sh.detachNode();
        QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d");
        SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);
        QName qn = new QName("aName");
        SOAPElement quotation = bodyElement.addChildElement(qn);

        quotation.addTextNode("TextMode");

        System.out.println("\n Soap Request:\n");
        sm.writeTo(System.out);
        System.out.println();

        URL endpoint = new URL("http://yourServer.com");
        SOAPMessage response = connection.call(sm, endpoint);
        System.out.println(response.getContentDescription());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.vab.iflex.gateway.paybillservice.Stub.java

/**
 * @param accesskey// w ww. j  a v  a 2 s. co  m
 * @param partnercode
 * @param signature
 * @return
 * <securityHeader><accesskey></accesskey><timestamp></timestamp><signature
 * ></signature></securityHeader>
 */
public static SOAPHeaderElement setSoapHeaderElement(String accesskey, String method, String signature)
        throws Exception {
    SOAPHeaderElement oHeaderElement;
    javax.xml.soap.SOAPElement oElement;

    try {
        oHeaderElement = new SOAPHeaderElement("http://phn.com.vn", "securityHeader");
        oHeaderElement.setPrefix("sec");
        oHeaderElement.setMustUnderstand(false);

        Date now = new Date();
        SimpleDateFormat sdate = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        String sDateNow = sdate.format(now);

        String signnow = calculateRFC2104HMAC(method + sDateNow, signature);

        oElement = oHeaderElement.addChildElement("accesskey");
        oElement.addTextNode(accesskey);
        oElement = oHeaderElement.addChildElement("timestamp");
        oElement.addTextNode(sDateNow);
        oElement = oHeaderElement.addChildElement("signature");
        oElement.addTextNode(signnow);

        return oHeaderElement;
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:eu.planets_project.tb.gui.backing.admin.wsclient.util.WSClient.java

/**
 * Builds a hierarchy of SOAPElements given a complex value JDOM Element
 *
 * @param   envelope   The SOAP Envelope
 * @param   rootElem   The root SOAP Element to build content for
 * @param   jdomElem   A JDOM Element that represents a complex value
 * @param   isRPC      Pass true when building for RPC encoded messages
 *
 * @throws SOAPException/*from  w w w. j a  v a2  s .com*/
 */
protected static void buildSoapElement(SOAPEnvelope envelope, SOAPElement soapElem, Element jdomElem,
        boolean isRPC) throws SOAPException {
    // If the source node has text use its value
    String elemText = jdomElem.getText();

    if (elemText != null) {
        if (isRPC == true) {
            // Set the type attribute for this element
            String type = jdomElem.getAttributeValue("type");

            if (type != null) {
                soapElem.addAttribute(envelope.createName(XSI_NAMESPACE_PREFIX + ":type"),
                        XSD_NAMESPACE_PREFIX + ":" + type);
            }
        }

        // Add the element text value
        soapElem.addTextNode(elemText);
    }

    // If the source node has attributes add the attribute values
    List attrs = jdomElem.getAttributes();

    if (attrs != null) {
        Iterator attrIter = attrs.iterator();

        while (attrIter.hasNext()) {
            // Get the attribute to add
            Attribute attr = (Attribute) attrIter.next();

            // Create a name for the attribute
            Name attrName = envelope.createName(attr.getName(), attr.getNamespacePrefix(),
                    attr.getNamespaceURI());

            // Add the attribute and its value to the element
            soapElem.addAttribute(attrName, attr.getValue());
        }
    }

    // Build children
    List children = jdomElem.getChildren();

    if (children != null) {
        Iterator childIter = children.iterator();

        while (childIter.hasNext()) {
            Element jdomChildElem = (Element) childIter.next();

            // Create a new SOAPElement as a child of the current one
            //SOAPElement soapChildElem = soapElem.addChildElement(jdomChildElem.getName());
            SOAPElement soapChildElem = soapElem.addChildElement(jdomChildElem.getName(),
                    jdomChildElem.getNamespacePrefix(), jdomChildElem.getNamespaceURI());

            // Build it
            buildSoapElement(envelope, soapChildElem, jdomChildElem, isRPC);
        }
    }
}

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 ww .j a  v  a2s . c  om
    <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: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();//w  w w.j av  a2 s. co  m

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

From source file:com.profesorfalken.payzen.webservices.sdk.handler.soap.HeaderHandler.java

private void addHeaderField(SOAPHeader header, String fieldName, String value) throws SOAPException {
    QName qname = new QName(NAMESPACE, fieldName);
    SOAPElement element = header.addChildElement(qname);
    element.addTextNode(value);
}

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());
        }/* ww  w  . j  a va  2  s  .c  o  m*/

        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:SendSOAPMessage.java

/**
 * send a simple soap message with JAXM API.
 *//*from   w  ww  .  j  a  v  a2 s  . c  o m*/
public void sendMessage(String url) {

    try {
        /**
         * Construct a default SOAP message factory.
         */
        MessageFactory mf = MessageFactory.newInstance();
        /**
         * Create a SOAP message object.
         */
        SOAPMessage soapMessage = mf.createMessage();
        /**
         * Get SOAP part.
         */
        SOAPPart soapPart = soapMessage.getSOAPPart();
        /**
         * Get SOAP envelope.
         */
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();

        /**
         * Get SOAP body.
         */
        SOAPBody soapBody = soapEnvelope.getBody();

        /**
         * Add child element with the specified name.
         */
        SOAPElement element = soapBody.addChildElement("HelloWorld");

        /**
         * Add text message
         */
        element.addTextNode("Welcome to SunOne Web Services!");

        soapMessage.saveChanges();

        /**
         * Construct a default SOAP connection factory.
         */
        SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();

        /**
         * Get SOAP connection.
         */
        SOAPConnection soapConnection = connectionFactory.createConnection();

        /**
         * Construct endpoint object.
         */
        URLEndpoint endpoint = new URLEndpoint(url);

        /**
         * Send SOAP message.
         */
        SOAPMessage resp = soapConnection.call(soapMessage, endpoint);

        /**
         * Print response to the std output.
         */
        resp.writeTo(System.out);

        /**
         * close the connection
         */
        soapConnection.close();

    } catch (java.io.IOException ioe) {
        ioe.printStackTrace();
    } catch (SOAPException soape) {
        soape.printStackTrace();
    }
}

From source file:backend.Weather.java

private SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = "http://ws.cdyne.com/";
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetCityWeatherByZIP");
    QName attributeName = new QName("xmlns");
    soapBodyElem.addAttribute(attributeName, "http://ws.cdyne.com/WeatherWS/");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ZIP");
    soapBodyElem1.addTextNode("02215");
    soapMessage.saveChanges();//  w  w w .ja va  2  s.  c o  m
    return soapMessage;

}