Apache camel 未捕获驼峰HttpOperationFailedException

Apache camel 未捕获驼峰HttpOperationFailedException,apache-camel,Apache Camel,我在Camel中测试异常处理,发现了一个奇怪的行为。我有一个http组件故意抛出404错误。然后,Camel将抛出一个由org.apache.Camel.component.http.HttpProducer.populateHttpOperationFailedException创建的HttpOperationFailedException,我正在使用onWhen来区分不同的状态代码: 这是404的方法示例: onException(HttpOperationFailedException.c

我在Camel中测试异常处理,发现了一个奇怪的行为。我有一个http组件故意抛出404错误。然后,Camel将抛出一个由
org.apache.Camel.component.http.HttpProducer.populateHttpOperationFailedException创建的
HttpOperationFailedException
,我正在使用onWhen来区分不同的状态代码:

这是404的方法示例:

onException(HttpOperationFailedException.class)
    .onWhen(new Predicate() {
        public boolean matches(Exchange exchange) {
            HttpOperationFailedException ex = exchange.getProperty(
                    Exchange.EXCEPTION_CAUGHT,
                    HttpOperationFailedException.class);
            logger.warn("*** 404 Error ***");
            return (ex.getStatusCode() == 404);
        }
    }).handled(true).maximumRedeliveries(0);
但它永远不会被执行

于是我尝试了这个:

onException(Exception.class)
    .onWhen(new Predicate() {
        public boolean matches(Exchange exchange) {
            Object ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
            logger.error(ex.getClass());
            return (true);
        }
    }).handled(true).maximumRedeliveries(0);
并且记录器总是显示
classorg.apache.camel.http.common.HttpOperationFailedException


任何帮助都会很好!我用的是骆驼2.17.1

我发现了问题。我使用的是
import org.apache.camel.component.http.HttpOperationFailedException
,而不是
import org.apache.camel.http.HttpOperationFailedException
,我发现了问题。我使用的是
import org.apache.camel.component.http.HttpOperationFailedException
,而不是
import org.apache.camel.http.HttpOperationFailedException