Rodrigo Sasaki
Rodrigo Sasaki

Reputation: 7226

Can I invoke a webservice with Apache Camel and return the response?

This question might be a little abstract, but I'm trying to do something with Apache Camel and I'm stuck.

The basic scenario is this, I expose a webservice A through Camel, in this service, there is a content-based routing to decide if I have to invoke B or C, and I'd like to invoke the right one, and have the response from B or C to be the response of my service A

I have exposed the webservice already with camel-cxf and it works very well, but I don't know how to go about the routing after that, I have thought of this:

from("cxf:bean:myServiceA").choice()
    .when(new PredicateForServiceB())
        .process(new ProcessorForServiceB())
    .when(new PredicateForServiceC())
        .process(new ProcessorForServiceC())
    .otherwise()
    .endChoice()
.to("log:output");

I'm not sure if this is the best way or even if this is correct, but it's what I came up with.

Now I don't know how I would implement those processors, I could just create a normal invocation to the services and build the output, but I'd like to do it with the Camel infrastructure.

does anyone have any pointers on this? I'd be glad to provide more information if necessary

Upvotes: 0

Views: 291

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

Camel provides the Bean binding, which you don't need to touch much of Camel API and focus on the business logic you need to in the POJO bean. If you use Processor API, you can handle the Exchange yourself, then the response can be send back to client if you setup out message on the exchange.

Upvotes: 1

Related Questions