cookiesapache-camelapache-httpclient-4.xjsessionid

Apache Camel HTTP4 and (JSESSIONID) cookies


I have a relatively complex route that calls 5 different URLs on the same host. The host will occasionally send cookies which I have to return on subsequent calls, like a browser would. I am using Camel 2.10 (no chance of upgrade due to compatibility issues) and this version doesn't seem to configure a cookie store by default. If I would wire in a BasicCookieStore, it stands to reason it would be shared by all calls made by HTTP4 component... but this, of course, makes no sense in the context of a web-app shared by many users, so it might be a wrong assumption.

I've also noticed that if I make multiple requests to the same URL, the server should always send a Set-Cookie for JSESSIONID (unless, of course, I (the client) had already sent this cookie), but even though I specifically remove all headers before making the request, the server sends JSESSIONID only the first time. I have tried both with bridgeEndpoint=true and without, with no difference in behavior. When accessed using a browser, it behaves as expected.

It seems I'm terribly misunderstanding something about how Camel deals with cookies. Can someone help me understand what's going on?


Solution

  • When you setup the bridgeEndpoint option to be true, camel just setup the http client default cookieStore to be false, which means it doesn't remember any cookies.

    If the bridgeEndpoint option is false (the default value), http client use the BasicCookieStore to store cookies.