Fuse ESB: CXF message enrichment from intermediate service

113 views Asked by At

I want to achive the following scenario: CXF route in FUSE receives SOAP request, extracts a number of IDs from the request, creates a different SOAP message with the IDs, sends it to service A. This service replies with data associated with these IDs, and the route should insert these data to the original message and send it to the final destination service. So in short, before sending the message to the final destination, we have to take a detour and enrich our original message with data from the intermediate service. I'm researching the correct configuration (we are using Fuse ESB 6.2 pre-release with Spring-based blueprint XML).

UPDATE I'm updating my answer because after a bunch of trial and error my problems are completely solved.

1

There are 1 answers

0
gyorgyabraham On BEST ANSWER

Okay, the actually working version is:

Routing configuration: The enrichment call must be a seperated route in the same camel context:

<route id="direct:enrichroute">
            <from uri="direct:enrichroute"/>
            <bean ref="processorBean"/>
            <to uri="cxf:bean:intermediateEndpoint"/>
</route>

In the actual route, we insert the enrichment between from and to and configure the aggregation strategy bean:

<route id="someRoute">
            <from uri="cxf:bean:incomingEndpoint"/>
            <enrich uri="direct:enrichroute" strategyRef="aggregationStrategyBean"/>
            <to uri="cxf:bean:finalEndpoint"/>
</route>

Where cxf:bean:incomingEndpoint is the entry point in our ESB and finalEndpoint is the final destination. Using this config, the processor in enrich route gets the request body so it can create the enrichment request body, send it to the enrich endpoint. Also, in the actual route, the aggregation processor is aware of the original request body and the enrichment response body so it can insert the necessary data.

Processor class:

public class ProcessorBean implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        // original request body can be fetched from exchange
        // we can override the request body before sending it 
        exchange.getIn().setBody(newRq);
    }
}

Aggregation strategy class:

public class AggregationStrategyBean implements AggregationStrategy {

    @Override
    public Exchange aggregate(Exchange originalExchange, Exchange intermediateExchange) {
    }
}