Hi

The following unit-test should demonstrate how to do it in Java (doing the
same in Spring-XML should be also straight forward):

Babak

import java.util.HashMap;
import java.util.Map;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class CustomExceptionHandlerTest extends CamelTestSupport {

    @Test
    public void useOfCustomizedExceptionHandler() throws Exception {
        FtpComponent component = context.getComponent("ftp",
FtpComponent.class);
        FtpEndpoint<?> endpoint = (FtpEndpoint<?>)
component.createEndpoint("ftp://inbox?noop=true";);

        ExceptionHandler myExceptionHandler = new MyExceptionHandler();
        Map<String, Object> consumerProperties = new HashMap<String,
Object>();
        consumerProperties.put("exceptionHandler", myExceptionHandler);
        endpoint.setConsumerProperties(consumerProperties);

        // verify that our own propriety ExceptionHandler has been setup as
expected ...
        RemoteFileConsumer<?> consumer = endpoint.createConsumer(new
Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                // noop
            }
        });

        assertSame(consumer.getExceptionHandler(), myExceptionHandler);
    }

    private static class MyExceptionHandler implements ExceptionHandler {

        @Override
        public void handleException(String message, Exchange exchange,
Throwable exception) {
            throw new RuntimeCamelException(message, exception);
        }

        @Override
        public void handleException(String message, Throwable exception) {
            handleException(message, null, exception);
        }

        @Override
        public void handleException(Throwable exception) {
            handleException(null, null, exception);
        }

    }

}


--
View this message in context: 
http://camel.465427.n5.nabble.com/ExceptionHandler-in-a-ftp-Route-tp5451466p5460365.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to