use of javax.xml.soap.MessageFactory in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcMessageModeXMLBinding.
@Test
public void testInvokeWithDOMSourcMessageModeXMLBinding() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
XMLService service = new XMLService();
assertNotNull(service);
Dispatch<DOMSource> disp = service.createDispatch(portNameXML, DOMSource.class, Mode.MESSAGE);
setAddress(disp, addNumbersAddress);
TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
addHandlersProgrammatically(disp, handler);
InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage(null, is);
DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
DOMSource response = disp.invoke(domReqMessage);
assertNotNull(response);
}
use of javax.xml.soap.MessageFactory in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithSOAPMessagePayloadMode.
@Test
public void testInvokeWithSOAPMessagePayloadMode() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class, Mode.PAYLOAD);
setAddress(disp, addNumbersAddress);
TestHandler handler = new TestHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler();
addHandlersProgrammatically(disp, handler, soapHandler);
InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage(null, is2);
try {
disp.invoke(soapReq);
fail("Did not get expected exception");
} catch (SOAPFaultException e) {
assertTrue("Did not get expected exception message: " + e.getMessage(), e.getMessage().indexOf("is not valid in PAYLOAD mode with SOAP/HTTP binding") > -1);
}
}
use of javax.xml.soap.MessageFactory in project cxf by apache.
the class DispatchHandlerInvocationTest method testInvokeWithDOMSourcPayloadMode.
@Test
public void testInvokeWithDOMSourcPayloadMode() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
assertNotNull(service);
Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.PAYLOAD);
setAddress(disp, addNumbersAddress);
TestHandler handler = new TestHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler();
addHandlersProgrammatically(disp, handler, soapHandler);
InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReqPayload.xml");
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapReq = factory.createMessage(null, is2);
DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
DOMSource response = disp.invoke(domReqMessage);
assertNotNull(response);
}
use of javax.xml.soap.MessageFactory in project cxf by apache.
the class CXF4130Provider method invoke.
public SOAPMessage invoke(SOAPMessage request) {
try {
Node node = DOMUtils.getFirstElement(SAAJUtils.getBody(request));
String requestMsgName = node.getLocalName();
String responseText = null;
if ("FooRequest".equals(requestMsgName)) {
responseText = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<SOAP-ENV:Header>" + "<FooResponseHeader xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">" + "FooResponseHeader</FooResponseHeader>" + "</SOAP-ENV:Header>" + "<SOAP-ENV:Body>" + "<ns2:FooResponse xmlns:ns2=\"http://cxf.apache.org/soapheader/inband\">" + "<ns2:Return>Foo Response Body</ns2:Return>" + "</ns2:FooResponse>" + "</SOAP-ENV:Body>" + "</SOAP-ENV:Envelope>\n";
} else {
throw new WebServiceException("Error in InBand Provider JAX-WS service -- Unknown Request: " + requestMsgName);
}
// Create a SOAP request message
MessageFactory soapmsgfactory = MessageFactory.newInstance();
SOAPMessage responseMessage = soapmsgfactory.createMessage();
StreamSource responseMessageSrc = null;
responseMessageSrc = new StreamSource(new StringReader(responseText));
responseMessage.getSOAPPart().setContent(responseMessageSrc);
responseMessage.saveChanges();
return responseMessage;
} catch (Exception e) {
throw new WebServiceException(e);
}
}
use of javax.xml.soap.MessageFactory in project cxf by apache.
the class ProviderRPCClientServerTest method testSWA.
@Test
public void testSWA() throws Exception {
SOAPFactory soapFac = SOAPFactory.newInstance();
MessageFactory msgFac = MessageFactory.newInstance();
SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
SOAPMessage msg = msgFac.createMessage();
QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach");
msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
AttachmentPart ap1 = msg.createAttachmentPart();
ap1.setContent("Attachment content", "text/plain");
msg.addAttachmentPart(ap1);
AttachmentPart ap2 = msg.createAttachmentPart();
ap2.setContent("Attachment content - Part 2", "text/plain");
msg.addAttachmentPart(ap2);
msg.saveChanges();
SOAPConnection con = conFac.createConnection();
URL endpoint = new URL("http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
SOAPMessage response = con.call(msg, endpoint);
QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
assertEquals(2, response.countAttachments());
}
Aggregations