commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurent ForĂȘt <l.fo...@clipack.com>
Subject [HttpClient] How to use the cookie JSessionID for Applet/J2EE Connections.
Date Wed, 17 Mar 2004 13:17:50 GMT
Hello,

According to 2 threads in jguru.com website (33978, 85187), I try to use httpclient for connection

between applet and j2ee server.
For this, I want to reuse the opened session by the browser : using javascript I give the
JSESSIONID 
cookie value to the applet, and I try to use this cookie value with httpclient, without success.
Does anyone can help me !

Thanks, Laurent F.


The code applet is :

public class TestHttpClientApplet extends JApplet {

   private static String SESSIONID_PARAMETER = "jsessionid";
   private static String URL_PARAMETER = "serverurl";

   private MyHttpClient httpClient_;

   public TestHttpClientApplet() {
     super();
   }

   public void init() {
     String jsessionid = getParameter(SESSIONID_PARAMETER);
     String url = getParameter(URL_PARAMETER);
     httpClient_ = new MyHttpClient(jsessionid);
     JTextArea text = new JTextArea(100, 100);
     setContentPane(new JScrollPane(text));
     text.setText(new String(httpClient_.get(url)));
   }
}


The MyHttpClient code looks like this:

public class MyHttpClient {

   private HttpClient httpClient_ = new HttpClient();

   private String sessionId_;
   private final static String SESSION_ID = "JSESSIONID";

   public HttpClipackClient(String sessionId) {
     sessionId_ = sessionId;
   }

   public byte[] get(String url) throws MyException  {
//    GetMethod get = new GetMethod(url+";jsessionid="+sessionId_);
     GetMethod get = new GetMethod(url);
     get.setRequestHeader(SESSION_ID, sessionId_);
     try {
       statusCode = httpClient_.executeMethod(method);
     } catch (HttpRecoverableException hrex) {
       throw MyException(hrex);
     } catch (IOException ioex) {
       throw MyException(ioex);
     }

     if (statusCode == -1) {
       throw new MyException("Can not post "+method.getName());
     }
     byte[] response = method.getResponseBody();
     method.releaseConnection();
     return response;

   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message