Permalink
Browse files

Upgraded HttpCore to 4.2-beta1

  • Loading branch information...
ok2c committed Feb 6, 2012
1 parent 19ab830 commit cd7f9317b04a2535c182398de8d43558b993652f
Showing with 272 additions and 227 deletions.
  1. +2 −0 .gitignore
  2. +8 −8 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractHttpAsyncClient.java
  3. +32 −24 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultAsyncRequestDirector.java
  4. +6 −6 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
  5. +1 −1 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalIOReactorExceptionHandler.java
  6. +21 −20 ...pache/http/impl/nio/client/{LoggingClientProtocolHandler.java → LoggingAsyncRequestExecutor.java}
  7. +4 −4 httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
  8. +1 −1 httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/LoggingIOSession.java
  9. +11 −3 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncByteConsumer.java
  10. +19 −24 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/AsyncCharConsumer.java
  11. +15 −12 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/BaseZeroCopyRequestProducer.java
  12. +6 −3 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/HttpAsyncMethods.java
  13. +15 −5 httpasyncclient/src/main/java/org/apache/http/nio/client/methods/ZeroCopyConsumer.java
  14. +1 −3 httpasyncclient/src/main/java/org/apache/http/nio/conn/OperatedAsyncClientConnection.java
  15. +2 −2 httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java
  16. +23 −24 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestClientAuthentication.java
  17. +12 −10 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpAsync.java
  18. +2 −2 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsAsync.java
  19. +2 −2 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestHttpsRedirects.java
  20. +28 −26 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestRedirects.java
  21. +19 −9 httpasyncclient/src/test/java/org/apache/http/impl/nio/client/TestStatefulConnManagement.java
  22. +11 −10 httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java
  23. +15 −17 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
  24. +15 −10 httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
  25. +1 −1 pom.xml
View
@@ -4,3 +4,5 @@
.clover
.externalToolBuilders
target
+maven-eclipse.xml
+
@@ -75,15 +75,15 @@
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
import org.apache.http.impl.cookie.RFC2109SpecFactory;
import org.apache.http.impl.cookie.RFC2965SpecFactory;
-import org.apache.http.impl.nio.DefaultClientIODispatch;
+import org.apache.http.impl.nio.DefaultHttpClientIODispatch;
import org.apache.http.impl.nio.conn.DefaultHttpAsyncRoutePlanner;
import org.apache.http.impl.nio.conn.PoolingAsyncClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.nio.reactor.IOEventDispatch;
@@ -101,7 +101,7 @@
private final Log log = LogFactory.getLog(getClass());;
private final ClientAsyncConnectionManager connmgr;
- private final Queue<HttpAsyncClientExchangeHandler<?>> queue;
+ private final Queue<HttpAsyncRequestExecutionHandler<?>> queue;
private Thread reactorThread;
private BasicHttpProcessor mutableProcessor;
@@ -124,15 +124,15 @@
protected AbstractHttpAsyncClient(final ClientAsyncConnectionManager connmgr) {
super();
this.connmgr = connmgr;
- this.queue = new ConcurrentLinkedQueue<HttpAsyncClientExchangeHandler<?>>();
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncRequestExecutionHandler<?>>();
}
protected AbstractHttpAsyncClient(final IOReactorConfig config) throws IOReactorException {
super();
DefaultConnectingIOReactor defaultioreactor = new DefaultConnectingIOReactor(config);
defaultioreactor.setExceptionHandler(new InternalIOReactorExceptionHandler(this.log));
this.connmgr = new PoolingAsyncClientConnectionManager(defaultioreactor);
- this.queue = new ConcurrentLinkedQueue<HttpAsyncClientExchangeHandler<?>>();
+ this.queue = new ConcurrentLinkedQueue<HttpAsyncRequestExecutionHandler<?>>();
}
protected abstract HttpParams createHttpParams();
@@ -454,16 +454,16 @@ public synchronized void removeRequestInterceptorByClass(Class<? extends HttpReq
}
private void doExecute() {
- LoggingClientProtocolHandler handler = new LoggingClientProtocolHandler();
+ LoggingAsyncRequestExecutor handler = new LoggingAsyncRequestExecutor();
try {
- IOEventDispatch ioEventDispatch = new DefaultClientIODispatch(handler, getParams());
+ IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(handler, getParams());
this.connmgr.execute(ioEventDispatch);
} catch (Exception ex) {
this.log.error("I/O reactor terminated abnormally", ex);
} finally {
this.terminated = true;
while (!this.queue.isEmpty()) {
- HttpAsyncClientExchangeHandler<?> exchangeHandler = this.queue.remove();
+ HttpAsyncRequestExecutionHandler<?> exchangeHandler = this.queue.remove();
exchangeHandler.cancel();
}
}
@@ -80,8 +80,8 @@
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
import org.apache.http.nio.conn.ManagedAsyncClientConnection;
import org.apache.http.nio.conn.scheme.AsyncScheme;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
-import org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
import org.apache.http.params.HttpConnectionParams;
@@ -91,7 +91,7 @@
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpProcessor;
-class DefaultAsyncRequestDirector<T> implements HttpAsyncClientExchangeHandler<T> {
+class DefaultAsyncRequestDirector<T> implements HttpAsyncRequestExecutionHandler<T> {
private final Log log;
@@ -171,6 +171,10 @@ public synchronized void close() throws IOException {
public synchronized void start() {
try {
+
+ this.localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetAuthState);
+ this.localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
+
HttpHost target = this.requestProducer.getTarget();
HttpRequest request = this.requestProducer.generateRequest();
this.params = new ClientParamsStack(null, this.clientParams, request.getParams(), null);
@@ -229,7 +233,10 @@ public synchronized HttpRequest generateRequest() throws IOException, HttpExcept
target = route.getTargetHost();
}
HttpHost proxy = route.getProxyHost();
-
+ this.localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
+ this.localContext.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
+ this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, this.managedConn);
+
if (this.currentRequest == null) {
this.currentRequest = this.mainRequest.getRequest();
// Re-write request URI if needed
@@ -238,14 +245,6 @@ public synchronized HttpRequest generateRequest() throws IOException, HttpExcept
// Reset headers on the request wrapper
this.currentRequest.resetHeaders();
- this.localContext.setAttribute(ExecutionContext.HTTP_REQUEST, this.currentRequest);
- this.localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
- this.localContext.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy);
- this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, this.managedConn);
- this.localContext.setAttribute(ClientContext.TARGET_AUTH_STATE, this.targetAuthState);
- this.localContext.setAttribute(ClientContext.PROXY_AUTH_STATE, this.proxyAuthState);
-
- this.httppocessor.process(this.currentRequest, this.localContext);
this.currentRequest.incrementExecCount();
if (this.currentRequest.getExecCount() > 1
&& !this.requestProducer.isRepeatable()
@@ -277,7 +276,7 @@ public boolean isRepeatable() {
return this.requestProducer.isRepeatable();
}
- public void resetRequest() {
+ public void resetRequest() throws IOException {
this.requestProducer.resetRequest();
}
@@ -288,8 +287,6 @@ public synchronized void responseReceived(
}
this.currentResponse = response;
this.currentResponse.setParams(this.params);
- this.localContext.setAttribute(ExecutionContext.HTTP_RESPONSE, this.currentResponse);
- this.httppocessor.process(this.currentResponse, this.localContext);
int status = this.currentResponse.getStatusLine().getStatusCode();
@@ -339,7 +336,7 @@ public synchronized void consumeContent(
private void releaseConnection() {
if (this.managedConn != null) {
try {
- this.managedConn.getContext().removeAttribute(HttpAsyncClientProtocolHandler.HTTP_HANDLER);
+ this.managedConn.getContext().removeAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER);
this.managedConn.releaseConnection();
} catch (IOException ioex) {
this.log.debug("I/O error releasing connection", ioex);
@@ -361,7 +358,16 @@ private void releaseResources() {
this.connFuture.cancel(true);
this.connFuture = null;
}
- this.requestProducer.resetRequest();
+ try {
+ this.requestProducer.close();
+ } catch (IOException ex) {
+ this.log.debug("I/O error closing request producer", ex);
+ }
+ try {
+ this.responseConsumer.close();
+ } catch (IOException ex) {
+ this.log.debug("I/O error closing response consumer", ex);
+ }
}
public synchronized void failed(final Exception ex) {
@@ -485,7 +491,7 @@ private synchronized void connectionRequestCompleted(final ManagedAsyncClientCon
conn.open(route, this.localContext, this.params);
}
this.managedConn = conn;
- this.managedConn.getContext().setAttribute(HttpAsyncClientProtocolHandler.HTTP_HANDLER, this);
+ this.managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this);
this.managedConn.requestOutput();
this.routeEstablished = route.equals(conn.getRoute());
} catch (IOException ex) {
@@ -499,20 +505,18 @@ private synchronized void connectionRequestCompleted(final ManagedAsyncClientCon
private synchronized void connectionRequestFailed(final Exception ex) {
this.log.debug("Connection request failed", ex);
try {
- this.requestProducer.resetRequest();
- this.responseConsumer.failed(ex);
- } finally {
this.resultCallback.failed(ex, this);
+ } finally {
+ releaseResources();
}
}
private synchronized void connectionRequestCancelled() {
this.log.debug("Connection request cancelled");
try {
- this.requestProducer.resetRequest();
- this.responseConsumer.cancel();
- } finally {
this.resultCallback.cancelled(this);
+ } finally {
+ releaseResources();
}
}
@@ -856,6 +860,10 @@ public HttpContext getContext() {
return this.localContext;
}
+ public HttpProcessor getHttpProcessor() {
+ return this.httppocessor;
+ }
+
public ConnectionReuseStrategy getConnectionReuseStrategy() {
return this.reuseStrategy;
}
@@ -29,31 +29,31 @@
import java.util.Queue;
import org.apache.http.concurrent.BasicFuture;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
class DefaultResultCallback<T> implements ResultCallback<T> {
private final BasicFuture<T> future;
- private final Queue<HttpAsyncClientExchangeHandler<?>> queue;
+ private final Queue<HttpAsyncRequestExecutionHandler<?>> queue;
DefaultResultCallback(
- final BasicFuture<T> future, final Queue<HttpAsyncClientExchangeHandler<?>> queue) {
+ final BasicFuture<T> future, final Queue<HttpAsyncRequestExecutionHandler<?>> queue) {
super();
this.future = future;
this.queue = queue;
}
- public void completed(final T result, final HttpAsyncClientExchangeHandler<T> handler) {
+ public void completed(final T result, final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.completed(result);
this.queue.remove(handler);
}
- public void failed(final Exception ex, final HttpAsyncClientExchangeHandler<T> handler) {
+ public void failed(final Exception ex, final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.failed(ex);
this.queue.remove(handler);
}
- public void cancelled(final HttpAsyncClientExchangeHandler<T> handler) {
+ public void cancelled(final HttpAsyncRequestExecutionHandler<T> handler) {
this.future.cancel(true);
this.queue.remove(handler);
}
@@ -50,4 +50,4 @@ public boolean handle(final RuntimeException ex) {
return false;
}
-}
+}
@@ -35,23 +35,25 @@
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.protocol.HttpAsyncClientProtocolHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutor;
-class LoggingClientProtocolHandler extends HttpAsyncClientProtocolHandler {
+class LoggingAsyncRequestExecutor extends HttpAsyncRequestExecutor {
- private final Log log = LogFactory.getLog(HttpAsyncClientProtocolHandler.class);
+ private final Log log = LogFactory.getLog(HttpAsyncRequestExecutor.class);
- public LoggingClientProtocolHandler() {
+ public LoggingAsyncRequestExecutor() {
super();
}
@Override
- protected void onException(final Exception ex) {
+ protected void log(final Exception ex) {
this.log.debug(ex.getMessage(), ex);
}
@Override
- public void connected(final NHttpClientConnection conn, final Object attachment) {
+ public void connected(
+ final NHttpClientConnection conn,
+ final Object attachment) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Connected");
}
@@ -63,58 +65,57 @@ public void closed(final NHttpClientConnection conn) {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Disconnected");
}
+ super.closed(conn);
}
@Override
- public void exception(final NHttpClientConnection conn, final HttpException ex) {
+ public void exception(final NHttpClientConnection conn, final Exception ex) {
if (this.log.isErrorEnabled()) {
this.log.error(conn + " HTTP protocol exception: " + ex.getMessage(), ex);
}
super.exception(conn, ex);
}
@Override
- public void exception(final NHttpClientConnection conn, final IOException ex) {
- if (this.log.isErrorEnabled()) {
- this.log.error(conn + " I/O error: " + ex.getMessage(), ex);
- }
- super.exception(conn, ex);
- }
-
- @Override
- public void requestReady(final NHttpClientConnection conn) {
+ public void requestReady(
+ final NHttpClientConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Request ready");
}
super.requestReady(conn);
}
@Override
- public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
+ public void inputReady(
+ final NHttpClientConnection conn,
+ final ContentDecoder decoder) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Input ready " + decoder);
}
super.inputReady(conn, decoder);
}
@Override
- public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
+ public void outputReady(
+ final NHttpClientConnection conn,
+ final ContentEncoder encoder) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Output ready " + encoder);
}
super.outputReady(conn, encoder);
}
@Override
- public void responseReceived(final NHttpClientConnection conn) {
+ public void responseReceived(
+ final NHttpClientConnection conn) throws HttpException, IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Response received");
}
super.responseReceived(conn);
}
@Override
- public void timeout(final NHttpClientConnection conn) {
+ public void timeout(final NHttpClientConnection conn) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Timeout");
}
@@ -26,15 +26,15 @@
*/
package org.apache.http.impl.nio.client;
-import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
+import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
interface ResultCallback<T> {
- void completed(T result, HttpAsyncClientExchangeHandler<T> handler);
+ void completed(T result, HttpAsyncRequestExecutionHandler<T> handler);
- void failed(Exception ex, HttpAsyncClientExchangeHandler<T> handler);
+ void failed(Exception ex, HttpAsyncRequestExecutionHandler<T> handler);
- void cancelled(HttpAsyncClientExchangeHandler<T> handler);
+ void cancelled(HttpAsyncRequestExecutionHandler<T> handler);
boolean isDone();
@@ -226,4 +226,4 @@ public boolean isOpen() {
}
-}
+}
Oops, something went wrong.

0 comments on commit cd7f931

Please sign in to comment.