Karthik
Karthik

Reputation: 41

Camel HTTP response body is empty though the exchange body has the payload

rest("/getOptChoice").
        get("/v1")
        .consumes("application/json")
        .to("direct:hello")
        .produces("application/json");

from("direct:hello")
        .split(header("emails"))
        .to("seda:consumeGuestChoice")
        .aggregate(constant(true),new OptAggregator())
        .completionSize(2)
        .marshal(jaxb)
        .convertBodyTo(String.class);

After converting the body, if i do print the exchange body, i see the payload. But the HTTP response from the rest service is always empty.

Has someone faced this issue before? If so, is there a work-around?

Upvotes: 3

Views: 2349

Answers (2)

Karbos 538
Karbos 538

Reputation: 3055

If you write :

from("direct:hello")
    .split(header("emails"), new OptAggregator())
        .to("seda:consumeGuestChoice")
        .end()
    .marshal(jaxb)
    .convertBodyTo(String.class);

It may work. Is it ?

Upvotes: 0

grinch
grinch

Reputation: 814

You might need to enable stream caching in your route: http://camel.apache.org/stream-caching.html

It allows the body to be read multiple times for these stream-backed components.

from("direct:hello")
    .streamCaching()
    .split(header("emails"))
    .to("seda:consumeGuestChoice")
    .aggregate(constant(true),new OptAggregator())
    .completionSize(2)
    .marshal(jaxb)
    .convertBodyTo(String.class);

Upvotes: 1

Related Questions