title: same HttpClient multiple request ends up with different HttpSession
body: <p>I am using the new Apache HttpClient 4.2 (not the one from Apache Commons).</p>
  
  <p>I need to open up one HttpClient and make multiple requests to the same server. From the documentation, the httpClient should automatically maintain the cookie, and therefore have the multiple requests fall in the same session. However, on the server side, I am debugging thru and see that </p>
  
  <pre><code>HttpSession session = req.getHttpSession(true);
  </code></pre>
  
  <p>is returning a new HttpSession Object every time.</p>
  
  <p>my client code is like this.</p>
  
  <p>// 1st time</p>
  
  <pre><code>HttpClient httpClient = new DefaultHttpClient();
              req.getSession(true).setAttribute(HTTPCLIENT, httpClient);
  
              HttpGet httpget = new HttpGet(redirectUrl);
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              String content = httpClient.execute(httpget, responseHandler);
  
  // subsequent calls
  HttpClient httpClient = getHttpClient(req);
  
              HttpGet httpget = new HttpGet(redirectUrl);
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
              String content = httpClient.execute(httpget, responseHandler);
  
  
  // supported by the private method
  
  private HttpClient getHttpClient(HttpServletRequest req){
          return (HttpClient) req.getSession(true).getAttribute(HTTPCLIENT);
      }
  </code></pre>
  
  <p>did I do anything wrong?</p>