List of usage examples for javax.xml.soap MessageFactory newInstance
public static MessageFactory newInstance() throws SOAPException
From source file:net.sf.sripathi.ws.mock.util.WebServiceutil.java
/** * Invokes the web service using SAAJ API. * //from w ww . j a v a2s . co m * @param request soap request string. * @param url end point URL. * @param user user name for authentication. * @param password password for authentication. * * @return response soap string. */ public static String callWebService(String request, String url, String user, String password) { if (request == null) request = ""; try { SOAPConnection conn = SOAPConnectionFactory.newInstance().createConnection(); MimeHeaders hd = new MimeHeaders(); hd.addHeader("Content-Type", "text/xml"); if (StringUtil.isValid(user) && StringUtil.isValid(password)) { String authorization = new String(Base64.encodeBase64((user + ":" + password).getBytes())); hd.addHeader("Authorization", "Basic " + authorization); } SOAPMessage msg = MessageFactory.newInstance().createMessage(hd, new ByteArrayInputStream(request.getBytes())); SOAPMessage resp = conn.call(msg, url); ByteArrayOutputStream baos = new ByteArrayOutputStream(); resp.writeTo(baos); return new String(baos.toByteArray()); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); return sw.toString(); } }
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 w w . j a v a 2 s .c o m*/ 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:net.bpelunit.framework.model.test.wire.IncomingMessage.java
public void setMessage(InputStream in) { try {/*from w ww .ja v a2 s . co m*/ message = MessageFactory.newInstance().createMessage(null, in); } catch (IOException e) { message = null; } catch (SOAPException e) { message = null; } finally { IOUtils.closeQuietly(in); } }
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);/*w w w . j a v a2 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);/*from w w w . jav a 2 s . com*/ 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:net.bpelunit.framework.control.util.BPELUnitUtil.java
/** * Creates a new, generic SOAP fault to be used when something goes wrong in a partner track and * other tracks must be notified.//from ww w. j a v a2s. c om * * @return */ public static SOAPMessage generateGenericSOAPFault() { try { MessageFactory mFactory = MessageFactory.newInstance(); SOAPMessage message = mFactory.createMessage(); SOAPBody body = message.getSOAPBody(); SOAPFault fault = body.addFault(BPELUnitConstants.SOAP_FAULT_CODE_CLIENT, BPELUnitConstants.SOAP_FAULT_DESCRIPTION); Detail detail = fault.addDetail(); DetailEntry entry = detail .addDetailEntry(new QName("http://www.bpelunit.org/framework/error", "BPELUnitFault")); entry.addTextNode( "The BPELUnit test framework has detected a test failure or error. This test case is aborted."); return message; } catch (Exception e) { return null; } }
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 . j av a 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.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);// w ww . ja va2 s .c om 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:SendSOAPMessage.java
/** * send a simple soap message with JAXM API. *//*w w w. j a v a 2 s . co 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:org.jasig.portlet.calendar.adapter.exchange.ExchangeWebServiceCallBackTest.java
@Before public void setUp() throws IOException, SOAPException { initMocks(this); testee = new ExchangeWebServiceCallBack(actionCallbackType, requestServerVersion, impersonatedUser); File soapFile = new File("src/test/resources/TestGetAvailabilitySoapMessage.xml"); InputStream is = new ByteArrayInputStream(FileUtils.readFileToString(soapFile).getBytes()); request = new SaajSoapMessageFactory(MessageFactory.newInstance()).createWebServiceMessage(is); outStream = new ByteArrayOutputStream(); }