Camel 的 CXF 组件未捕获 onException(Exception.class) [英] Camel's CXF component not catching onException(Exception.class)

查看:20
本文介绍了Camel 的 CXF 组件未捕获 onException(Exception.class)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 camel-cxf 网络服务.我用来处理 CXF 的 SOAP 故障拦截器机制中的所有 SOAP 故障.效果很好.

I have a camel-cxf webservice up. I use to handle all SOAP Faults in the CXF's SOAP Fault Interceptor mechanism. That is working well.

我认为最好在同一层处理Camel层抛出的异常,并编写了一个简单的onException场景如下:

I thought that its better to handle Exception thrown at the Camel layer at the same layer and wrote a simple onException scenario like this:

onException(Exception.class).to("direct:MyWSExceptionHandler");

onException(Exception.class). to("direct:MyWSExceptionHandler");

每当抛出自定义异常时,我都期待 onException 启动(请记住,我也有一个 SOAP 故障拦截器),但它没有.CXF 正在接管,消息通过拦截器,而不是骆驼路线.

Whenever a custom exception is thrown, I was expecting the onException to kick in(Remember I also have a SOAP Fault Interceptor too), but it doesn't. The CXF is taking over and the message is going through the Interceptors, rather than the Camel Route.

这是预期的方式,还是我做错了什么?

Is this the expected way, or am I doing something wrong?

我的 CXF 故障拦截器如下所示:

My CXF fault interceptor looks like this:

@Component("SOAPFaultInterceptor")
public class SOAPFaultInterceptor extends AbstractPhaseInterceptor {

    public SOAPFaultInterceptor() {
        super(Phase.MARSHAL);
    }

    public void handleMessage(Message message) throws Fault {
     // The message is coming here directly, instead of going to the route defined by onException.
    }
}

有人能告诉我如何解决这个问题吗?我不希望在 Camel 层生成的异常离开该层而不被处理..

Can someone please tell how to fix this? I don't want Exception generated at the Camel layer to leave that layer without being handled..

提前致谢.

推荐答案

Camel的onException只有在有异常的情况下才会触发.SOAP 故障表示为带有故障标志 = true 的消息.

Camel's onException only triggeres if there is an exception. A SOAP Fault is represented as a Message with the fault flag = true.

您可以做的是在 CamelContext 上设置 handleFault=true,然后它将 SOAP 错误消息转换为 onException 可以响应的异常.

What you can do is to set handleFault=true on CamelContext, then it will turn SOAP fault messages into an exception that the onException can react upon.

这篇关于Camel 的 CXF 组件未捕获 onException(Exception.class)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆