hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leena Borle" <lsbo...@gmail.com>
Subject HttpClient invalidates session
Date Wed, 16 Jul 2008 23:18:42 GMT
Hi,
  I have a struts-2 application running on Tomcat-5 with Single Sign on
enabled. What I am trying to do is , use HttpClient(struts2 app) to access
data  other WAR(say WAR2) which also has Form Based login system. To avoid
sending user's credentials(Which I don't have in my application), I am
trying to send cookie-JSESSIOIDSSO in the request header.
  Everything works fine, I get the data back. But after that, my application
throws error that, session is invalidated.
  How do I stop HttpClient from invalidating the session ?

Thanks
Leena.

Here is the code in my application ,

(Struts-2) HttpServletRequest request = ServletActionContext.getRequest();

        //try out httpclient

        javax.servlet.http.Cookie[] cookies = request.getCookies();
        HttpState newState = new HttpState();
        javax.servlet.http.Cookie ssoID = null;
        for(int c = 0; c < cookies.length; c ++) {
            javax.servlet.http.Cookie k = cookies[c];
            if(k.getName().equalsIgnoreCase("JSESSIONIDSSO"))
                ssoID=k;
        }


        HttpClient client = new HttpClient();
        client.setState(newState);
        GetMethod getMethod  = new GetMethod("
http://localhost:8080/war2/exceuteServlet");

getMethod.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.IGNORE_COOKIES);

        getMethod.setRequestHeader("Cookie", ssoID.getName() + "=" +
ssoID.getValue());
        try {

            int responseCode =
client.executeMethod(null,getMethod,newState);
            String body = getMethod.getResponseBodyAsString();

            AppLogger.getLogger().debug("Response code = " + responseCode+ "
\nResponse is " + body);

          } catch (HttpException e) {
              // TODO Auto-generated catch block

          } catch (IOException e) {
              // TODO Auto-generated catch block

          } finally {
              // release any connection resources used by the method
              getMethod.releaseConnection();
          }

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message