use of org.apache.handler_test.PingException in project cxf by apache.
the class TestHandler method handleMessage.
public boolean handleMessage(T ctx) {
methodCalled("handleMessage");
printHandlerInfo("handleMessage", isOutbound(ctx));
boolean outbound = (Boolean) ctx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
boolean ret = getHandleMessageRet();
if (!isServerSideHandler()) {
return true;
}
try {
verifyJAXWSProperties(ctx);
} catch (PingException e) {
e.printStackTrace();
throw new ProtocolException(e);
}
Object obj = ctx.getMessage().getPayload(jaxbCtx);
if (obj instanceof Ping || obj instanceof PingResponse) {
ret = handlePingMessage(outbound, ctx);
} else if (obj instanceof PingWithArgs) {
ret = handlePingWithArgsMessage(outbound, ctx);
}
return ret;
}
use of org.apache.handler_test.PingException in project cxf by apache.
the class HandlerInvocationTest method testServerEndpointRemoteFault.
@Test
public void testServerEndpointRemoteFault() throws PingException {
TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(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.PingException in project cxf by apache.
the class HandlerTestImpl method pingWithArgs.
public final List<String> pingWithArgs(String handlerCommand) throws PingException {
List<String> ret = new ArrayList<>();
ret.add(handlerCommand);
ret.addAll(getHandlersInfo(context.getMessageContext()));
if (handlerCommand.contains("servant throw exception")) {
PingFaultDetails details = new PingFaultDetails();
details.setDetail(ret.toString());
throw new PingException("from servant", details);
} else if (handlerCommand.contains("servant throw RuntimeException")) {
throw new RuntimeException("servant throw RuntimeException");
} else if (handlerCommand.contains("servant throw SOAPFaultException")) {
throw createSOAPFaultException("servant throws SOAPFaultException");
} else if (handlerCommand.contains("servant throw WebServiceException")) {
RuntimeException re = new RuntimeException("servant throws RuntimeException");
throw new WebServiceException("RemoteException with nested RuntimeException", re);
}
return ret;
}
Aggregations