在自定义拦截器中捕获SOAP Fault错误(Soap12FaultOutInterceptor) [英] Catching the SOAP Fault error in custom interceptor (Soap12FaultOutInterceptor)

查看:1639
本文介绍了在自定义拦截器中捕获SOAP Fault错误(Soap12FaultOutInterceptor)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个自定义CXF拦截器来将所有SOAP请求和响应记录到数据库中,它似乎与正面测试用例和服务器错误一起工作正常。

I wrote a custom CXF interceptor to log all the SOAP request and responses into the database and it seems to be working fine with positive test cases and server errors.

但是当发生SOAP Fault时,它只是忽略了我的拦截器而没有记录任何东西。

But when a SOAP Fault occurs it just neglects my interceptor and nothing is logged.

自定义CXF拦截器。

public class DbLogOutInterceptor extends AbstractSoapInterceptor {

 public void handleMessage(SoapMessage message) {
    logger.info("Handling outbound request");

    String transaction = MDC.get(mdcKey);
    logger.info("OutBound Transaction ID : {} ", transaction);

     //code to log the SOAP message in database
    .......

     }
   }

我没有看到此方法的日志语句而是看到

I am not seeing the log statements from this method instead I see

 11:56:34,102 INFO  [Soap12FaultOutInterceptor] class org.apache.cxf.binding.soap.interceptor.Soap12FaultOutInterceptor$Soap12FaultOutInterceptor Internalapplication/soap+xml
 11:56:34,103 INFO  [EligibilityInfo] Outbound Message
 ---------------------------
 ID: 2
 Response-Code: 500
 Encoding: UTF-8
 Content-Type: application/soap+xml
 Headers: {}
 Payload :  

为了捕获自定义拦截器中的SOAP错误错误,我需要做些什么。

What I have to do in order to capture the SOAP fault erros in my custom interceptors.

推荐答案

所以在我的自定义拦截器中,我编写了以下代码:

So in my custom interceptor I write the following code:

Fault fault = new Fault(message.getContent(Exception.class));

现在这是一些遗留代码,它从Java中抛出异常并让框架将其转换为故障。我不会对此有所了解,但这会让你产生错误。

Now this is in some legacy code that was throwing exceptions from Java and letting the framework convert it to a fault. I won't get into my feelings on that, but this will get you the fault that is generated.

现在,如果你从服务方法中抛出错误,那么

Now if you are throwing a fault from your service method, do

Fault fault = message.getContect(Fault.class);

希望这可以帮助您获得所需的答案。确保你注册下面的拦截器

Hopefully this will help you get the answer to what you want. Make sure you register the interceptor like below

<jaxws:endpoint
  id="fooService" implementor="com.bar.FooService" address="/FooServices">
  <jaxws:outFaultInterceptors>
        <ref class="com.bar.interceptor.DbLogOutInterceptor"/>
  </jaxws:outFaultInterceptors>
</jaxws:endpoint>
<jaxws:endpoint

这篇关于在自定义拦截器中捕获SOAP Fault错误(Soap12FaultOutInterceptor)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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