修改Apache camel

时间:2016-11-29 13:34:00

标签: exception-handling apache-camel

在我的骆驼路线中,我正在对现有的捆绑进行直接vm调用。在该服务中,他们已经处理了异常并设置了一些自定义故障消息。当在该服务中发生任何异常时,它们将发送如下的错误消息。

{
"errorCode": "400",
"errorMessage": "Unknown error"
}

但我需要根据收到的错误信息形成自己的自定义错误信息。但是一旦在第二个捆绑包中发生异常,我就无法恢复故障消息并对其进行修改。以下是我的路线的样子。

   <route handleFault="true" streamCache="true" id="route1">
    <from uri="cxfrs://bean://testCxf?synchronous=true"/>
    <log message="The consumer message  ${body}"/> 
      <bean ref="requestValidator" method="validateRequest"/>
      <to uri="direct-vm:retrieveData"/>
      <bean ref="validateResponse" method="validate"/>//need to manipulate  the fault message coming from bundle 2 in this bean.
    <onException>
      <exception>java.lang.Exception</exception>
      <handled>
        <constant>true</constant>
      </handled>
      <bean ref="faultMapper" method="mapFault"/>
    </onException>
   </route>

以下是现有的直接:vm路线。

<route handleFault="true" streamCache="true" id="route2">
    <from uri="direct-vm:retrieveData"/>
      <bean ref="manipulateData" method"manipulate"/>
        <onException>
          <exception>java.lang.Exception</exception>
          <handled>
            <constant>true</constant>
          </handled>
          <bean ref="faultMapper1" method="mapFault1"/>
        </onException>
    </route>

我需要在direct-vm调用之后拦截在我的route1中的类faultmapper1中映射的错误。如何实现这个?我不会被允许更改现有第二个包中的任何内容。提前谢谢。

1 个答案:

答案 0 :(得分:0)

经过一番研究发现,这是不可能的。为了达到这个要求,我在第二个路径中将处理常量设为false,并在第一个路径中添加了一个块。这样我就可以捕获抛出的异常并通过一些自定义故障映射来处理它。