FYI - Thanks much for this information. We had a what seemed like a bug using Linux/WPS/IBM-JDK to Windows/IIS using NTLM Auth... the code ran once or twice then started getting 401 responses. I believe the socket closed / or connection closed (then the NTLM negotiation was not performed again.)
Using a single HttpClient instead of new one for each method invokation plus using getResponseBodyAsString instead of getResonseBodyAsStream resolved it for us. IMHO adding Roland's 1..4 below to the site/tutorial would be a good thing. Thanks -TR > -----Original Message----- > From: Roland Weber [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 12, 2003 4:13 AM > To: Commons HttpClient Project > Subject: RE: getMethod.getResponseBody() leaks handles > > > David, Michael, > > I get the feeling you have entered a closed loop in your discussion. > Please let me add an observer's view, in hope to break the loop. > I'll adress this mail to David, since it's whom we are trying to help > with his problem. > I want to point out that I did not dive into the source code for this > mail, neither into that of the HTTP client nor that of David's test > program. I gathered my "evidence" just from the natural language > parts of the correspondence, and from my user-level knowledge > of the HTTP client. So, David: > > HttpMethod is not meant to close connections. It is meant to use > them, and then give them back to the connection manager, which > will decide whether to close or reuse them. There are some cases > in which the HttpMethod knows that the connection cannot be > reused and closes them, but that's not the regular case. > > From one of Michaels remarks I learned that you are creating a > new instance of the HTTP client and connection manager for > each request. Which means you are not using the HTTP client > in the way it is meant to be used. This may or may not indicate > a deficiency in the documentation. It probably does, see below. > > Actually, the connections do not leak when you execute your > HTTP method, or finish executing it. They leak when you forget > about the current connection manager rather than reusing it for > the next request. The difference in behavior between Linux and > Windows is due to the fact that the Linux JVM has a fall-back > cleanup mechanism which closes the connection, while the > Windows JVM has not. If you restructure your application, no > fall-back cleanup will come into this and behaviour will be similar > on both platforms. > > I guess the sample code on how to use the HTTP client for a > single request does not point out which part of the code is a > one-time initialization and which part needs to be repeated for > each request. So let me tell you: > 1. The HTTP Client instance and it's connection manager > should be created once, during initialization of the application. > Both are meant to be reused for all subsequent requests. > 2. Connections will be opened, closed or reused implicitly > by the connection manager (see 4). > 3. The HttpMethod objects can be created for each request, > or recycled if you want to. > 4. HttpMethod.releaseConnection() must be invoked after > each request. It will make sure that the connection used > for that request is given back to the connection manager. > > I hope this helps, > Roland > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]