我在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;
}
}