1

I using camel reactive streams and I would like to add content type APPLICATION_JSON_UTF8_VALUE for the response. I tried to add it in map function. Here is my code.

    @Autowired
    private CamelReactiveStreamsService camel;

    camel.process("rest:post:test", exchangeProperty ->
            Flux.from(exchangeProperty)
                    .map(ex -> {
                        ex.getIn().setHeader(Exchange.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE);
                        return ex;
                    })
                    .map(ex -> ex.getIn().getBody(String.class))
                    .flatMap(camel.toStream("testRest", String.class))
                    .doOnNext(ex -> System.out.println(ex)));

This code returns only text without Header "content type" I think I don't understand how it works, so will be nice if someone can send me a link with tutorial(because I can't find), or someone can help me understand it. Thank you for help

Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
  • I'm not that fluent with Camel reactive streams though I'm under the impression that something like `.map(ex -> ex.getIn().getBody(String.class))` will lead to the remaining stream to operate on the result of the mapping, which is the body of the exchange as String object, and therefore you'll lose any other information available within the exchange, such as the header – Roman Vottner Mar 15 '19 at 15:29
  • Thank you for your help. Now I removed it and I see headers in response but I doesn't see body ehh.... in Exchange Body I see Object NettyChannelBufferStreamCache and I don't know how to use it – Mateusz Sobczak Mar 15 '19 at 18:25
  • Ican cast NettyChannelBufferStreamCache into InputStream and read body request now question is how to add body to response – Mateusz Sobczak Mar 15 '19 at 18:39

0 Answers0