Hi,

this is how the template works in combination with different endpoints. Camel 
exchanges can have an in message and an out message. If the camel pipeline 
proceeds to the next step the out message is moved to the in message before 
that endpoint is called in case there is an out message. The endpoint itself 
can either write the out message or overwrite the in message. The bean 
processors obviously write an out message, so if you are calling that first 
pipeline, you end up with your response in the out message and the template 
does not move it to the in message. Replacing the getIn() with getOut() would 
give you the expected response for the first route. The empty processor adds 
another endpoint to the route, so the result of your bean is moved to the in 
message (and your dummy processor just leaves it alone).

This behavior is kind of weird, but you will only notice it when you are 
calling direct endpoints from a template, which is probably mostly happening in 
unit tests.

Best regards
Stephan

-----Original Message-----
From: Artur Jablonski [mailto:[email protected]] 
Sent: Mittwoch, 27. Dezember 2017 16:32
To: [email protected]
Subject: v2.20.1 bug or a feature?

Hey,

I bumped into this one today and not sure if this is a bug or a feature :).

The example is in SpringBoot application, if that makes any difference

Given this route:

from("direct:bugOrFeature")
    .to("bean:mybean?method=transform");

and the bean method:

public String transform(@Body String in)
{
    return "I want to change the body!";
}

if I call it like this:

String result =
    template.request("direct:bugOrFeature",
                     e -> e.getIn().setBody("Some input"))
            .getIn()
            .getBody(String.class);

logger.info("result: {}", result);

Then it prints out the old value:
> result: Some input

However if I stick a dummy processor at the end of the route

from("direct:bugOrFeature")
    .to("bean:camelMaintenanceRoutes?method=transform")
    .process(e -> {});

then suddenly the same call gives me the new value
> result: I want to change the body!

Is this a bug or am I missing something?

Note that if I request for a body like this:

template
    .requestBody("direct:bugOrFeature", "some input", String.class)

then it get's the 'new' value without the dummy processor.
The thing is that I need to get out some headers from response, so I need
Exchange object and not just the body.

Best,
Artur

Reply via email to