3

I have client requests that are initiated through a Load balancer and routed to the least weighted Tomcat server to process.

When the client hits a target Tomcat server, the response to the client contains absolute URL's to be used for the second request. This essentially eliminates the load balancer to allow the client to communicate directly with the Tomcat instance for the life of the client session.

ISSUE: The issue is that the first request through the load balancer is creating a SESSION, then the second request directly to Tomcat creates a second SESSION for a single client. The first SESSION is just unused and expires eventually.

QUESTION: How can I connect the client on the second request, back to the SESSION that was created on the first request (through the load balancer)?

UPDATE: I tested this in JMeter and did not have any luck connecting the sessions.

Request one:

http://loadbalancer:80/page1.jsp

Response header:

Set-Cookie: JSESSIONID=070894D435A46DF60AFE506018018325; Path=/

Then the second request is:

http://directTomcat:8080/page2.jsp?token1=123&token2=xyz;JSESSIONID=070894D435A46DF60AFE506018018325

[no cookies]

Second Response headers:

Set-Cookie: JSESSIONID=1081A016CBA9B3AA7E7C38EF775C04F7; Path=/

I also tried:

http://directTomcat:8080/page2.jsp?token1=123&token2=xyz&JSESSIONID=070894D435A46DF60AFE506018018325

but that also did not work either.

Is it necessary to set the JSESSIONID as a cookie on the client before making the second request?

Mick Knutson
  • 2,297
  • 3
  • 25
  • 48
  • Do you have control in your Java code over the absolute URLs returned from the request made by the load balancer? If so you could append ;jsessionid=[sessionid] to the end. – Martin Wilson Oct 03 '12 at 19:53
  • Martin I do and I updated my original question with the testing that I did for this issue. – Mick Knutson Oct 16 '12 at 18:12
  • When appending the jessionid did you include the semicolon? Ignore this - just noticed you did. – Martin Wilson Oct 16 '12 at 20:15
  • Yep sorry. I actually spent quite a bit of time on this with Jmeter trying to simulate this and have not had any luck even though I seem to have a pretty good jmeter script to test with. – Mick Knutson Oct 16 '12 at 21:38
  • You're doing this wrong. You should get session stickiness working instead of all this malarkey. – user207421 Oct 16 '12 at 21:49
  • @EJP - my understanding is that Mick doesn't have a problem with sessions not being sticky, just that his (presumably 3rd-party, i.e. not Tomcat) load balancer creates its own session when it connects to assess load. – Martin Wilson Oct 17 '12 at 08:29
  • Martin you are correct. Then, after the 1st request, we take the load balancer out of the mix because it does not help the session anymore because there is NOT clustering, so not matter what each request must be tied to the Tomcat instance it starts with. – Mick Knutson Oct 17 '12 at 12:34

0 Answers0