use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.
the class DispatchClientServerTest method testDOMSourceMESSAGE.
@Test
public void testDOMSourceMESSAGE() throws Exception {
/*URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, serviceName);
assertNotNull(service);*/
Service service = Service.create(SERVICE_NAME);
assertNotNull(service);
service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class, Service.Mode.MESSAGE);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPPart());
assertNotNull(domReqMsg);
DOMSource domResMsg = disp.invoke(domReqMsg);
assertNotNull(domResMsg);
String expected = "Hello TestSOAPInputMessage";
assertEquals("Response should be : Hello TestSOAPInputMessage", expected, DOMUtils.getAllContent(domResMsg.getNode().getFirstChild()).trim());
Element el = (Element) domResMsg.getNode().getFirstChild();
assertEquals("gmns", el.lookupPrefix("http://apache.org/hello_world_soap_http/types"));
assertEquals("http://apache.org/hello_world_soap_http/types", el.lookupNamespaceURI("gmns"));
// Test invoke oneway
InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPPart());
assertNotNull(domReqMsg1);
disp.invokeOneWay(domReqMsg1);
// Test async polling
InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
SOAPMessage soapReqMsg2 = MessageFactory.newInstance().createMessage(null, is2);
DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPPart());
assertNotNull(domReqMsg2);
Response<DOMSource> response = disp.invokeAsync(domReqMsg2);
DOMSource domRespMsg2 = response.get();
assertNotNull(domReqMsg2);
String expected2 = "Hello TestSOAPInputMessage2";
assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, domRespMsg2.getNode().getFirstChild().getTextContent().trim());
// Test async callback
InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPPart());
assertNotNull(domReqMsg3);
TestDOMSourceHandler tdsh = new TestDOMSourceHandler();
Future<?> fd = disp.invokeAsync(domReqMsg3, tdsh);
assertNotNull(fd);
waitForFuture(fd);
String expected3 = "Hello TestSOAPInputMessage3";
assertEquals("Response should be : Hello TestSOAPInputMessage3", expected3, tdsh.getReplyBuffer().trim());
}
use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.
the class DispatchClientServerTest method testSOAPMessageInvokeToOneWay.
@Test
public void testSOAPMessageInvokeToOneWay() throws Exception {
SOAPService service = new SOAPService(null, SERVICE_NAME);
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
// message is "one way", but there really isn't a way for us to know that
// as we don't have a wsdl or other source of operation information to
// compare the payload to.
InputStream is1 = getClass().getResourceAsStream("resources/GreetMe1WDocLiteralReq2.xml");
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
assertNotNull(soapReqMsg1);
// Version 1:
// we'll just call invoke
disp.invoke(soapReqMsg1);
// Version 2:
// We want to handle things asynchronously
AsyncHandler<SOAPMessage> callback = new AsyncHandler<SOAPMessage>() {
public void handleResponse(Response<SOAPMessage> res) {
synchronized (this) {
notifyAll();
}
}
};
synchronized (callback) {
disp.invokeAsync(soapReqMsg1, callback);
callback.wait();
}
}
use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.
the class DispatchClientServerTest method testCreateDispatchWithEPR.
@Test
public void testCreateDispatchWithEPR() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
assertNotNull(service);
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
builder.address("http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
builder.serviceName(SERVICE_NAME);
builder.endpointName(PORT_NAME);
W3CEndpointReference w3cEpr = builder.build();
Dispatch<SOAPMessage> disp = service.createDispatch(w3cEpr, SOAPMessage.class, Service.Mode.MESSAGE);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
SOAPMessage soapResMsg = disp.invoke(soapReqMsg);
assertNotNull(soapResMsg);
String expected = "Hello TestSOAPInputMessage";
assertEquals("Response should be : Hello TestSOAPInputMessage", expected, DOMUtils.getAllContent(SAAJUtils.getBody(soapResMsg)).trim());
}
use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.
the class DispatchClientServerTest method testStreamSourcePAYLOADWithSchemaValidation.
@Test
public void testStreamSourcePAYLOADWithSchemaValidation() throws Exception {
URL wsdl = getClass().getResource("/org/apache/cxf/systest/provider/hello_world_with_restriction.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
assertNotNull(service);
Dispatch<StreamSource> disp = service.createDispatch(PORT_NAME, StreamSource.class, Service.Mode.PAYLOAD);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
disp.getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReqExceedMaxLength.xml");
StreamSource streamSourceReq = new StreamSource(is);
assertNotNull(streamSourceReq);
try {
disp.invoke(streamSourceReq);
fail("Should have thrown an exception");
} catch (Exception ex) {
// expected
assertTrue(ex.getMessage().contains("cvc-maxLength-valid"));
}
is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
streamSourceReq = new StreamSource(is);
assertNotNull(streamSourceReq);
StreamSource streamSourceResp = disp.invoke(streamSourceReq);
assertNotNull(streamSourceResp);
String expected = "Hello TestSOAPInputMessage";
assertTrue("Expected: " + expected, StaxUtils.toString(streamSourceResp).contains(expected));
}
use of org.apache.hello_world_soap_http.SOAPService in project cxf by apache.
the class DispatchClientServerTest method testJAXBObjectPAYLOADFromEPR.
@Test
public void testJAXBObjectPAYLOADFromEPR() throws Exception {
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
assertNotNull(service);
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
builder.address("http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
builder.serviceName(SERVICE_NAME);
builder.endpointName(PORT_NAME);
W3CEndpointReference w3cEpr = builder.build();
JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_soap_http.types");
Dispatch<Object> disp = service.createDispatch(w3cEpr, jc, Service.Mode.PAYLOAD, new AddressingFeature());
doJAXBPayload(disp);
}
Aggregations