在Apache Camel中,如何在Split中获取聚合以传递属性?

时间:2019-04-08 23:46:35

标签: java apache-camel

我在Apache Camel上正在处理的应用程序上有一些代码,该代码需要处理在拆分内更新的属性。为避免发送每一封更新的电子邮件。

但是在聚合中,它会导致Null Pointer Exception,因为oldExchange为null,而newExchange在电子邮件呼叫之后显示了交换。

我已尝试通读Camel手册,但这对网站示例的一半加载没有帮助。

我在做什么错了。

<route>
...
<when>
<simple>${property.updateAddress} == 'Y' </simple>
<split strategyRef="checkForEmail">
   <!-- Update Address Processes here -->

   <when>
   <simple>${property.alreadySentEmail == 'N'}</simple>

       <process ref="handleEmail"> <!-- sets alreadySentEmail property to 'N' -->
   </when>
   </split>
...
</when>
<when>
<simple>${property.updatePhone} == 'Y'</simple>
<split strategyRef="checkForEmail">
   <!-- Update Phone Processes here -->

   <when>
   <simple>${property.alreadySentEmail == 'N'}</simple> 

       <process ref="handleEmail"><!-- sets alreadySentEmail property to N-->
   </when>
   </split>
...
</when>
</route>


//added bean to Bean.xml that maps "checkForEmail" to this
public class CheckForEmail implements AggregationStrategy {
    @Override
    public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {

       if (newExchange != null && newExchange.getProperty("alreadySentEmail") != null){
            oldExchange.setProperty("alreadySentEmail", newExchange.getProperty("alreadySentEmail"));
        }
        return oldExchange;

    }
}

0 个答案:

没有答案