use of org.apache.cxf.binding.soap.SoapFault in project camel by apache.
the class CxfMessageStreamExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: onException
from("direct:start").onException(SoapFault.class).maximumRedeliveries(0).handled(true).process(new Processor() {
public void process(Exchange exchange) throws Exception {
SoapFault fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
}
}).end().to(serviceURI);
// END SNIPPET: onException
// START SNIPPET: MessageStreamFault
from(routerEndpointURI).process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message out = exchange.getOut();
// Set the message body with the
out.setBody(this.getClass().getResourceAsStream("SoapFaultMessage.xml"));
// Set the response code here
out.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
}
});
// END SNIPPET: MessageStreamFault
}
};
}
use of org.apache.cxf.binding.soap.SoapFault in project camel by apache.
the class CxfCustomizedExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: onException
from("direct:start").onException(SoapFault.class).maximumRedeliveries(0).handled(true).process(new Processor() {
public void process(Exchange exchange) throws Exception {
SoapFault fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
}
}).end().to(serviceURI);
// END SNIPPET: onException
// START SNIPPET: ThrowFault
from(routerEndpointURI).setFaultBody(constant(SOAP_FAULT));
// END SNIPPET: ThrowFault
}
};
}
use of org.apache.cxf.binding.soap.SoapFault in project camel by apache.
the class CxfCustomizedExceptionTest method testInvokingServiceFromCXFClient.
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
ClientProxyFactoryBean proxyFactory = new ClientProxyFactoryBean();
ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
clientBean.setAddress(routerAddress);
clientBean.setServiceClass(HelloService.class);
clientBean.setBus(bus);
HelloService client = (HelloService) proxyFactory.create();
try {
client.echo("hello world");
fail("Expect to get an exception here");
} catch (Exception e) {
assertEquals("Expect to get right exception message", EXCEPTION_MESSAGE, e.getMessage());
assertTrue("Exception is not instance of SoapFault", e instanceof SoapFault);
assertEquals("Expect to get right detail message", DETAIL_TEXT, ((SoapFault) e).getDetail().getTextContent());
//In CXF 2.1.2 , the fault code is per spec , the below fault-code is for SOAP 1.1
assertEquals("Expect to get right fault-code", "{http://schemas.xmlsoap.org/soap/envelope/}Client", ((SoapFault) e).getFaultCode().toString());
}
}
use of org.apache.cxf.binding.soap.SoapFault in project Activiti by Activiti.
the class WebServiceTaskTest method testFaultManagement.
@Deployment
public void testFaultManagement() throws Exception {
assertEquals(-1, webServiceMock.getCount());
// Expected fault catched with a boundary error event
webServiceMock.setTo(Integer.MAX_VALUE);
ProcessInstance processInstanceWithExpectedFault = runtimeService.startProcessInstanceByKey("webServiceInvocation");
waitForJobExecutorToProcessAllJobs(10000L, 250L);
assertTrue(processInstanceWithExpectedFault.isEnded());
final List<HistoricProcessInstance> historicProcessInstanceWithExpectedFault = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceWithExpectedFault.getId()).list();
assertEquals(1, historicProcessInstanceWithExpectedFault.size());
assertEquals("theEndWithError", historicProcessInstanceWithExpectedFault.get(0).getEndActivityId());
// RuntimException occurring during processing of the web-service, so not catched in the process definition. The RuntimeException
// is embedded as an unexpected fault at web-service server side
webServiceMock.setTo(123456);
try {
runtimeService.startProcessInstanceByKey("webServiceInvocation");
} catch (ActivitiException e) {
assertFalse("Exception processed as Business fault", e instanceof BpmnError);
assertTrue(e.getCause() instanceof SoapFault);
}
// Unexpected fault at ws-client side invoking the web-service, so not catched in the process definition
server.stop();
try {
runtimeService.startProcessInstanceByKey("webServiceInvocation");
} catch (ActivitiException e) {
assertFalse("Exception processed as Business fault", e instanceof BpmnError);
assertTrue(e.getCause() instanceof Fault);
} finally {
server.start();
}
}
Aggregations