use of org.apache.cxf.jaxws.handler.soap.SOAPMessageContextImpl in project cxf by apache.
the class HandlerChainInvokerTest method testHandleMessageThrowsProtocolExceptionOutbound.
@Test
public void testHandleMessageThrowsProtocolExceptionOutbound() {
message = new SoapMessage(message);
lmc = new LogicalMessageContextImpl(message);
pmc = new WrappedMessageContext(message);
ProtocolException pe = new ProtocolException("banzai");
protocolHandlers[2].setException(pe);
invoker.setRequestor(true);
assertTrue(invoker.isOutbound());
boolean continueProcessing = true;
invoker.setLogicalMessageContext(lmc);
continueProcessing = invoker.invokeLogicalHandlers(false, lmc);
assertTrue(continueProcessing);
// create an empty SOAP body for testing
try {
pmc = new SOAPMessageContextImpl(message);
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage soapMessage = factory.createMessage();
((SOAPMessageContext) pmc).setMessage(soapMessage);
} catch (SOAPException e) {
// do nothing
}
try {
invoker.setProtocolMessageContext(pmc);
continueProcessing = invoker.invokeProtocolHandlers(false, pmc);
fail("did not get expected exception");
} catch (ProtocolException e) {
assertEquals("banzai", e.getMessage());
}
assertFalse((Boolean) pmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
assertFalse((Boolean) lmc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY));
assertTrue(invoker.isInbound());
// the message is replaced by fault message
Source responseMessage = lmc.getMessage().getPayload();
// System.out.println(getSourceAsString(responseMessage));
assertTrue(getSourceAsString(responseMessage).indexOf("banzai") > -1);
// assertFalse(continueProcessing);
assertEquals(1, logicalHandlers[0].getHandleMessageCount());
assertEquals(1, logicalHandlers[1].getHandleMessageCount());
assertEquals(1, logicalHandlers[2].getHandleMessageCount());
assertEquals(1, logicalHandlers[3].getHandleMessageCount());
assertEquals(1, protocolHandlers[0].getHandleMessageCount());
assertEquals(1, protocolHandlers[1].getHandleMessageCount());
assertEquals(1, protocolHandlers[2].getHandleMessageCount());
assertEquals(0, protocolHandlers[3].getHandleMessageCount());
assertTrue(logicalHandlers[3].getInvokeOrderOfHandleMessage() < protocolHandlers[0].getInvokeOrderOfHandleMessage());
assertTrue(protocolHandlers[1].getInvokeOrderOfHandleMessage() < protocolHandlers[2].getInvokeOrderOfHandleMessage());
assertEquals(1, logicalHandlers[0].getCloseCount());
assertEquals(1, logicalHandlers[1].getCloseCount());
assertEquals(1, logicalHandlers[2].getCloseCount());
assertEquals(1, logicalHandlers[3].getCloseCount());
assertEquals(1, protocolHandlers[0].getCloseCount());
assertEquals(1, protocolHandlers[1].getCloseCount());
assertEquals(1, protocolHandlers[2].getCloseCount());
assertEquals(0, protocolHandlers[3].getCloseCount());
assertTrue(protocolHandlers[2].getInvokeOrderOfClose() < protocolHandlers[1].getInvokeOrderOfClose());
assertTrue(protocolHandlers[0].getInvokeOrderOfClose() < logicalHandlers[3].getInvokeOrderOfClose());
assertEquals(1, logicalHandlers[0].getHandleFaultCount());
assertEquals(1, logicalHandlers[1].getHandleFaultCount());
assertEquals(1, logicalHandlers[2].getHandleFaultCount());
assertEquals(1, logicalHandlers[3].getHandleFaultCount());
assertEquals(1, protocolHandlers[0].getHandleFaultCount());
assertEquals(1, protocolHandlers[1].getHandleFaultCount());
assertEquals(0, protocolHandlers[2].getHandleFaultCount());
assertEquals(0, protocolHandlers[3].getHandleFaultCount());
assertTrue(protocolHandlers[0].getInvokeOrderOfHandleFault() < logicalHandlers[3].getInvokeOrderOfHandleFault());
assertTrue(protocolHandlers[2].getInvokeOrderOfHandleFault() < protocolHandlers[1].getInvokeOrderOfHandleFault());
}
Aggregations