URLConnection & jsessionid to keep httpSession

Hi,

I would like to simulate a request from my browser client, through the URLConnection class.

My problem is that my Tomcat creates a new HTTPSession each time I make the urlConnection.getInputStream().

I would like Tomcat to use the browser's session, which I set like that :

urlconnection.setRequestProperty("Cookie","jsessionid=" + jsessionid);

urlconnection.setUseCaches(false);

urlconnection.connect();

urlconnection.getInputStream();

I found some links about this problem, but the following one is not found anymore :

http://forum.java.sun.com/thread.jspa?forumID=33&threadID=67175

Others links :

http://forum.java.sun.com/thread.jspa?forumID=33&threadID=632438

http://forum.java.sun.com/thread.jspa?forumID=33&threadID=599361

This is what happens :

1/ browser makes a request to the server

2/ the server answers the request

2.1/ In parallel, i make my urlConnection, with the jsessionid

2.2/ The server creates a new HttpSession :-(

The problem is that, those urlConnection create as many HttpSession on the server as the number of time they are called

Any help ? :p

[1292 byte] By [el_teedeea] at [2007-11-27 3:59:21]
# 1

Oh ! I found something that seams to work. I did it before, but not with the good sessionId, so the server created a new session anyway.

The way i call my function callUrl :

SessionUtil.callUrl("custom/abcd/stats/loginStat.jsp;jsessionid=" + session.getId() + "?mbrId=" + mbr.getId(), true);

the url called is for example :

custom/sipg/stats/loginStat.jsp;jsessionid=F11EB0A62628D13672945C29434188A8?mbrId=c_11634

but this time, the jsessionid is the good one :p, and the server reuse the existing session passed in the url, great !

el_teedeea at 2007-7-12 9:03:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...