Permalink
Browse files

HTTPASYNC-20: HTTP exchange can now be aborted with HttpUriRequest#ab…

…ort()

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpasyncclient/trunk@1368430 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 27a8266 commit 13c217cf2c8bf5e085f6a9d44143b5a1cd43b049 @ok2c ok2c committed Aug 2, 2012
View
@@ -1,6 +1,9 @@
Changes sicne release 4.0 Beta 1
-------------------
+* [HTTPASYNC-20] HTTP exchange can now be aborted with HttpUriRequest#abort().
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPASYNC-17] Caching HttpAsyncClient facade.
Contributed by Clinton Nielsen <clinton.h.nielsen at gmail.com>
@@ -54,13 +54,15 @@
import org.apache.http.client.RedirectException;
import org.apache.http.client.RedirectStrategy;
import org.apache.http.client.UserTokenHandler;
+import org.apache.http.client.methods.AbortableHttpRequest;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
+import org.apache.http.conn.ConnectionReleaseTrigger;
import org.apache.http.conn.routing.BasicRouteDirector;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.conn.routing.HttpRouteDirector;
@@ -92,7 +94,7 @@
class DefaultAsyncRequestDirector<T> implements HttpAsyncRequestExecutionHandler<T> {
private static final AtomicLong COUNTER = new AtomicLong(1);
-
+
private final Log log;
private final HttpAsyncRequestProducer requestProducer;
@@ -117,7 +119,7 @@
private volatile boolean closed;
private volatile ManagedClientAsyncConnection managedConn;
-
+
private RoutedRequest mainRequest;
private RoutedRequest followup;
private HttpResponse finalResponse;
@@ -209,6 +211,18 @@ public synchronized void start() {
HttpHost target = this.requestProducer.getTarget();
HttpRequest request = this.requestProducer.generateRequest();
+ if (request instanceof AbortableHttpRequest) {
+ ((AbortableHttpRequest) request).setReleaseTrigger(new ConnectionReleaseTrigger() {
+
+ public void releaseConnection() throws IOException {
+ }
+
+ public void abortConnection() throws IOException {
+ cancel();
+ }
+
+ });
+ }
this.params = new ClientParamsStack(null, this.clientParams, request.getParams(), null);
RequestWrapper wrapper = wrapRequest(request);
wrapper.setParams(this.params);
@@ -279,7 +293,7 @@ public synchronized HttpRequest generateRequest() throws IOException, HttpExcept
this.targetAuthState.update(
new BasicScheme(), new UsernamePasswordCredentials(userinfo));
}
-
+
// Re-write request URI if needed
rewriteRequestURI(this.currentRequest, route);
}

0 comments on commit 13c217c

Please sign in to comment.