-
1. Re: How to send a request to a node instance that I specify
greyfairer Jul 5, 2006 1:03 PM (in response to chwang)Hi chwang,
Mod_jk will recognize your session id request parameter only if it's called jsessionid, I suppose.
Why don't you use the 'real' HttpSession? In you servlet, you use getSession(true), this will generate a sessionId for you, and put it in a JSESSIONID cookie in the response. In the next request, you put this cookie in the request, and mod_jk will also recognize this. If your client would use commons-httpclient, this all goes automatically. HttpClient will keep all cookies, including the JSESSIONID, in a HttpState object, that you can reuse for the next request. It will even retain Credentials.
Instead of mod_jk, you could also use mod_proxy_balancer from Apache 2.2. You can configure the stickysession parameter of the balancers to JSESSIONID or PHPSESSIONID, maybe others, too, or even use your own rewrite rules like in http://wiki.jboss.org/wiki/Wiki.jsp?page=UsingMod_proxyWithJBoss
Greets,
Geert. -
2. Re: How to send a request to a node instance that I specify
chwang Jul 5, 2006 5:13 PM (in response to chwang)Hi, Geert,
Thank you very much.
I used(request.getSession(true)).getId()
to generate id.
D914C93143AF95B2712C64E7637EED68.node1 is genrated by above code.
I have a couple of questions.
1.) you mean I put this id in the cookie,
like this:
Cookie mycookie = new Cookie(D914C93143AF95B2712C64E7637EED68.node1 , "");
reposnse.addCookie( mycookie );
then at the client site, using HTTPClient to keep this cookie.
I know HTTPClient is from Apache, There is any related class from Sun' library?
2.) if I use mod_proxy_balancer instead of mod_jk, I wonder if I don't need to use cookie nad httpclient. becasue I have written code using URLconnection. with only mod_proxy_balancer setup will make it easy.
Chwang -
3. Re: How to send a request to a node instance that I specify
chwang Jul 5, 2006 6:36 PM (in response to chwang)Hi, Geert,
I also read the link you gave me
http://wiki.jboss.org/wiki/Wiki.jsp?page=UsingMod_proxyWithJBoss
there is this set upAdd stickysession parameter to ProxyPass ProxyPass /jmx-console balancer://mycluster stickysession=jsessionid lbmethod=bytraffic nofailover=Off ProxyPassReverse /jmx-console balancer://mycluster
Coule you tell me what is jsessionid, it is the same asreuest.getSession(true).getId()
Chwang -
4. Re: How to send a request to a node instance that I specify
greyfairer Jul 6, 2006 8:51 AM (in response to chwang)Cookie mycookie = new Cookie(D914C93143AF95B2712C64E7637EED68.node1 , "");
response.addCookie( mycookie );
No, that would beCookie mycookie = new Cookie("JSESSIONID", "D914C93143AF95B2712C64E7637EED68.node1");
But I think that gets done automatically by the servlet API.
There is no API from Sun AFAIK to manipulate cookies, other than parsing the HTTP Headers yourself and writing them back on the URLConnection.
If you use mod_proxy_balancer as in the wiki, sticky sessions should also work if you specify the jsessionid in the URL, instead of a cookie, using ";jsessionid=...".new URL("http://locahost/report/query?;jsessionid=D914C93143AF95B2712C64E7637EED68.node1" ).connection()
-
5. Re: How to send a request to a node instance that I specify
chwang Jul 10, 2006 3:43 PM (in response to chwang)Hi, Geert,
I tried both ways, they don't work.
First, I used httpclient to set cookie, but Appache2.0 still sends the package to different node.
Second, I used Apache2.2, mod_proxy, mod_proxy_ http , mod_proxy_balancer ,does't work well.
Thank you very much. I am not sure the reason why.
Chwang