Search in sources :

Example 1 with SoapFault

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
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) SoapFault(org.apache.cxf.binding.soap.SoapFault) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message)

Example 2 with SoapFault

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
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) SoapFault(org.apache.cxf.binding.soap.SoapFault) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException)

Example 3 with SoapFault

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());
    }
}
Also used : SoapFault(org.apache.cxf.binding.soap.SoapFault) ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with SoapFault

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();
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) SoapFault(org.apache.cxf.binding.soap.SoapFault) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Fault(org.apache.cxf.interceptor.Fault) SoapFault(org.apache.cxf.binding.soap.SoapFault) BpmnError(org.activiti.engine.delegate.BpmnError) Deployment(org.activiti.engine.test.Deployment)

Aggregations

SoapFault (org.apache.cxf.binding.soap.SoapFault)4 IOException (java.io.IOException)2 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 ActivitiException (org.activiti.engine.ActivitiException)1 BpmnError (org.activiti.engine.delegate.BpmnError)1 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)1 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)1 Deployment (org.activiti.engine.test.Deployment)1 Message (org.apache.camel.Message)1 ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)1 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)1 Fault (org.apache.cxf.interceptor.Fault)1 Test (org.junit.Test)1