use of org.apache.handler_test.HandlerTest in project cxf by apache.
the class HandlerInvocationTest method setUp.
@Before
public void setUp() throws Exception {
super.createBus();
wsdl = HandlerInvocationTest.class.getResource("/wsdl/handler_test.wsdl");
service = new HandlerTestService(wsdl, serviceName);
handlerTest = service.getPort(portName, HandlerTest.class);
setAddress(handlerTest, "http://localhost:" + port + "/HandlerTest/SoapPort");
}
use of org.apache.handler_test.HandlerTest in project cxf by apache.
the class HandlerInvocationTest method testServerEndpointRemoteFault.
@Test
public void testServerEndpointRemoteFault() throws PingException {
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();
String payload = convertDOMToString(msg.getPayload());
assertTrue(payload.indexOf("<faultstring>" + "servant throws SOAPFaultException" + "</faultstring>") > -1);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
private String convertDOMToString(Source s) throws TransformerException {
StringWriter stringWriter = new StringWriter();
StreamResult streamResult = new StreamResult(stringWriter);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "no");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.transform(s, streamResult);
return stringWriter.toString();
}
};
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
TestSOAPHandler soapHandler2 = new TestSOAPHandler(false) {
public boolean handleFault(SOAPMessageContext ctx) {
super.handleFault(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!outbound) {
SOAPEnvelope env = ctx.getMessage().getSOAPPart().getEnvelope();
assertTrue("expected SOAPFault in SAAJ model", env.getBody().hasFault());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
try {
handlerTest.pingWithArgs("servant throw SOAPFaultException");
fail("did not get expected Exception");
} catch (SOAPFaultException sfe) {
// expected
}
assertEquals(1, handler1.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleMessageInvoked());
assertEquals(1, soapHandler1.getHandleMessageInvoked());
assertEquals(1, soapHandler2.getHandleMessageInvoked());
assertEquals(1, handler2.getHandleFaultInvoked());
assertEquals(1, handler1.getHandleFaultInvoked());
assertEquals(1, soapHandler1.getHandleFaultInvoked());
assertEquals(1, soapHandler2.getHandleFaultInvoked());
assertEquals(1, handler1.getCloseInvoked());
assertEquals(1, handler2.getCloseInvoked());
assertEquals(1, soapHandler1.getCloseInvoked());
assertEquals(1, soapHandler2.getCloseInvoked());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
use of org.apache.handler_test.HandlerTest in project cxf by apache.
the class HandlerInvocationTest method testLogicalHandlerHandleMessageReturnFalseClientOutBound.
@Test
public void testLogicalHandlerHandleMessageReturnFalseClientOutBound() throws Exception {
final String clientHandlerMessage = "handler2 client side";
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleMessage(LogicalMessageContext ctx) {
super.handleMessage(ctx);
try {
Boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
LogicalMessage msg = ctx.getMessage();
assertNotNull("logical message is null", msg);
JAXBContext jaxbCtx = JAXBContext.newInstance(PackageUtils.getPackageName(PingOneWay.class));
PingResponse resp = new PingResponse();
resp.getHandlersInfo().add(clientHandlerMessage);
msg.setPayload(resp, jaxbCtx);
return false;
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
return true;
}
};
TestHandler<LogicalMessageContext> handler3 = new TestHandler<LogicalMessageContext>(false);
TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, handler3, soapHandler1);
List<String> resp = handlerTest.ping();
assertEquals(clientHandlerMessage, resp.get(0));
assertEquals("the first handler must be invoked twice", 2, handler1.getHandleMessageInvoked());
assertEquals("the second handler must be invoked once only on outbound", 1, handler2.getHandleMessageInvoked());
assertEquals("the third handler must not be invoked", 0, handler3.getHandleMessageInvoked());
assertEquals("the last handler must not be invoked", 0, soapHandler1.getHandleMessageInvoked());
// outbound MEP processing ceased, the message direction was changed to inbound, essentially this is
// only one MEP. So close is called only once at the end of inbound MEP, and the close order is
// reversed to the outbound handler invoking order.
assertEquals("close must be called", 1, handler1.getCloseInvoked());
assertEquals("close must be called", 1, handler2.getCloseInvoked());
assertEquals("close must be called", 0, handler3.getCloseInvoked());
assertEquals("close must be called", 0, soapHandler1.getCloseInvoked());
assertTrue(handler2.getInvokeOrderOfClose() < handler1.getInvokeOrderOfClose());
}
use of org.apache.handler_test.HandlerTest in project cxf by apache.
the class HandlerInvocationTest method testSOAPHandlerHandleMessageReturnTrueClient.
@Test
public void testSOAPHandlerHandleMessageReturnTrueClient() throws Exception {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<LogicalMessageContext>(false);
TestHandler<LogicalMessageContext> handler2 = new TestHandler<LogicalMessageContext>(false) {
public boolean handleMessage(LogicalMessageContext ctx) {
super.handleMessage(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);
addHandlersToChain((BindingProvider) handlerTest, handler1, handler2, soapHandler1, soapHandler2);
List<String> resp = handlerTest.ping();
assertNotNull(resp);
assertEquals("handle message was not invoked", 2, handler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, handler2.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, soapHandler1.getHandleMessageInvoked());
assertEquals("handle message was not invoked", 2, soapHandler2.getHandleMessageInvoked());
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());
// the server has encoded into the response the order in
// which the handlers have been invoked, parse it and make
// sure everything is ok expected order for inbound interceptors
String[] handlerNames = { "soapHandler4", "soapHandler3", "handler2", "handler1", "servant", "handler1", "handler2", "soapHandler3", "soapHandler4" };
assertEquals(handlerNames.length, resp.size());
Iterator<String> iter = resp.iterator();
for (String expected : handlerNames) {
assertEquals(expected, iter.next());
}
}
Aggregations