You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/01/29 15:19:02 UTC
svn commit: r1439903 - in
/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src:
main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Author: olegk
Date: Tue Jan 29 14:19:02 2013
New Revision: 1439903
URL: http://svn.apache.org/viewvc?rev=1439903&view=rev
Log:
Do not automatically close HttpAsyncRequestExecutionHandler on an I/O error allowing the handler to retry
Modified:
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1439903&r1=1439902&r2=1439903&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Tue Jan 29 14:19:02 2013
@@ -104,8 +104,8 @@ public class HttpAsyncRequestExecutor im
public void closed(final NHttpClientConnection conn) {
State state = getState(conn);
HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
- if (state == null || !state.isValid()) {
- closeHandler(handler, null);
+ if (state == null || (handler != null && handler.isDone())) {
+ closeHandler(handler);
}
if (state != null) {
state.reset();
@@ -117,7 +117,7 @@ public class HttpAsyncRequestExecutor im
shutdownConnection(conn);
HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
if (handler != null) {
- closeHandler(handler, cause);
+ handler.failed(cause);
} else {
log(cause);
}
@@ -131,7 +131,7 @@ public class HttpAsyncRequestExecutor im
}
HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
if (handler != null && handler.isDone()) {
- closeHandler(handler, null);
+ closeHandler(handler);
state.reset();
handler = null;
}
@@ -258,7 +258,8 @@ public class HttpAsyncRequestExecutor im
if (state != null) {
if (state.getRequestState().compareTo(MessageState.READY) != 0) {
state.invalidate();
- closeHandler(getHandler(conn), new ConnectionClosedException("Connection closed"));
+ HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
+ handler.failed(new ConnectionClosedException("Connection closed"));
}
}
// Closing connection in an orderly manner and
@@ -283,7 +284,11 @@ public class HttpAsyncRequestExecutor im
return;
} else {
state.invalidate();
- closeHandler(getHandler(conn), new SocketTimeoutException());
+ HttpAsyncRequestExecutionHandler<?> handler = getHandler(conn);
+ if (handler != null) {
+ handler.failed(new SocketTimeoutException());
+ handler.close();
+ }
}
}
if (conn.getStatus() == NHttpConnection.ACTIVE) {
@@ -337,18 +342,12 @@ public class HttpAsyncRequestExecutor im
}
}
- private void closeHandler(final HttpAsyncRequestExecutionHandler<?> handler, final Exception ex) {
+ private void closeHandler(final HttpAsyncRequestExecutionHandler<?> handler) {
if (handler != null) {
try {
- if (ex != null) {
- handler.failed(ex);
- }
- } finally {
- try {
- handler.close();
- } catch (IOException ioex) {
- log(ioex);
- }
+ handler.close();
+ } catch (IOException ioex) {
+ log(ioex);
}
}
}
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java?rev=1439903&r1=1439902&r2=1439903&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java Tue Jan 29 14:19:02 2013
@@ -148,7 +148,6 @@ public class TestHttpAsyncRequestExecuto
this.protocolHandler.exception(this.conn, httpex);
Mockito.verify(this.exchangeHandler).failed(httpex);
- Mockito.verify(this.exchangeHandler).close();
Mockito.verify(this.conn).shutdown();
}
@@ -164,7 +163,6 @@ public class TestHttpAsyncRequestExecuto
this.protocolHandler.exception(this.conn, ioex);
Mockito.verify(this.exchangeHandler).failed(ioex);
- Mockito.verify(this.exchangeHandler).close();
Mockito.verify(this.conn).shutdown();
}