This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlets, cookies, sessions, load balancing and coldfusion (phew!). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets, cookies, sessions, load balancing and coldfusion (phew!)." Watch "Servlets, cookies, sessions, load balancing and coldfusion (phew!)." New topic

Servlets, cookies, sessions, load balancing and coldfusion (phew!).

Jon Pincott

Joined: Jul 28, 2004
Posts: 17
Hi all,

Sorry if this is the wrong place to be posting this, but I've got a problem with a file upload mechanism i've been developing for a coldfusion web app...

Coldfusion5 can't handle large file uploads, so I've written a servlet to take care of the file processing, sandwiched between two coldfusion pages handling the upload form and post-upload processing. The form allows for multiple file uploads.

A file upload proceeds as follows:
1) User opens form.cfm on server A.
2) Form submits data to servlet on server B.
3) For each file submitted, the servlet:
a) writes the file to a storage area on server C,
b) calls log.cfm on server A to do logging etc.
4) Servlet redirects to the originating form.cfm on server A.

I'm using a URLConnection for the communication in (3b).
I'm using the HTTP_REFERER header to get the url of the originating page (4)and as a base url for the log.cfm page (3b).
I'm passing session tokens to the servlet via hidden parameters in (2) and appending them to the log.cfm url in (3b) so that the two pages share the same session.

I've had this working reliably in my test environment but now that I've come to deploy it in production i've hit a snag. The problem is that in production server A is actually 2 servers (A1 & A2) sat behind a load balancer. When I read HTTP_REFERER I get the address of the load balancer, not the originating server. This means that when I call log.cfm (3b) using HTTP_REFERER as the base for the url, I don't necessarily end up on the same server, e.g. form.cfm on A1 -> servlet on B -> log.cfm on A2, and I lose my session.

The load balancer uses a cookie to make sure that a session stays on one server, so I'm trying to send that cookie along with the session tokens in (2) to the servlet so it can use it in (3b) to force the load balancer into directing the request for log.cfm to the same server.

I can get the cookie to the servlet, but I'm having problems sending it from the servlet to log.cfm. I've tried setRequestProperty(...) on the URLConnection but it doesn't seem to be working.

Has anyone got any suggestions?


P.S. Thanks for reading this far!
[ May 18, 2005: Message edited by: Jon Pincott ]

Jon Pincott

Joined: Jul 28, 2004
Posts: 17
Hmm, turns out that setRequestProperty("HTTP_COOKIE", myCookies) actually sets a header called "HTTP_HTTP_COOKIE"!

Problem solved.
I agree. Here's the link:
subject: Servlets, cookies, sessions, load balancing and coldfusion (phew!).
It's not a secret anymore!