use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class HandlerInvocationTest method testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers.
@Test
public void testServerSOAPInboundHandlerThrowsSOAPFaultToClientHandlers() throws Exception {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleFault(LogicalMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
LogicalMessage msg = ctx.getMessage();
Source source = msg.getPayload();
assertNotNull(source);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
try {
SOAPMessage msg = ctx.getMessage();
assertNotNull(msg);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("soapHandler3 inbound throw SOAPFaultException");
fail("did not get expected SOAPFaultException");
} catch (SOAPFaultException e) {
// e.printStackTrace();
/* ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos, true);
e.printStackTrace(ps);
assertTrue("Did not get expected exception message", baos.toString()
.indexOf("HandleMessage throws exception") > -1);
assertTrue("Did not get expected javax.xml.ws.soap.SOAPFaultException", baos.toString()
.indexOf("javax.xml.ws.soap.SOAPFaultException") > -1);*/
}
/* assertEquals("handle message was not invoked", 1, handler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, handler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, soapHandler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, soapHandler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 1, handler1.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, handler2.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, soapHandler1.getHandleFaultInvoked());
assertEquals("handle message was not invoked", 1, soapHandler2.getHandleFaultInvoked());
assertEquals("close must be called", 1, handler1.getCloseInvoked());
assertEquals("close must be called", 1, handler2.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());
assertTrue(soapHandler2.getInvokeOrderOfClose()
< soapHandler1.getInvokeOrderOfClose());
assertTrue(soapHandler1.getInvokeOrderOfClose()
< handler2.getInvokeOrderOfClose());
assertTrue(handler2.getInvokeOrderOfClose()
< handler1.getInvokeOrderOfClose()); */
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class HandlerInvocationUsingAddNumbersTest method testInvokeFromDispatchWithJAXBPayload.
@Test
public void testInvokeFromDispatchWithJAXBPayload() throws Exception {
URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
assertNotNull(wsdl);
AddNumbersService service = new AddNumbersService(wsdl, serviceName);
assertNotNull(service);
JAXBContext jc = JAXBContext.newInstance("org.apache.handlers.types");
Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
setAddress(disp, addNumbersAddress);
SmallNumberHandler sh = new SmallNumberHandler();
TestSOAPHandler soapHandler = new TestSOAPHandler(false) {
public boolean handleMessage(SOAPMessageContext ctx) {
super.handleMessage(ctx);
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
try {
SOAPMessage msg = ctx.getMessage();
// System.out.println("aaaaaaaaaaaa");
// msg.writeTo(System.out);
assertNotNull(msg);
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
return true;
}
};
addHandlersProgrammatically(disp, sh, soapHandler);
org.apache.handlers.types.AddNumbers req = new org.apache.handlers.types.AddNumbers();
req.setArg0(10);
req.setArg1(20);
ObjectFactory factory = new ObjectFactory();
JAXBElement<org.apache.handlers.types.AddNumbers> e = factory.createAddNumbers(req);
JAXBElement<?> response = (JAXBElement<?>) disp.invoke(e);
assertNotNull(response);
AddNumbersResponse value = (AddNumbersResponse) response.getValue();
assertEquals(200, value.getReturn());
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class DispatchClientServerTest method testDOMSourcePAYLOAD.
@Test
public void testDOMSourcePAYLOAD() 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.PAYLOAD);
InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPBody().extractContentAsDocument());
assertNotNull(domReqMsg);
// invoke
DOMSource domResMsg = disp.invoke(domReqMsg);
assertNotNull(domResMsg);
String expected = "Hello TestSOAPInputMessage";
Node node = domResMsg.getNode();
assertNotNull(node);
if (node instanceof Document) {
node = ((Document) node).getDocumentElement();
}
String content = node.getTextContent();
assertNotNull(content);
assertEquals("Response should be : Hello TestSOAPInputMessage", expected, content.trim());
InputStream is1 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq1.xml");
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPBody().extractContentAsDocument());
assertNotNull(domReqMsg1);
// invokeOneWay
disp.invokeOneWay(domReqMsg1);
InputStream is2 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq2.xml");
SOAPMessage soapReqMsg2 = MessageFactory.newInstance().createMessage(null, is2);
DOMSource domReqMsg2 = new DOMSource(soapReqMsg2.getSOAPBody().extractContentAsDocument());
assertNotNull(domReqMsg2);
// invokeAsync
Response<DOMSource> response = disp.invokeAsync(domReqMsg2);
DOMSource domRespMsg2 = response.get();
assertNotNull(domRespMsg2);
String expected2 = "Hello TestSOAPInputMessage2";
node = domRespMsg2.getNode();
assertNotNull(node);
if (node instanceof Document) {
node = ((Document) node).getDocumentElement();
}
content = node.getTextContent();
assertNotNull(content);
assertEquals("Response should be : Hello TestSOAPInputMessage2", expected2, content.trim());
InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
DOMSource domReqMsg3 = new DOMSource(soapReqMsg3.getSOAPBody().extractContentAsDocument());
assertNotNull(domReqMsg3);
// invokeAsync with AsyncHandler
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 javax.xml.soap.SOAPMessage in project cxf by apache.
the class DispatchClientServerWithHugeResponseTest method testStackOverflowErrorForSOAPMessageWithHugeResponse.
@Test
public void testStackOverflowErrorForSOAPMessageWithHugeResponse() throws Exception {
HugeResponseInterceptor hugeResponseInterceptor = new HugeResponseInterceptor(ResponseInterceptorType.overflow);
getBus().getInInterceptors().add(hugeResponseInterceptor);
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
StaxUtils.setInnerElementCountThreshold(12);
StaxUtils.setInnerElementLevelThreshold(12);
InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
assertNotNull(soapReqMsg3);
Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
try {
response.get(300, TimeUnit.SECONDS);
} catch (TimeoutException te) {
fail("We should not have encountered a timeout, " + "should get some exception tell me stackoverflow");
} catch (Throwable e) {
assertTrue(e.getCause() instanceof StackOverflowError);
} finally {
getBus().getInInterceptors().remove(hugeResponseInterceptor);
}
}
use of javax.xml.soap.SOAPMessage in project cxf by apache.
the class DispatchClientServerWithHugeResponseTest method testElementCountThresholdfForSOAPMessageWithHugeResponse.
@Test
public void testElementCountThresholdfForSOAPMessageWithHugeResponse() throws Throwable {
HugeResponseInterceptor hugeResponseInterceptor = new HugeResponseInterceptor(ResponseInterceptorType.ElementCountThreshold);
getBus().getInInterceptors().add(hugeResponseInterceptor);
URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
assertNotNull(wsdl);
SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
assertNotNull(service);
Dispatch<SOAPMessage> disp = service.createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
StaxUtils.setInnerElementCountThreshold(12);
StaxUtils.setInnerElementLevelThreshold(12);
InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
assertNotNull(soapReqMsg3);
Response<SOAPMessage> response = disp.invokeAsync(soapReqMsg3);
try {
response.get(300, TimeUnit.SECONDS);
fail("should catch exception");
} catch (TimeoutException te) {
fail("We should not have encountered a timeout, " + "should get some exception tell me stackoverflow");
} catch (ExecutionException e) {
if (e.getCause() == null) {
throw e;
}
Throwable t = e.getCause();
if (t instanceof SoapFault) {
SoapFault sf = (SoapFault) e.getCause();
if (sf.getCause() == null) {
throw e;
}
t = sf.getCause();
}
if (t.getMessage() == null) {
throw e;
}
String msg = t.getMessage();
assertTrue(msg, msg.startsWith("reach the innerElementCountThreshold") || msg.contains("Maximum Number of Child Elements"));
} finally {
getBus().getInInterceptors().remove(hugeResponseInterceptor);
}
}
Aggregations