Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 50103 invoked from network); 17 Mar 2004 19:39:04 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 17 Mar 2004 19:39:04 -0000 Received: (qmail 39738 invoked by uid 500); 17 Mar 2004 19:38:49 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 39708 invoked by uid 500); 17 Mar 2004 19:38:48 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 39682 invoked from network); 17 Mar 2004 19:38:48 -0000 Received: from unknown (HELO mail6.bluewin.ch) (195.186.4.229) by daedalus.apache.org with SMTP; 17 Mar 2004 19:38:48 -0000 Received: from [192.168.0.2] (81.62.21.22) by mail6.bluewin.ch (Bluewin AG 7.0.027) id 4055A1BD0005DC47 for commons-user@jakarta.apache.org; Wed, 17 Mar 2004 19:38:52 +0000 Subject: Re: [HttpClient] How to use the cookie JSessionID for Applet/J2EE Connections. From: Oleg Kalnichevski To: Jakarta Commons Users List In-Reply-To: <40584FFE.6060402@clipack.com> References: <40584FFE.6060402@clipack.com> Content-Type: text/plain; charset=ISO-8859-1 Message-Id: <1079552331.13104.5.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 (1.4.5-7) Date: Wed, 17 Mar 2004 20:38:51 +0100 Content-Transfer-Encoding: 8bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Laurent, Try using the session cookie instead: String jsessionid = getParameter(SESSIONID_PARAMETER); HttpClient agent = new HttpClient(); Cookie sessionCookie = new Cookie(".mycompany.com", "jsessionid", jsessionid, "/", null, false); agent.getState().addCookie(sessionCookie); GetMethod httpget = new GetMethod( "http://mycompany.com/protected/whatever.url"); try { agent.executeMethod(httpget); System.out.println(httpget.getStatusLine()); } finally { httpget.releaseConnection(); } Make sure that you get the domain and path attributes of the session cookie right, otherwise the cookie will not be sent with the request Oleg On Wed, 2004-03-17 at 14:17, Laurent For�t wrote: > 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 > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org