1

Setting Content-Type for GET method is not getting populated using Apache Camel-Http component.

exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");

Whereas the same is working when using POST method.

Understood that there is no body for method GET. A strange thing is, if body is set to empty string("") Content-Type is being passed but the method type also changes to POST.

exchange.getIn().setBody("");

2.13.1 is the Camel version that i am currently using. Tried with the latest versions too, still the same. Is there something that i am missing.

Service mandates to pass Content-Type.

Samy
  • 2,387
  • 2
  • 17
  • 31

1 Answers1

0

In the Camel source there is a test for this kind of scenario: https://github.com/apache/camel/blob/master/components/camel-http4/src/test/java/org/apache/camel/component/http4/HttpProducerContentTypeTest.java

In both the test cases the body need to be set. You should see this in camel-http4:

https://github.com/apache/camel/blob/master/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpProducer.java#L482-L582

and camel-http too:

https://github.com/apache/camel/blob/master/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java#L447-L506

If you decide to use Http4/http component then you'll need to set a body.

There is also this very old discussion on nabble: http://camel.465427.n5.nabble.com/Http4-Set-Header-Content-Type-not-passing-through-to-the-HTTP-Request-td5746414.html

Oscerd
  • 1,616
  • 11
  • 14
  • Thanks for the details. I have already gone through the discussion above and as mentioned in it, using apache-cxfrs is not an option for me. We consume lot of services using apache-http component. How to handle such scenarios wherein GET type requires Content-Type too. – Samy Nov 07 '17 at 13:14
  • There is no other way than setting a body. – Oscerd Nov 07 '17 at 13:55
  • If body is set, method type is changed to POST. Tried setting an empty string "". – Samy Nov 07 '17 at 13:56
  • The component is not developed for this. It's not possible to set content type on a GET request. – Oscerd Nov 07 '17 at 14:52
  • Thanks for all your inputs! Will look at the possibility changing to Camel-cxfrs. – Samy Nov 07 '17 at 14:54