mbecke 2003/12/18 22:02:13 Modified: httpclient/src/test/org/apache/commons/httpclient Tag: HTTPCLIENT_2_0_BRANCH TestHttpConnectionManager.java httpclient/src/java/org/apache/commons/httpclient Tag: HTTPCLIENT_2_0_BRANCH HttpMethodBase.java Log: Connections are now closed and released automatically when an unrecoverable exception occurs in HttpMethodBase.processRequest(). PR: 25370 Submitted by: Michael Becke Reviewed by: Oleg Kalnichevski Revision Changes Path No revision No revision 1.8.2.3 +37 -4 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java Index: TestHttpConnectionManager.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttpConnectionManager.java,v retrieving revision 1.8.2.2 retrieving revision 1.8.2.3 diff -u -r1.8.2.2 -r1.8.2.3 --- TestHttpConnectionManager.java 19 Nov 2003 13:27:42 -0000 1.8.2.2 +++ TestHttpConnectionManager.java 19 Dec 2003 06:02:13 -0000 1.8.2.3 @@ -246,6 +246,39 @@ assertNull("connectionManager should be null", connectionManager); } + public void testWriteRequestReleaseConnection() { + + MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.setMaxConnectionsPerHost(1); + + HttpClient client = createHttpClient(connectionManager); + + GetMethod get = new GetMethod("/") { + protected boolean writeRequestBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { + throw new IOException("Oh no!!"); + } + }; + + try { + client.executeMethod(get); + fail("An exception should have occurred."); + } catch (HttpException e) { + e.printStackTrace(); + fail("HttpException should not have occurred: " + e); + } catch (IOException e) { + // expected + } + + try { + connectionManager.getConnection(client.getHostConfiguration(), 1); + } catch (HttpException e) { + e.printStackTrace(); + fail("Connection was not released: " + e); + } + + } + public void testReleaseConnection() { MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); No revision No revision 1.159.2.21 +12 -4 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.159.2.20 retrieving revision 1.159.2.21 diff -u -r1.159.2.20 -r1.159.2.21 --- HttpMethodBase.java 14 Dec 2003 22:41:37 -0000 1.159.2.20 +++ HttpMethodBase.java 19 Dec 2003 06:02:13 -0000 1.159.2.21 @@ -2685,6 +2685,14 @@ doneWithConnection = true; throw httpre; } + } catch (IOException e) { + connection.close(); + doneWithConnection = true; + throw e; + } catch (RuntimeException e) { + connection.close(); + doneWithConnection = true; + throw e; } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]