code: public static String removeSessionId(String uri, HttpResponse httpResponse) {
          CookieSpec cookieSpec = new DefaultCookieSpec();
          // Dummy origin, used only by CookieSpec for setting the domain for the
          // cookie but we don't need it
          CookieOrigin cookieOrigin = new CookieOrigin("dummy", Http.DEFAULT_HTTP_PORT, "/", false);
          Header[] responseHeaders = httpResponse.getHeaders("Set-cookie");
          String jsessionid = null;
          for (Header header : responseHeaders) {
              try {
                  List<Cookie> cookies = cookieSpec.parse(header, cookieOrigin);
                  for (Cookie cookie : cookies) {
                      if ("JSESSIONID".equalsIgnoreCase(cookie.getName())) {
                          jsessionid = cookie.getValue();
                      }
                      break;
                  }
              } catch (MalformedCookieException ex) {
                  LOG.warn("Malformed header: " + header.getName() + ": " + header.getValue());
              }
              if (jsessionid != null) {
                  break;
              }
          }
          if (jsessionid == null) {
              return uri;
          }
  
          return UriUtils.removeSessionId(jsessionid, uri);
  
      }
docs: Removes ";jsessionid=&lt;id&gt;" from the url, if the session id is also set in "httpResponse".
  <p>
  This methods first looks for the following header :
  
  <pre>
  Set-Cookie: JSESSIONID=
  </pre>
  
  If found and perfectly matches the jsessionid value in url, the complete jsessionid definition is removed from
  the url.
  
  @param uri
  original uri, may contains a jsessionid.
  @param httpResponse
  the response which set the jsessionId
  @return uri, without jsession