Apache-camel: Enabling bridgeEndpoint on the http endpoint
Answer by @SubOptimal is almost correct, except it should be HTTP_URI
header. From the doc:
If the bridgeEndpoint option is true, HttpProducer will ignore the Exchange.HTTP_URI header, and use the endpoint’s URI for request.
Therefore there are 2 solutions:
- add
.removeHeader(Exchange.HTTP_URI)
to the route definition - add
?bridgeEndpoint=true
query parameter
However this might not solve the problem if you have other headers that get in the way. Probably that was your case, that's why removing all Camel http headers helped.
Please be aware though that removing all headers might break your logic: for example HTTP_METHOD
header is used to define the http method of the outgoing request. And it's up to you if you want to proxy the method too or not. You can find more in the same doc via the link above.
From the FAQ
In camel there are a number of components that use the http protocol headers to do their business.
I believe your producer does it as well. So the following could solve your problem.
from("direct:getContact")
.marshal().json(JsonLibrary.Jackson)
.setHeader("Content-Type", constant("application/json"))
.setHeader("Accept", constant("application/json"))
.setHeader(Exchange.HTTP_METHOD, constant("GET"))
.removeHeader(Exchange.HTTP_PATH)
.recipientList(simple("http://<remoteHost>:8080/api/contact" +
"/${header.contactId}?bridgeEndpoint=true"))
.unmarshal().json(JsonLibrary.Jackson);
You could also remove contact/${header.contactId}
from the endpoint. As it looks redundant. But this depends on what you want to achieve.