hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ADEL...@jam.rr.com
Subject Re: RE: java 1.5 multithreaded problem
Date Thu, 11 Aug 2005 19:58:24 GMT
Thank you for responding....I appreciate all the help I can get with this.  

My application was using HttpClient.executeMethod(HttpMethod method).  I
modified it to use the version of the executeMethod you specified, but
unfortunately it didn't change the strange behaviour I am encountering.

I haven't had to do anything specific to handle cookies in my code, at
least under java 1.4.  But, it looks as though something related to
threading and cookies is definitely happening with my application under
1.5.  My application takes test cases from a configuration file, and
tries to execute each test case in its own thread, using the HttpClient
classes of course.  If I execute only one test case with one thread,
everything works fine under java 1.5.  If I run in multithreaded mode,
even if I'm only running one thread at a time, then my test cases start
to fail.  More specifically, it looks as though session information,
such as cookies, isn't being maintained from one URL call to the next.
If executed under java 1.4, it all works perfectly though.  

The following semi-pseudo code explains, hopefully in appropriate
detail, how I am using the HttpClient library.  Also, if there examples
of multithreaded applications such as what I describe below working with
java 1.5, I would be simply thrilled to see some source code.  

//numThreads is a user defined value
MultiThreadedHttpConnectionManager connectionManager= new
HttpClient httpClient= new HttpClient(connectionManager);

//Now, I have a configuration section that gets "testcases" from the
configuration files
testCaseConfig = config.getTestCaseConfiguration();

//Next I have a thread manager that runs through handing off test cases
to threads as they
//become available.  The thread takes the httpClient class in the
testCaseThread[x] = new testCaseThread(globalConfig, testCaseConfig,
sTestCaseDescription, iThreadCounter, httpClient);

//Within the tetCaseThread class, the hostConfiguration class is set
with necessary values
HostConfiguration hostConfiguration = new HostConfiguration();
hostConfiguration.setHost(sHost, iPort, "http");

//Next, I create the proper method, based on the method the URL requires
HttpMethod method= null;
PostMethod pmethod= null;
if (sMethod.equals("POST")) {
     pmethod= new PostMethod(sURLInfo);
} else {
     method= new GetMethod(sURLInfo);

//I then create NameValuePair objects
nvPair[y]= new NameValuePair(sName, URLDecoder.decode(sValue, "US-ASCII"));

//This is added to the proper method
if (sMethod.equals("POST")) pmethod.setRequestBody(nvPair);
else if (sMethod.equals("GET")) method.setQueryString(nvPair);

//I add the host configuration to the httpClient object

//The execute method is now called
if (sMethod.equals("POST")) httpClient.execute(pmethod);
else if (sMethod.equals("GET")) httpClient.execute(method);

//An input stream is then used to examine the data returned from the
InputStream iStream= null;
if (sMethod.equals("GET")) iStream= method.getResponseBodyAsStream();
else if (sMethod.equals("POST")) iStream= pmethod.getResponseBodyAsStream();

//Once the data is analyzed, the releaseConnection method is called
if (sMethod.equals("POST")) pmethod.releaseConnection();
else if (sMethod.equals("GET")) method.releaseConnection();

//Now the thread ends, and the thread handler will assign a test case to
a new instance of this thread.

----- Original Message -----
From: Steven Terrell <Steven.Terrell@guideworkstv.com>
Date: Thursday, August 11, 2005 12:04 pm
Subject: RE: java 1.5 multithreaded problem

> I am running HttpClient successfully in a multithreaded 
> environment, using
> Java 1.5 and HttpClient 3.0 rc3. My app also uses cookies. My original
> implementation used a single HttpState to get the cookies. I 
> worried about
> how to keep the cookies separate for all threads, so I switched my 
> clientcall to use HttpClient.execute(HostConfiguration, PostMethod, 
> HttpState).
> Each thread has its own state, so you are guaranteed that the 
> cookies for
> each thread are correct. I don't know if this is how you're 
> running, but it
> works for me.
> --Steve
> -----Original Message-----
> From: ADELONG@jam.rr.com [mailto:ADELONG@jam.rr.com] 
> Sent: Thursday, August 11, 2005 12:05 PM
> To: httpclient-user@jakarta.apache.org
> Subject: java 1.5 multithreaded problem
> I am trying to run an existing application that uses HttpClient, 
> with a
> new JVM.  Previously, I was using java 1.4.1, now I am trying to use
> java 1.5.0.  Additionally, I updated from httpclient 2.0 to httpclient
> 3.0 rc 3.
> The program I am trying to use (and I'm a developer of the application
> too) is webtester, http://webtester.sourceforge.net.   I upgraded the
> application to use httpclient 3.0 rc 3, and this worked fine under 
> java 1.4.
> When I try to run it under java 1.5, however, the httpclient classes
> seem to function differently somehow.  Namely, when I run the
> application in a multithreaded environment, cookies do not seem to be
> persistent.  
> I was wondering if anyone else has had a problem with using 
> httpclient,in a multithreaded environment, with java 1.5?  I 
> examined the list of
> changes for java 1.5, and httpclient 3.0, and did not identify 
> anythingobvious which would explain this.
> If I need to provide more information, or if I am posting to the wrong
> mailing list, then my apologies in advance.
> Thank you.
> --------------------------------------------------------------------
> -
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-
> help@jakarta.apache.org
> --------------------------------------------------------------------
> -
> To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-user-
> help@jakarta.apache.org

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

View raw message