5 Replies Latest reply on Jul 10, 2006 3:43 PM by chwang

    How to send a request to a node instance that I specify

      Hi, Folks,

      I have a web report service application, which is a servlet application, accepting the requests from clients ( using UrlConnection.connect() ) to generate report. I have setup 2 instances in my computer using clustering.

      The work flow is like this:

      1.) the client use

      new URL(http://locahost/report/submit? ).connection()

      to submit request to report server to generate a report. At report server site, it will generate a sessionID, for example:

      D914C93143AF95B2712C64E7637EED68.node1
      ,

      This ID will save in a hashtable of report server code , and the server responds this id to client.

      2.) After client gets this id, every 15 seconds, the client will use this id to query the status of the percentage of report done.
      new URL(http://locahost/report/query?id=D914C93143AF95B2712C64E7637EED68.node1 ).connection()


      the current issue is the each request doesn't maintain a Session, so
      when the client sends the first query to node1, the second query will send the node2, but node2 doesn't save the id, so the client gets no id for the second quest.

      I have set up
      worker.loadbalancer.sticky_session=1

      in workers.perperties. but it is not useful.

      1.)There is any way to fix this issue?

      2.) or can I specify a node to send? because I know seesion id is
      like this
      D914C93143AF95B2712C64E7637EED68.node1
      , I can retrieve node1 , so I can send the request to it.

      Thank you.

      Chwang








      Thank you very much.

      Chwang


        • 1. Re: How to send a request to a node instance that I specify

          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

            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

              Hi, Geert,

              I also read the link you gave me
              http://wiki.jboss.org/wiki/Wiki.jsp?page=UsingMod_proxyWithJBoss

              there is this set up

              Add 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 as
              reuest.getSession(true).getId()


              Chwang

              • 4. Re: How to send a request to a node instance that I specify

                 

                Cookie mycookie = new Cookie(D914C93143AF95B2712C64E7637EED68.node1 , "");
                response.addCookie( mycookie );


                No, that would be
                Cookie 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

                  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