I have route below.

        from("direct:getJson")
                .removeHeaders("CamelHttp*")
                .setHeader("Accept", constant("application/json"))
                .setHeader("Cache-Control", constant("no-cache"))
                .setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.POST))
                *.setHeader(Exchange.CONTENT_TYPE,
constant("application/json"))*
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                        String userCredentials = "username:password";
                        final String auth = "Basic " + new String(new
Base64().encode(userCredentials.getBytes()));
                        exchange.getOut().setHeader("Authorization", auth);
                        exchange.getOut().setBody("{"key","value"}");
                    }
                })
                .to("http4:www.myhost.com");

and request fails with http 500 (Internal Server Error). No feedback from
server owner. But it works with Rest client and curl.

So, I decided to use wireshark. And I see that CONTENT_TYPE sent as
text/plain. Tried few other combinations but no luck. But it worked after I
set it after process. 

        from("direct:getJson")
                .removeHeaders("CamelHttp*")

                .setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.POST))
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception
{
                        String userCredentials = "username:password";
                        final String auth = "Basic " + new String(new
Base64().encode(userCredentials.getBytes()));
                        exchange.getOut().setHeader("Authorization", auth);
                        exchange.getOut().setBody("{"key","value"}");
                    }
                })
                *.setHeader(Exchange.CONTENT_TYPE,
constant("application/json"))
                .setHeader("Accept", constant("application/json"))
                .setHeader("Cache-Control", constant("no-cache"))*

                .to("http4:www.myhost.com");

What is the reason?. Is it a bug or normal scenario? If it is normal, what
is the rule?

Many thanks in advance!




--
View this message in context: 
http://camel.465427.n5.nabble.com/header-changes-just-after-process-tp5794482.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to