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:org.wso2.carbon.identity.provisioning.connector.UserUpdation.java

private static SOAPMessage createUserObject(String userId, String serviceId, String loginId, String login,
        String firstName, String name, String mail, String phone, String status, String role,
        String extraFields) throws SOAPException, IdentityProvisioningException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = InweboConnectorConstants.INWEBO_URI;
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("con", serverURI);
    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("loginUpdate", "con");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("userid", "con");
    soapBodyElem1.addTextNode(userId);
    SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("serviceid", "con");
    soapBodyElem2.addTextNode(serviceId);
    SOAPElement soapBodyElem3 = soapBodyElem.addChildElement("loginid", "con");
    soapBodyElem3.addTextNode(loginId);//from   ww w  .j a v a 2 s  .c o  m
    SOAPElement soapBodyElem4 = soapBodyElem.addChildElement("login", "con");
    soapBodyElem4.addTextNode(login);
    SOAPElement soapBodyElem5 = soapBodyElem.addChildElement("firstname", "con");
    soapBodyElem5.addTextNode(firstName);
    SOAPElement soapBodyElem6 = soapBodyElem.addChildElement("name", "con");
    soapBodyElem6.addTextNode(name);
    SOAPElement soapBodyElem7 = soapBodyElem.addChildElement("mail", "con");
    soapBodyElem7.addTextNode(mail);
    SOAPElement soapBodyElem8 = soapBodyElem.addChildElement("phone", "con");
    soapBodyElem8.addTextNode(phone);
    SOAPElement soapBodyElem9 = soapBodyElem.addChildElement("status", "con");
    soapBodyElem9.addTextNode(status);
    SOAPElement soapBodyElem10 = soapBodyElem.addChildElement("role", "con");
    soapBodyElem10.addTextNode(role);
    SOAPElement soapBodyElem11 = soapBodyElem.addChildElement("extrafields", "con");
    soapBodyElem11.addTextNode(extraFields);
    MimeHeaders headers = soapMessage.getMimeHeaders();
    headers.addHeader("SOAPAction", serverURI + "/services/ConsoleAdmin");
    soapMessage.saveChanges();
    return soapMessage;
}

From source file:test.functional.TestJAXMSamples.java

public void testJWSFault() throws Exception {
    try {/*from ww w .j  a  v  a 2s .com*/
        SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection con = scFactory.createConnection();

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message = factory.createMessage();

        SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
        SOAPBody body = envelope.getBody();

        Name bodyName = envelope.createName("echo");
        SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

        Name name = envelope.createName("arg0");
        SOAPElement symbol = bodyElement.addChildElement(name);
        symbol.addTextNode("Hello");

        URLEndpoint endpoint = new URLEndpoint("http://localhost:8080/jws/FaultTest.jws");
        SOAPMessage response = con.call(message, endpoint);
        SOAPBody respBody = response.getSOAPPart().getEnvelope().getBody();
        assertTrue(respBody.hasFault());
    } catch (javax.xml.soap.SOAPException e) {
        Throwable t = e.getCause();
        if (t != null) {
            t.printStackTrace();
            if (t instanceof AxisFault) {
                AxisFault af = (AxisFault) t;
                if ((af.detail instanceof SocketException)
                        || (af.getFaultCode().getLocalPart().equals("HTTP"))) {
                    System.out.println("Connect failure caused testJWSFault to be skipped.");
                    return;
                }
            }
            throw new Exception("Fault returned from test: " + t);
        } else {
            e.printStackTrace();
            throw new Exception("Exception returned from test: " + e);
        }
    } catch (Throwable t) {
        t.printStackTrace();
        throw new Exception("Fault returned from test: " + t);
    }
}

From source file:test.saaj.TestAttachmentSerialization.java

public int saveMsgWithAttachments(OutputStream os) throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage msg = mf.createMessage();

    SOAPPart sp = msg.getSOAPPart();
    SOAPEnvelope envelope = sp.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();

    SOAPElement el = header.addHeaderElement(envelope.createName("field4", NS_PREFIX, NS_URI));
    SOAPElement el2 = el.addChildElement("field4b", NS_PREFIX);
    SOAPElement el3 = el2.addTextNode("field4value");

    el = body.addBodyElement(envelope.createName("bodyfield3", NS_PREFIX, NS_URI));
    el2 = el.addChildElement("bodyfield3a", NS_PREFIX);
    el2.addTextNode("bodyvalue3a");
    el2 = el.addChildElement("bodyfield3b", NS_PREFIX);
    el2.addTextNode("bodyvalue3b");
    el2 = el.addChildElement("datefield", NS_PREFIX);

    AttachmentPart ap = msg.createAttachmentPart();
    ap.setContent("some attachment text...", "text/plain");
    msg.addAttachmentPart(ap);//w ww.  j  a v a2s  .com

    String jpgfilename = "docs/images/axis.jpg";
    File myfile = new File(jpgfilename);
    FileDataSource fds = new FileDataSource(myfile);
    DataHandler dh = new DataHandler(fds);
    AttachmentPart ap2 = msg.createAttachmentPart(dh);
    ap2.setContentType("image/jpg");
    msg.addAttachmentPart(ap2);

    // Test for Bug #17664
    if (msg.saveRequired()) {
        msg.saveChanges();
    }
    MimeHeaders headers = msg.getMimeHeaders();
    assertTrue(headers != null);
    String[] contentType = headers.getHeader("Content-Type");
    assertTrue(contentType != null);

    msg.writeTo(os);
    os.flush();
    return msg.countAttachments();
}