How do I sync camel route processing with Java application?

Hello,

I have a Java application that sends a series of test messages from a test injector to a target “service”. The means of message transport and data format is handled by a third party “service bus”. I am attempting to use Camel to assist with message capture (sent from the service bus), modifying the captured message and forwarding on to the target. Following is an outline of the processing flow:

Read in and parse XML message

For each element or attribute

Determine a set of test cases to use

For each test case

Send message via service bus

Intercept message (via Camel)

Replace original element/attribute content with test data

Forward message to target

The means by which I’m doing this is that I have written a Camel route like the following:

interceptSendToEndpoint(destURI).process(interceptor);

from(sourceURI).to(destURI);

The interceptor is an extension of org.apache.camel.Processor. The process() method retrieves the exchange body and performs the modification of the message by means of information (we’ll call it the discovery data) that I pass to the interceptor from my test injector. The process() method checks to see if the discovery data has been set, otherwise it just returns. If the discovery data is not null, the modification is performed and the modified data placed back in the exchange body. Then the discovery data is then set to null in the interceptor.

The Problem

All of this appears to be working as I need, except for the first test case. In this instance, process() always reports that the discovery data is null, even though I am always setting the discovery data into the interceptor before invoking the service bus message send.

My suspicion is that I am over-running a prior test case that hasn’t been received and processed “soon enough” before the next test case comes along and clobbers it. I need some way to have my injector logic wait until Camel intercepts the data of the prior test case, processes it and forwards it on to the target.

I’m looking for suggestions on how I might go about that. I don’t know enough about Camel to know what (if any) mechanisms are available that could help.