나는 CAMEL을 사용하여 xml과 다른 json 인 두 소스의 응답을 집계합니다. 처음에는 그 응답을 스텁하고 파일에서 가져 왔습니다. 목표는 두 소스의 응답을 집계하는 것입니다.Camel AggregatonStrategy wrong result
내 애그리 게이터 (aggregator) 노선이
from("direct:fetchProfile")
.multicast(new ProfileAggregationStrategy()).stopOnException()
.enrich("direct:xmlProfile")
.enrich("direct:jsonProfile")
.end();
내 같다 : - 난 JAXB를 사용하여 다음 파일에서 XML을 읽고 있어요 위의 경로에서
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);
}
});
처럼 "직접 xmlProfile"경로 보인다 컨버터를 사용하여 관심있는 요소를 '프로필'로 표시된 클래스에 매핑합니다. 이 경로를 호출 한 후 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;
}
}
}
문제는 '문제가있는 줄'로 표시된 줄입니다. '직접 : xmlProfile'경로의 최종 단계에서 명시 적으로 개체를 Exchange의 본문에 넣었지만 ProfileAggregationStrategy의 newExchange는 Body가 iostream 유형으로 표시됩니다.