[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-users
Subject:    Re: RE: java 1.5 multithreaded problem
From:       "Aaron DeLong" <adelong () jam ! rr ! com>
Date:       2005-08-20 17:41:19
Message-ID: 002e01c5a5ae$5f9bdd70$6401a8c0 () Thor
[Download RAW message or body]

Thank you for your help.

Comparing headers from the two logs allowed me to discover that the problem 
wasn't with HttpClient, but with my application.  Specifically, under java 
1.5, the xerces parser, at least the version I'm using, returns "null" 
rather than an empty string for XML elements with 0 length content.  Anyway, 
the result was that under java 1.5 the body one of my POST requests wasn't 
being set, thus the problem I observed.

Once again, I appreciate your help.

Thank you.

----- Original Message ----- 
From: "Oleg Kalnichevski" <olegk@apache.org>
To: "HttpClient User Discussion" <httpclient-user@jakarta.apache.org>
Sent: Thursday, August 11, 2005 4:49 PM
Subject: Re: RE: java 1.5 multithreaded problem


> Consider producing two context/wire logs, one with JRE 1.4 and anther
> one with JRE 1.5, and post them to this list if you fail to spot the
> problem yourself
>
> Oleg
>
> On Thu, 2005-08-11 at 14:58 -0500, ADELONG@jam.rr.com wrote:
>> 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
>> MultiThreadedHttpConnectionManager();
>> connectionManager.setMaxTotalConnections(numThreads);
>> 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
>> constructor
>> testCaseThread[x] = new testCaseThread(globalConfig, testCaseConfig,
>> sTestCaseDescription, iThreadCounter, httpClient);
>> testCaseThread[x].start();
>>
>> //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);
>>      pmethod.setFollowRedirects(true);
>> } else {
>>      method= new GetMethod(sURLInfo);
>>      method.setFollowRedirects(true);
>> }
>>
>> //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
>> httpClient.setHostConfiguration(hostConfiguration);
>>
>> //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
>> operation
>> 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
>>
>>
>
>
> ---------------------------------------------------------------------
> 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic