0
我使用CAMEL来汇总两个来源的响应,一个是xml和其他json。最初,我扼杀了这些反应,并且从文件中获取它们。 目标是汇总来自两个来源的回复。Camel AggregatonStrategy错误结果
我的聚合路线是这样的
from("direct:fetchProfile")
.multicast(new ProfileAggregationStrategy()).stopOnException()
.enrich("direct:xmlProfile")
.enrich("direct:jsonProfile")
.end();
我“直接:xmlProfile”路线看起来像 -
from("direct:xmlProfile")
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
String filename = "target/classes/xml/customerDetails.xml";
InputStream fileStream = new FileInputStream(filename);
exchange.getIn().setBody(fileStream);
}
})
.split(body().tokenizeXML("attributes", null))
.unmarshal(jaxbDataFormat)
.process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
Profile legacyProfile = exchange.getIn().getBody(Profile.class);
// some more processing here
exchange.getIn().setBody(legacyProfile);
}
});
在上面的路线我读从文件的XML,然后使用JAXB转换器将感兴趣的元素映射到由“配置文件”表示的类中。呼叫此路由后,CAMEL调用ProfileAggregationStrategy。此代码是 -
public class ProfileAggregationStrategy implements AggregationStrategy{
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
// this is the problematic line
Profile newProfile = newExchange.getIn().getBody(Profile.class);
if (oldExchange == null){
return newExchange;
} else {
Profile oldProfile = oldExchange.getIn().getBody(Profile.class);
// code to copy merge oldProfile with newProfile
return oldExchange;
}
}
}
问题在于标记为'有问题的行'的行。即使在路由'direct:xmlProfile'的最后阶段,我已明确地将一个对象放入交换体中,ProfileAggregationStrategy中的newExchange仍然显示Body是iostream类型。