Example usage for javax.xml.soap SOAPBody addTextNode

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

Introduction

In this page you can find the example usage for javax.xml.soap SOAPBody 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.drools.server.CxfSoapClientServerTest.java

@org.junit.Test
public void test1() throws Exception {
    ClassPathXmlApplicationContext springContext = new ClassPathXmlApplicationContext(
            "classpath:beans-test.xml");

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);//from w  ww .ja v  a  2s.  c  om

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"message\">\n";
    cmd += "      <org.drools.server.Message>\n";
    cmd += "         <text>Helllo World</text>\n";
    cmd += "      </org.drools.server.Message>\n";
    cmd += "   </insert>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    CamelServerApp test = new CamelServerApp();
    String response = test.execute(soapMessage, (CamelContext) springContext.getBean("camel-client-ctx"));

    assertTrue(response.contains("execution-results"));
    assertTrue(response.contains("echo"));
    springContext.stop();
}

From source file:org.kie.camel.component.cxf.CxfSoapTest.java

@Test
public void test1() throws Exception {
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);//www. j  a  v  a  2 s .c o m

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.kie.pipeline.camel.Person>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.kie.pipeline.camel.Person>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);
    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));
}

From source file:org.drools.camel.component.cxf.CxfSoapTest.java

@Test
public void test1() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/* ww w  . j a  v a  2s  .  co  m*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.drools.pipeline.camel.Person>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.drools.pipeline.camel.Person>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));
}

From source file:org.kie.camel.component.cxf.CxfSoapTestWithLookup.java

public void testCxfSoapSessionLookup() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);//from  w w  w .ja  va2 s .  c o  m

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.kie.springframework.Person2>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.kie.springframework.Person2>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body2.addBodyElement(payloadName2);

    String cmd2 = "";
    cmd2 += "<batch-execution lookup=\"ksession2\">\n";
    cmd2 += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd2 += "      <org.kie.springframework.Person3>\n";
    cmd2 += "         <name>salaboy</name>\n";
    cmd2 += "         <age>27</age>\n";
    cmd2 += "      </org.kie.springframework.Person3>\n";
    cmd2 += "   </insert>\n";
    cmd2 += "   <fire-all-rules/>\n";
    cmd2 += "</batch-execution>\n";

    body2.addTextNode(cmd2);

    Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2);

    OutputStream out2 = new ByteArrayOutputStream();
    out2 = new ByteArrayOutputStream();
    soapMessage2 = (SOAPMessage) object2;
    soapMessage2.writeTo(out2);
    String response2 = out2.toString();
    assertTrue(response2.contains("fact-handle identifier=\"salaboy\""));

}

From source file:org.drools.camel.component.cxf.CxfSoapTestWithLookup.java

public void testCxfSoapSessionLookup() throws Exception {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*from  w  w w  .ja  va 2  s  .  c o m*/

    String cmd = "";
    cmd += "<batch-execution lookup=\"ksession1\">\n";
    cmd += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd += "      <org.drools.springframework.Person2>\n";
    cmd += "         <name>salaboy</name>\n";
    cmd += "         <age>27</age>\n";
    cmd += "      </org.drools.springframework.Person2>\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);

    Object object = this.context.createProducerTemplate().requestBody("direct://http", soapMessage);

    OutputStream out = new ByteArrayOutputStream();
    out = new ByteArrayOutputStream();
    soapMessage = (SOAPMessage) object;
    soapMessage.writeTo(out);
    String response = out.toString();
    assertTrue(response.contains("fact-handle identifier=\"salaboy\""));

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPBody body2 = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName2 = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body2.addBodyElement(payloadName2);

    String cmd2 = "";
    cmd2 += "<batch-execution lookup=\"ksession2\">\n";
    cmd2 += "  <insert out-identifier=\"salaboy\" disconnected=\"true\">\n";
    cmd2 += "      <org.drools.springframework.Person3>\n";
    cmd2 += "         <name>salaboy</name>\n";
    cmd2 += "         <age>27</age>\n";
    cmd2 += "      </org.drools.springframework.Person3>\n";
    cmd2 += "   </insert>\n";
    cmd2 += "   <fire-all-rules/>\n";
    cmd2 += "</batch-execution>\n";

    body2.addTextNode(cmd2);

    Object object2 = this.context.createProducerTemplate().requestBody("direct://http", soapMessage2);

    OutputStream out2 = new ByteArrayOutputStream();
    out2 = new ByteArrayOutputStream();
    soapMessage2 = (SOAPMessage) object2;
    soapMessage2.writeTo(out2);
    String response2 = out2.toString();
    assertTrue(response2.contains("fact-handle identifier=\"salaboy\""));

}

From source file:org.drools.server.CxfSoapClientServerGridTest.java

private SOAPMessage createMessageForKsession(String ksessionName) throws SOAPException {

    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
    QName payloadName = new QName("http://soap.jax.drools.org", "execute", "ns1");

    body.addBodyElement(payloadName);/*  www.  j a v a2  s  .  c  o m*/
    String add = "";
    String packages = "org.test";
    if (ksessionName.equals("ksession2")) {
        add = "2";
        packages = "org.grid.test";
    }
    String cmd = "";
    cmd += "<batch-execution lookup=\"" + ksessionName + "\">\n";
    cmd += "  <insert out-identifier=\"message\">\n";
    cmd += "      <" + packages + ".Message" + add + ">\n";
    cmd += "         <text>Helllo World" + ksessionName + "</text>\n";
    cmd += "      </" + packages + ".Message" + add + ">\n";
    cmd += "   </insert>\n";
    cmd += "   <fire-all-rules/>\n";
    cmd += "</batch-execution>\n";

    body.addTextNode(cmd);
    OutputStream os = new ByteArrayOutputStream();
    try {
        soapMessage.writeTo(os);
    } catch (IOException ex) {
        Logger.getLogger(CxfSoapClientServerGridTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    //System.out.println("SOAP = "+os.toString());
    return soapMessage;

}

From source file:org.wso2.carbon.identity.sso.saml.util.SAMLSOAPUtils.java

/**
 *
 * @param samlRes SAML Response/*  w  w w. jav a  2  s. c om*/
 * @param acUrl Assertion Consumer URL
 * @return
 */
public static String createSOAPMessage(String samlRes, String acUrl)
        throws TransformerException, SOAPException {
    SOAPMessage soapMsg;
    MessageFactory factory = MessageFactory.newInstance();
    soapMsg = factory.createMessage();
    SOAPPart part = soapMsg.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPHeaderElement soapHeaderElement = header.addHeaderElement(
            envelope.createName(SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_LOCAL_NAME,
                    SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_PREFIX,
                    SAMLECPConstants.SOAPECPHeaderElements.SOAP_ECP_HEADER_URI));
    soapHeaderElement.setMustUnderstand(true);
    soapHeaderElement.setActor(SAMLECPConstants.SOAPHeaderElements.SOAP_HEADER_ELEMENT_ACTOR);
    soapHeaderElement.addAttribute(new QName(SAMLECPConstants.SOAPHeaderElements.SOAP_HEADER_ELEMENT_ACS_URL),
            acUrl);
    SOAPBody body = envelope.getBody();
    String rawxml = "<![CDATA[" + samlRes + "]]>";
    body.addTextNode(rawxml);
    return convertSOAPMsgToString(soapMsg).replace("<![CDATA[", "").replace("]]>", "");
}