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/04/02 22:10:36 UTC
svn commit: r1463728 [1/2] - in /httpcomponents/httpasyncclient/trunk: ./
httpasyncclient/src/main/java/org/apache/http/impl/nio/client/
httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/
httpasyncclient/src/test/java/org/apache/http/ httpasy...
Author: olegk
Date: Tue Apr 2 20:10:35 2013
New Revision: 1463728
URL: http://svn.apache.org/r1463728
Log:
Upgraded HttpCore 4.3-beta1 APIs; ported test cases
Added:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java (contents, props changed)
- copied, changed from r1463727, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultRequestExectionHandlerImpl.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/CPoolUtils.java
- copied, changed from r1463727, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
Removed:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultRequestExectionHandlerImpl.java
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalClientExec.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExec.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolProxy.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ManagedNHttpClientConnectionImpl.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthentication.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthenticationFallBack.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientReauthentication.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsync.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncClientUtils.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPrematureTermination.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpsAsync.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpsRedirects.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestStatefulConnManagement.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestAsyncConsumers.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/methods/TestZeroCopy.java
httpcomponents/httpasyncclient/trunk/pom.xml
Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java (from r1463727, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultRequestExectionHandlerImpl.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultRequestExectionHandlerImpl.java&r1=1463727&r2=1463728&rev=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultRequestExectionHandlerImpl.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java Tue Apr 2 20:10:35 2013
@@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.http.ConnectionClosedException;
-import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
@@ -39,6 +38,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpExecutionAware;
import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.concurrent.BasicFuture;
import org.apache.http.concurrent.Cancellable;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.conn.routing.HttpRoute;
@@ -48,52 +48,45 @@ import org.apache.http.nio.ContentEncode
import org.apache.http.nio.IOControl;
import org.apache.http.nio.NHttpClientConnection;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+import org.apache.http.nio.protocol.HttpAsyncClientExchangeHandler;
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.protocol.ExecutionContext;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.HttpCoreContext;
-class DefaultRequestExectionHandlerImpl<T>
- implements HttpAsyncRequestExecutionHandler<T>, InternalConnManager, Cancellable {
+class DefaultClientExchangeHandlerImpl<T>
+ implements HttpAsyncClientExchangeHandler, InternalConnManager, Cancellable {
private final Log log;
private final HttpAsyncRequestProducer requestProducer;
private final HttpAsyncResponseConsumer<T> responseConsumer;
private final HttpClientContext localContext;
- private final ResultCallback<T> resultCallback;
+ private final BasicFuture<T> resultFuture;
private final NHttpClientConnectionManager connmgr;
- private final HttpProcessor httppocessor;
- private final ConnectionReuseStrategy reuseStrategy;
private final InternalClientExec exec;
private final InternalState state;
private volatile boolean closed;
+ private volatile boolean completed;
private volatile NHttpClientConnection managedConn;
- public DefaultRequestExectionHandlerImpl(
+ public DefaultClientExchangeHandlerImpl(
final Log log,
final HttpAsyncRequestProducer requestProducer,
final HttpAsyncResponseConsumer<T> responseConsumer,
final HttpClientContext localContext,
- final ResultCallback<T> callback,
+ final BasicFuture<T> resultFuture,
final NHttpClientConnectionManager connmgr,
- final HttpProcessor httppocessor,
- final ConnectionReuseStrategy reuseStrategy,
final InternalClientExec exec) {
super();
this.log = log;
this.requestProducer = requestProducer;
this.responseConsumer = responseConsumer;
this.localContext = localContext;
- this.resultCallback = callback;
+ this.resultFuture = resultFuture;
this.connmgr = connmgr;
- this.httppocessor = httppocessor;
- this.reuseStrategy = reuseStrategy;
this.exec = exec;
this.state = new InternalState(requestProducer, responseConsumer, localContext);
}
@@ -127,8 +120,8 @@ class DefaultRequestExectionHandlerImpl<
requestConnection();
}
- public HttpHost getTarget() {
- return this.requestProducer.getTarget();
+ public boolean isDone() {
+ return this.completed;
}
public synchronized HttpRequest generateRequest() throws IOException, HttpException {
@@ -140,18 +133,10 @@ class DefaultRequestExectionHandlerImpl<
this.exec.produceContent(this.state, encoder, ioctrl);
}
- public void requestCompleted(final HttpContext context) {
+ public void requestCompleted() {
this.exec.requestCompleted(this.state);
}
- public boolean isRepeatable() {
- return this.requestProducer.isRepeatable();
- }
-
- public void resetRequest() throws IOException {
- this.requestProducer.resetRequest();
- }
-
public synchronized void responseReceived(
final HttpResponse response) throws IOException, HttpException {
this.exec.responseReceived(this.state, response);
@@ -162,37 +147,44 @@ class DefaultRequestExectionHandlerImpl<
this.exec.consumeContent(this.state, decoder, ioctrl);
}
- public synchronized void responseCompleted(final HttpContext context) {
- if (this.resultCallback.isDone()) {
+ public synchronized void responseCompleted() throws IOException, HttpException {
+ if (this.resultFuture.isDone()) {
+ this.completed = true;
+ releaseConnection();
return;
}
- try {
- this.exec.responseCompleted(this.state, this);
- } catch (final HttpException ex) {
- failed(ex);
- }
+ this.exec.responseCompleted(this.state, this);
+
if (this.state.getFinalResponse() != null) {
releaseConnection();
final T result = this.responseConsumer.getResult();
final Exception ex = this.responseConsumer.getException();
if (ex == null) {
- this.resultCallback.completed(result, this);
+ this.resultFuture.completed(result);
} else {
- this.resultCallback.failed(ex, this);
+ this.resultFuture.failed(ex);
}
+ this.completed = true;
} else {
+ if (this.managedConn != null &&!this.managedConn.isOpen()) {
+ releaseConnection();
+ }
if (this.managedConn != null) {
- if (!this.managedConn.isOpen()) {
- reopenConnection();
- } else {
- this.managedConn.requestOutput();
- }
+ this.managedConn.requestOutput();
} else {
requestConnection();
}
}
}
+ public void inputTerminated() {
+ if (!this.completed) {
+ requestConnection();
+ } else {
+ close();
+ }
+ }
+
public synchronized void releaseConnection() {
if (this.managedConn != null) {
try {
@@ -237,7 +229,7 @@ class DefaultRequestExectionHandlerImpl<
this.responseConsumer.failed(ex);
} finally {
try {
- this.resultCallback.failed(ex, this);
+ this.resultFuture.failed(ex);
} finally {
close();
}
@@ -254,45 +246,21 @@ class DefaultRequestExectionHandlerImpl<
final T result = this.responseConsumer.getResult();
final Exception ex = this.responseConsumer.getException();
if (ex != null) {
- this.resultCallback.failed(ex, this);
+ this.resultFuture.failed(ex);
} else if (result != null) {
- this.resultCallback.completed(result, this);
+ this.resultFuture.completed(result);
} else {
- this.resultCallback.cancelled(this);
+ this.resultFuture.cancel();
}
return cancelled;
} catch (final RuntimeException runex) {
- this.resultCallback.failed(runex, this);
+ this.resultFuture.failed(runex);
throw runex;
} finally {
close();
}
}
- public boolean isDone() {
- return this.resultCallback.isDone();
- }
-
- public T getResult() {
- return this.responseConsumer.getResult();
- }
-
- public Exception getException() {
- return this.responseConsumer.getException();
- }
-
- public HttpContext getContext() {
- return this.localContext;
- }
-
- public HttpProcessor getHttpProcessor() {
- return this.httppocessor;
- }
-
- public ConnectionReuseStrategy getConnectionReuseStrategy() {
- return this.reuseStrategy;
- }
-
private synchronized void connectionAllocated(final NHttpClientConnection managedConn) {
try {
if (this.log.isDebugEnabled()) {
@@ -307,7 +275,7 @@ class DefaultRequestExectionHandlerImpl<
return;
}
- this.localContext.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn);
+ this.localContext.setAttribute(HttpCoreContext.HTTP_CONNECTION, managedConn);
this.state.setRouteEstablished(this.connmgr.isRouteComplete(managedConn));
if (!this.state.isRouteEstablished()) {
this.state.setRouteTracker(new RouteTracker(this.state.getRoute()));
@@ -325,31 +293,12 @@ class DefaultRequestExectionHandlerImpl<
}
}
- private synchronized void connectionReopened(final NHttpClientConnection managedConn) {
- try {
- if (this.log.isDebugEnabled()) {
- this.log.debug("[exchange: " + this.state.getId() + "] Connection re-opened: " + managedConn);
- }
- this.managedConn = managedConn;
- this.state.setValidDuration(0);
- this.state.setNonReusable();
- this.state.setRouteEstablished(false);
- this.state.setRouteTracker(new RouteTracker(this.state.getRoute()));
-
- this.managedConn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this);
- this.managedConn.requestOutput();
- } catch (final RuntimeException runex) {
- failed(runex);
- throw runex;
- }
- }
-
private synchronized void connectionRequestFailed(final Exception ex) {
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + this.state.getId() + "] connection request failed");
}
try {
- this.resultCallback.failed(ex, this);
+ this.resultFuture.failed(ex);
} finally {
close();
}
@@ -360,7 +309,7 @@ class DefaultRequestExectionHandlerImpl<
this.log.debug("[exchange: " + this.state.getId() + "] Connection request cancelled");
}
try {
- this.resultCallback.cancelled(this);
+ this.resultFuture.cancel();
} finally {
close();
}
@@ -395,34 +344,6 @@ class DefaultRequestExectionHandlerImpl<
});
}
- private void reopenConnection() {
- if (this.log.isDebugEnabled()) {
- this.log.debug("[exchange: " + this.state.getId() + "] Re-open connection for " +
- this.state.getRoute());
- }
- final HttpRoute route = this.state.getRoute();
- final RequestConfig config = this.localContext.getRequestConfig();
- this.connmgr.connect(
- this.managedConn,
- route,
- config.getConnectTimeout(),
- new FutureCallback<NHttpClientConnection>() {
-
- public void completed(final NHttpClientConnection managedConn) {
- connectionReopened(managedConn);
- }
-
- public void failed(final Exception ex) {
- connectionRequestFailed(ex);
- }
-
- public void cancelled() {
- connectionRequestCancelled();
- }
-
- });
- }
-
public NHttpClientConnection getConnection() {
return this.managedConn;
}
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultClientExchangeHandlerImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/DefaultResultCallback.java Tue Apr 2 20:10:35 2013
@@ -31,6 +31,7 @@ import java.util.Queue;
import org.apache.http.concurrent.BasicFuture;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+@Deprecated
class DefaultResultCallback<T> implements ResultCallback<T> {
private final BasicFuture<T> future;
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClientBuilder.java Tue Apr 2 20:10:35 2013
@@ -542,6 +542,7 @@ public class HttpAsyncClientBuilder {
final MainClientExec exec = new MainClientExec(
connManager,
+ httpprocessor,
routePlanner,
reuseStrategy,
keepAliveStrategy,
@@ -552,8 +553,6 @@ public class HttpAsyncClientBuilder {
return new InternalHttpAsyncClient(
connManager,
- httpprocessor,
- reuseStrategy,
exec,
cookieSpecRegistry,
authSchemeRegistry,
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalClientExec.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalClientExec.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalClientExec.java Tue Apr 2 20:10:35 2013
@@ -66,6 +66,6 @@ interface InternalClientExec {
void responseCompleted(
InternalState state,
- InternalConnManager connManager) throws HttpException;
+ InternalConnManager connManager) throws IOException, HttpException;
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java Tue Apr 2 20:10:35 2013
@@ -27,13 +27,10 @@
package org.apache.http.impl.nio.client;
import java.io.IOException;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.auth.AuthSchemeProvider;
import org.apache.http.auth.AuthState;
import org.apache.http.client.CookieStore;
@@ -47,7 +44,6 @@ import org.apache.http.config.Lookup;
import org.apache.http.cookie.CookieSpecProvider;
import org.apache.http.nio.conn.ClientAsyncConnectionManager;
import org.apache.http.nio.conn.NHttpClientConnectionManager;
-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;
@@ -55,7 +51,6 @@ import org.apache.http.nio.reactor.IORea
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpProcessor;
@SuppressWarnings("deprecation")
class InternalHttpAsyncClient extends CloseableHttpAsyncClient {
@@ -63,23 +58,18 @@ class InternalHttpAsyncClient extends Cl
private final Log log = LogFactory.getLog(getClass());
private final NHttpClientConnectionManager connmgr;
- private final HttpProcessor httpProcessor;
- private final ConnectionReuseStrategy reuseStrategy;
private final InternalClientExec exec;
private final Lookup<CookieSpecProvider> cookieSpecRegistry;
private final Lookup<AuthSchemeProvider> authSchemeRegistry;
private final CookieStore cookieStore;
private final CredentialsProvider credentialsProvider;
private final RequestConfig defaultConfig;
- private final Queue<HttpAsyncRequestExecutionHandler<?>> queue;
private final Thread reactorThread;
private volatile IOReactorStatus status;
public InternalHttpAsyncClient(
final NHttpClientConnectionManager connmgr,
- final HttpProcessor httpProcessor,
- final ConnectionReuseStrategy reuseStrategy,
final InternalClientExec exec,
final Lookup<CookieSpecProvider> cookieSpecRegistry,
final Lookup<AuthSchemeProvider> authSchemeRegistry,
@@ -88,15 +78,12 @@ class InternalHttpAsyncClient extends Cl
final RequestConfig defaultConfig) {
super();
this.connmgr = connmgr;
- this.httpProcessor = httpProcessor;
- this.reuseStrategy = reuseStrategy;
this.exec = exec;
this.cookieSpecRegistry = cookieSpecRegistry;
this.authSchemeRegistry = authSchemeRegistry;
this.cookieStore = cookieStore;
this.credentialsProvider = credentialsProvider;
this.defaultConfig = defaultConfig;
- this.queue = new ConcurrentLinkedQueue<HttpAsyncRequestExecutionHandler<?>>();
this.reactorThread = new Thread() {
@Override
@@ -116,10 +103,6 @@ class InternalHttpAsyncClient extends Cl
this.log.error("I/O reactor terminated abnormally", ex);
} finally {
this.status = IOReactorStatus.SHUT_DOWN;
- while (!this.queue.isEmpty()) {
- final HttpAsyncRequestExecutionHandler<?> exchangeHandler = this.queue.remove();
- exchangeHandler.cancel();
- }
}
}
@@ -127,6 +110,7 @@ class InternalHttpAsyncClient extends Cl
return this.status;
}
+ @Override
public void start() {
this.status = IOReactorStatus.ACTIVE;
this.reactorThread.start();
@@ -189,22 +173,18 @@ class InternalHttpAsyncClient extends Cl
"I/O reactor status: " + this.status);
}
final BasicFuture<T> future = new BasicFuture<T>(callback);
- final ResultCallback<T> resultCallback = new DefaultResultCallback<T>(future, this.queue);
final HttpClientContext localcontext = HttpClientContext.adapt(
context != null ? context : new BasicHttpContext());
setupContext(localcontext);
- final DefaultRequestExectionHandlerImpl<T> handler = new DefaultRequestExectionHandlerImpl<T>(
+ final DefaultClientExchangeHandlerImpl<T> handler = new DefaultClientExchangeHandlerImpl<T>(
this.log,
requestProducer,
responseConsumer,
localcontext,
- resultCallback,
+ future,
this.connmgr,
- this.httpProcessor,
- this.reuseStrategy,
this.exec);
- this.queue.add(handler);
try {
handler.start();
} catch (final Exception ex) {
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/LoggingAsyncRequestExecutor.java Tue Apr 2 20:10:35 2013
@@ -80,7 +80,7 @@ class LoggingAsyncRequestExecutor extend
@Override
public void inputReady(
final NHttpClientConnection conn,
- final ContentDecoder decoder) throws IOException {
+ final ContentDecoder decoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Input ready");
}
@@ -93,7 +93,7 @@ class LoggingAsyncRequestExecutor extend
@Override
public void outputReady(
final NHttpClientConnection conn,
- final ContentEncoder encoder) throws IOException {
+ final ContentEncoder encoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + " Output ready");
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MainClientExec.java Tue Apr 2 20:10:35 2013
@@ -76,14 +76,17 @@ import org.apache.http.nio.NHttpClientCo
import org.apache.http.nio.conn.NHttpClientConnectionManager;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
-import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpCoreContext;
+import org.apache.http.protocol.HttpProcessor;
class MainClientExec implements InternalClientExec {
private final Log log = LogFactory.getLog(getClass());
private final NHttpClientConnectionManager connmgr;
+ private final HttpProcessor httpProcessor;
private final HttpRoutePlanner routePlanner;
+ private final ConnectionReuseStrategy connReuseStrategy;
private final ConnectionKeepAliveStrategy keepaliveStrategy;
private final AuthenticationStrategy targetAuthStrategy;
private final AuthenticationStrategy proxyAuthStrategy;
@@ -94,8 +97,9 @@ class MainClientExec implements Internal
public MainClientExec(
final NHttpClientConnectionManager connmgr,
+ final HttpProcessor httpProcessor,
final HttpRoutePlanner routePlanner,
- final ConnectionReuseStrategy reuseStrategy,
+ final ConnectionReuseStrategy connReuseStrategy,
final ConnectionKeepAliveStrategy keepaliveStrategy,
final RedirectStrategy redirectStrategy,
final AuthenticationStrategy targetAuthStrategy,
@@ -103,7 +107,9 @@ class MainClientExec implements Internal
final UserTokenHandler userTokenHandler) {
super();
this.connmgr = connmgr;
+ this.httpProcessor = httpProcessor;
this.routePlanner = routePlanner;
+ this.connReuseStrategy = connReuseStrategy;
this.keepaliveStrategy = keepaliveStrategy;
this.redirectStrategy = redirectStrategy;
this.targetAuthStrategy = targetAuthStrategy;
@@ -264,6 +270,10 @@ class MainClientExec implements Internal
if (this.log.isDebugEnabled()) {
this.log.debug("[exchange: " + state.getId() + "] Response received " + response.getStatusLine());
}
+ final HttpClientContext context = state.getLocalContext();
+ context.setAttribute(HttpCoreContext.HTTP_RESPONSE, response);
+ this.httpProcessor.process(response, context);
+
state.setCurrentResponse(response);
if (!state.isRouteEstablished()) {
@@ -311,11 +321,11 @@ class MainClientExec implements Internal
public void responseCompleted(
final InternalState state,
- final InternalConnManager connManager) throws HttpException {
+ final InternalConnManager connManager) throws IOException, HttpException {
final HttpClientContext localContext = state.getLocalContext();
final HttpResponse currentResponse = state.getCurrentResponse();
- if (connManager.getConnection().isOpen()) {
+ if (this.connReuseStrategy.keepAlive(currentResponse, localContext)) {
final long validDuration = this.keepaliveStrategy.getKeepAliveDuration(
currentResponse, localContext);
if (this.log.isDebugEnabled()) {
@@ -334,6 +344,7 @@ class MainClientExec implements Internal
this.log.debug("[exchange: " + state.getId() + "] Connection cannot be kept alive");
}
state.setNonReusable();
+ connManager.releaseConnection();
final AuthState proxyAuthState = localContext.getProxyAuthState();
if (proxyAuthState.getState() == AuthProtocolState.SUCCESS
&& proxyAuthState.getAuthScheme() != null
@@ -444,7 +455,7 @@ class MainClientExec implements Internal
}
}
- private void prepareRequest(final InternalState state) throws HttpException {
+ private void prepareRequest(final InternalState state) throws IOException, HttpException {
final HttpClientContext localContext = state.getLocalContext();
final HttpRequestWrapper currentRequest = state.getCurrentRequest();
final HttpRoute route = state.getRoute();
@@ -483,8 +494,10 @@ class MainClientExec implements Internal
// Re-write request URI if needed
rewriteRequestURI(state);
- localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target);
+ localContext.setAttribute(HttpCoreContext.HTTP_REQUEST, currentRequest);
+ localContext.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, target);
localContext.setAttribute(ClientContext.ROUTE, route);
+ this.httpProcessor.process(currentRequest, localContext);
}
private HttpRequest createConnectRequest(final HttpRoute route) {
@@ -525,33 +538,12 @@ class MainClientExec implements Internal
final HttpClientContext localContext = state.getLocalContext();
final RequestConfig config = localContext.getRequestConfig();
if (config.isAuthenticationEnabled()) {
- final CredentialsProvider credsProvider = localContext.getCredentialsProvider();
- if (credsProvider != null) {
- final HttpRoute route = state.getRoute();
- final HttpResponse currentResponse = state.getCurrentResponse();
- HttpHost target = localContext.getTargetHost();
- if (target == null) {
- target = route.getTargetHost();
- }
- if (target.getPort() < 0) {
- target = new HttpHost(
- target.getHostName(),
- route.getTargetHost().getPort(),
- target.getSchemeName());
- }
- final AuthState targetAuthState = localContext.getTargetAuthState();
- if (this.authenticator.isAuthenticationRequested(target, currentResponse,
- this.targetAuthStrategy, targetAuthState, localContext)) {
- return this.authenticator.handleAuthChallenge(target, currentResponse,
- this.targetAuthStrategy, targetAuthState, localContext);
- }
- final HttpHost proxy = route.getProxyHost();
- final AuthState proxyAuthState = localContext.getProxyAuthState();
- if (this.authenticator.isAuthenticationRequested(proxy, currentResponse,
- this.proxyAuthStrategy, proxyAuthState, localContext)) {
- return this.authenticator.handleAuthChallenge(proxy, currentResponse,
- this.proxyAuthStrategy, proxyAuthState, localContext);
- }
+ if (needAuthentication(state)) {
+ // discard previous auth headers
+ final HttpRequest currentRequest = state.getCurrentRequest();
+ currentRequest.removeHeaders(AUTH.WWW_AUTH_RESP);
+ currentRequest.removeHeaders(AUTH.PROXY_AUTH_RESP);
+ return true;
}
}
if (config.isRedirectsEnabled()) {
@@ -572,4 +564,37 @@ class MainClientExec implements Internal
return false;
}
+ private boolean needAuthentication(final InternalState state) throws HttpException {
+ final HttpClientContext localContext = state.getLocalContext();
+ final CredentialsProvider credsProvider = localContext.getCredentialsProvider();
+ if (credsProvider != null) {
+ final HttpRoute route = state.getRoute();
+ final HttpResponse currentResponse = state.getCurrentResponse();
+ HttpHost target = localContext.getTargetHost();
+ if (target == null) {
+ target = route.getTargetHost();
+ }
+ if (target.getPort() < 0) {
+ target = new HttpHost(
+ target.getHostName(),
+ route.getTargetHost().getPort(),
+ target.getSchemeName());
+ }
+ final AuthState targetAuthState = localContext.getTargetAuthState();
+ if (this.authenticator.isAuthenticationRequested(target, currentResponse,
+ this.targetAuthStrategy, targetAuthState, localContext)) {
+ return this.authenticator.handleAuthChallenge(target, currentResponse,
+ this.targetAuthStrategy, targetAuthState, localContext);
+ }
+ final HttpHost proxy = route.getProxyHost();
+ final AuthState proxyAuthState = localContext.getProxyAuthState();
+ if (this.authenticator.isAuthenticationRequested(proxy, currentResponse,
+ this.proxyAuthStrategy, proxyAuthState, localContext)) {
+ return this.authenticator.handleAuthChallenge(proxy, currentResponse,
+ this.proxyAuthStrategy, proxyAuthState, localContext);
+ }
+ }
+ return false;
+ }
+
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExec.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExec.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExec.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalClientExec.java Tue Apr 2 20:10:35 2013
@@ -56,7 +56,7 @@ import org.apache.http.nio.NHttpClientCo
import org.apache.http.nio.conn.NHttpClientConnectionManager;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.nio.protocol.HttpAsyncResponseConsumer;
-import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpCoreContext;
class MinimalClientExec implements InternalClientExec {
@@ -115,7 +115,7 @@ class MinimalClientExec implements Inter
host = target;
}
- localContext.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
+ localContext.setAttribute(HttpCoreContext.HTTP_TARGET_HOST, host);
localContext.setAttribute(ClientContext.ROUTE, route);
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java Tue Apr 2 20:10:35 2013
@@ -28,6 +28,7 @@ package org.apache.http.impl.nio.client;
import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
+@Deprecated
interface ResultCallback<T> {
void completed(T result, HttpAsyncRequestExecutionHandler<T> handler);
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPool.java Tue Apr 2 20:10:35 2013
@@ -26,18 +26,16 @@
*/
package org.apache.http.impl.nio.conn;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.http.HttpHost;
import org.apache.http.annotation.ThreadSafe;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.nio.conn.ManagedNHttpClientConnection;
import org.apache.http.nio.pool.AbstractNIOConnPool;
import org.apache.http.nio.pool.NIOConnFactory;
+import org.apache.http.nio.pool.SocketAddressResolver;
import org.apache.http.nio.reactor.ConnectingIOReactor;
@ThreadSafe
@@ -51,9 +49,10 @@ class CPool extends AbstractNIOConnPool<
public CPool(
final ConnectingIOReactor ioreactor,
final NIOConnFactory<HttpRoute, ManagedNHttpClientConnection> connFactory,
+ final SocketAddressResolver<HttpRoute> addressResolver,
final int defaultMaxPerRoute, final int maxTotal,
final long timeToLive, final TimeUnit tunit) {
- super(ioreactor, connFactory, defaultMaxPerRoute, maxTotal);
+ super(ioreactor, connFactory, addressResolver, defaultMaxPerRoute, maxTotal);
this.timeToLive = timeToLive;
this.tunit = tunit;
}
@@ -63,20 +62,4 @@ class CPool extends AbstractNIOConnPool<
return new CPoolEntry(this.log, conn.getId(), route, conn, this.timeToLive, this.tunit);
}
- @Override
- protected SocketAddress resolveLocalAddress(final HttpRoute route) {
- return new InetSocketAddress(route.getLocalAddress(), 0);
- }
-
- @Override
- protected SocketAddress resolveRemoteAddress(final HttpRoute route) {
- HttpHost firsthop = route.getProxyHost();
- if (firsthop == null) {
- firsthop = route.getTargetHost();
- }
- final String hostname = firsthop.getHostName();
- final int port = firsthop.getPort();
- return new InetSocketAddress(hostname, port);
- }
-
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolProxy.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolProxy.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/CPoolProxy.java Tue Apr 2 20:10:35 2013
@@ -45,6 +45,7 @@ class CPoolProxy implements InvocationHa
private static final Method SHUTDOWN_METHOD;
private static final Method IS_OPEN_METHOD;
private static final Method IS_STALE_METHOD;
+ private static final Method TO_STRING;
static {
try {
@@ -52,6 +53,7 @@ class CPoolProxy implements InvocationHa
SHUTDOWN_METHOD = HttpConnection.class.getMethod("shutdown");
IS_OPEN_METHOD = HttpConnection.class.getMethod("isOpen");
IS_STALE_METHOD = HttpConnection.class.getMethod("isStale");
+ TO_STRING = Object.class.getMethod("toString");
} catch (final NoSuchMethodException ex) {
throw new Error(ex);
}
@@ -126,6 +128,8 @@ class CPoolProxy implements InvocationHa
return Boolean.valueOf(isOpen());
} else if (method.equals(IS_STALE_METHOD)) {
return Boolean.valueOf(isStale());
+ } else if (method.equals(TO_STRING)) {
+ return "Managed connection";
} else {
final NHttpClientConnection conn = getConnection();
if (conn == null) {
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ManagedNHttpClientConnectionImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ManagedNHttpClientConnectionImpl.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ManagedNHttpClientConnectionImpl.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/ManagedNHttpClientConnectionImpl.java Tue Apr 2 20:10:35 2013
@@ -72,7 +72,7 @@ class ManagedNHttpClientConnectionImpl
final ContentLengthStrategy outgoingContentStrategy,
final NHttpMessageWriterFactory<HttpRequest> requestWriterFactory,
final NHttpMessageParserFactory<HttpResponse> responseParserFactory) {
- super(iosession, buffersize, allocator, chardecoder, charencoder, constraints,
+ super(iosession, buffersize, buffersize, allocator, chardecoder, charencoder, constraints,
incomingContentStrategy, outgoingContentStrategy,
requestWriterFactory, responseParserFactory);
this.id = id;
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java Tue Apr 2 20:10:35 2013
@@ -29,6 +29,7 @@ package org.apache.http.impl.nio.conn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.SocketAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -57,6 +58,7 @@ import org.apache.http.nio.conn.NHttpCon
import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
import org.apache.http.nio.conn.ssl.SchemeLayeringStrategy;
import org.apache.http.nio.pool.NIOConnFactory;
+import org.apache.http.nio.pool.SocketAddressResolver;
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOEventDispatch;
import org.apache.http.nio.reactor.IOSession;
@@ -139,6 +141,7 @@ public class PoolingNHttpClientConnectio
this.configData = new ConfigData();
this.pool = new CPool(ioreactor,
new InternalConnectionFactory(this.configData, connFactory),
+ new InternalAddressResolver(schemePortResolver, dnsResolver),
2, 20, timeToLive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
this.layeringStrategyRegistry = layeringStrategyRegistry;
this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
@@ -588,4 +591,40 @@ public class PoolingNHttpClientConnectio
}
+ static class InternalAddressResolver implements SocketAddressResolver<HttpRoute> {
+
+ private final SchemePortResolver schemePortResolver;
+ private final DnsResolver dnsResolver;
+
+ public InternalAddressResolver(
+ final SchemePortResolver schemePortResolver,
+ final DnsResolver dnsResolver) {
+ super();
+ this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
+ DefaultSchemePortResolver.INSTANCE;
+ this.dnsResolver = dnsResolver != null ? dnsResolver :
+ SystemDefaultDnsResolver.INSTANCE;
+ }
+
+ public SocketAddress resolveLocalAddress(final HttpRoute route) throws IOException {
+ return route.getLocalAddress() != null ? new InetSocketAddress(route.getLocalAddress(), 0) : null;
+ }
+
+ public SocketAddress resolveRemoteAddress(final HttpRoute route) throws IOException {
+ final HttpHost host;
+ if (route.getProxyHost() != null) {
+ host = route.getProxyHost();
+ } else {
+ host = route.getTargetHost();
+ }
+ final int port = this.schemePortResolver.resolve(host);
+ try {
+ final InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
+ return new InetSocketAddress(addresses[0], port);
+ } catch (final UnknownHostException ex) {
+ return new InetSocketAddress(host.getHostName(), port);
+ }
+ }
+
+ }
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/HttpAsyncTestBase.java Tue Apr 2 20:10:35 2013
@@ -29,19 +29,15 @@ package org.apache.http;
import java.io.IOException;
+import org.apache.http.config.ConnectionConfig;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
-import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
-import org.apache.http.impl.nio.conn.PoolingClientAsyncConnectionManager;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.localserver.HttpServerNio;
import org.apache.http.nio.NHttpConnectionFactory;
-import org.apache.http.nio.conn.scheme.AsyncScheme;
-import org.apache.http.nio.conn.scheme.AsyncSchemeRegistry;
import org.apache.http.nio.reactor.IOReactorExceptionHandler;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
-import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.ResponseConnControl;
@@ -52,15 +48,18 @@ import org.junit.After;
public abstract class HttpAsyncTestBase {
- protected HttpParams serverParams;
protected HttpServerNio server;
+ protected IOReactorConfig serverReactorConfig;
+ protected ConnectionConfig serverConnectionConfig;
protected HttpProcessor serverHttpProc;
- protected DefaultConnectingIOReactor ioreactor;
- protected PoolingClientAsyncConnectionManager connMgr;
- protected DefaultHttpAsyncClient httpclient;
+ protected DefaultConnectingIOReactor clientIOReactor;
+ protected IOReactorConfig clientReactorConfig;
+ protected ConnectionConfig clientrConnectionConfig;
+ protected PoolingNHttpClientConnectionManager connMgr;
+ protected CloseableHttpAsyncClient httpclient;
protected abstract NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
- HttpParams params) throws Exception;
+ ConnectionConfig config) throws Exception;
protected abstract String getSchemeName();
@@ -79,42 +78,26 @@ public abstract class HttpAsyncTestBase
}
public void initServer() throws Exception {
- this.serverParams = new SyncBasicHttpParams();
- this.serverParams
- .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
- .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
- .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
- .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
- .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1");
- this.server = new HttpServerNio(createServerConnectionFactory(this.serverParams));
+ this.server = new HttpServerNio(
+ this.serverReactorConfig, createServerConnectionFactory(this.serverConnectionConfig));
this.server.setExceptionHandler(new SimpleIOReactorExceptionHandler());
this.serverHttpProc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
- new ResponseServer(),
+ new ResponseServer("TEST-SERVER/1.1"),
new ResponseContent(),
new ResponseConnControl()
});
}
- public void initClient() throws Exception {
- this.ioreactor = new DefaultConnectingIOReactor();
- final AsyncSchemeRegistry schemeRegistry = new AsyncSchemeRegistry();
- schemeRegistry.register(new AsyncScheme("http", 80, null));
- this.connMgr = new PoolingClientAsyncConnectionManager(this.ioreactor, schemeRegistry);
- this.httpclient = new DefaultHttpAsyncClient(this.connMgr);
- this.httpclient.getParams()
- .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
- .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 60000)
- .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
- .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
- .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
- .setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1");
- }
+ public void initConnectionManager() throws Exception {
+ this.clientIOReactor = new DefaultConnectingIOReactor(this.clientReactorConfig);
+ this.connMgr = new PoolingNHttpClientConnectionManager(this.clientIOReactor);
+ }
@After
public void shutDownClient() throws Exception {
if (this.httpclient != null) {
- this.httpclient.shutdown();
+ this.httpclient.close();
}
}
Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/CPoolUtils.java (from r1463727, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/CPoolUtils.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/CPoolUtils.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java&r1=1463727&r2=1463728&rev=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/ResultCallback.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/CPoolUtils.java Tue Apr 2 20:10:35 2013
@@ -24,18 +24,17 @@
* <http://www.apache.org/>.
*
*/
-package org.apache.http.impl.nio.client;
+package org.apache.http.impl.nio.conn;
-import org.apache.http.nio.protocol.HttpAsyncRequestExecutionHandler;
-
-interface ResultCallback<T> {
-
- void completed(T result, HttpAsyncRequestExecutionHandler<T> handler);
-
- void failed(Exception ex, HttpAsyncRequestExecutionHandler<T> handler);
-
- void cancelled(HttpAsyncRequestExecutionHandler<T> handler);
-
- boolean isDone();
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.nio.NHttpClientConnection;
+import org.apache.http.nio.conn.ManagedNHttpClientConnection;
+import org.apache.http.pool.PoolEntry;
+
+public class CPoolUtils {
+
+ public static PoolEntry<HttpRoute, ManagedNHttpClientConnection> getPoolEntry(final NHttpClientConnection managedConn) {
+ return CPoolProxy.getPoolEntry(managedConn);
+ }
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java Tue Apr 2 20:10:35 2013
@@ -50,6 +50,7 @@ import org.apache.http.conn.DnsResolver;
import org.apache.http.conn.SchemePortResolver;
import org.apache.http.conn.routing.HttpRoute;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.ConfigData;
+import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.InternalAddressResolver;
import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.InternalConnectionFactory;
import org.apache.http.nio.NHttpClientConnection;
import org.apache.http.nio.conn.ManagedNHttpClientConnection;
@@ -646,4 +647,70 @@ public class TestPoolingHttpClientAsyncC
Mockito.verify(connFactory).create(iosession, ConnectionConfig.DEFAULT);
}
+ @Test
+ public void testResolveLocalAddress() throws Exception {
+ final InternalAddressResolver addressResolver = new InternalAddressResolver(
+ schemePortResolver, dnsResolver);
+
+ final HttpHost target = new HttpHost("localhost");
+ final byte[] ip = new byte[] {10, 0, 0, 10};
+ final HttpRoute route = new HttpRoute(target, InetAddress.getByAddress(ip), false);
+ final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveLocalAddress(route);
+
+ Assert.assertNotNull(address);
+ Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
+ Assert.assertEquals(0, address.getPort());
+ }
+
+ @Test
+ public void testResolveLocalAddressNull() throws Exception {
+ final InternalAddressResolver addressResolver = new InternalAddressResolver(
+ schemePortResolver, dnsResolver);
+
+ final HttpHost target = new HttpHost("localhost");
+ final HttpRoute route = new HttpRoute(target);
+ final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveLocalAddress(route);
+
+ Assert.assertNull(address);
+ }
+
+ @Test
+ public void testResolveRemoteAddress() throws Exception {
+ final InternalAddressResolver addressResolver = new InternalAddressResolver(
+ schemePortResolver, dnsResolver);
+
+ final HttpHost target = new HttpHost("somehost");
+ final HttpRoute route = new HttpRoute(target);
+
+ final byte[] ip = new byte[] {10, 0, 0, 10};
+ Mockito.when(schemePortResolver.resolve(target)).thenReturn(123);
+ Mockito.when(dnsResolver.resolve("somehost")).thenReturn(new InetAddress[] {InetAddress.getByAddress(ip)});
+
+ final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveRemoteAddress(route);
+
+ Assert.assertNotNull(address);
+ Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
+ Assert.assertEquals(123, address.getPort());
+ }
+
+ @Test
+ public void testResolveRemoteAddressViaProxy() throws Exception {
+ final InternalAddressResolver addressResolver = new InternalAddressResolver(
+ schemePortResolver, dnsResolver);
+
+ final HttpHost target = new HttpHost("somehost");
+ final HttpHost proxy = new HttpHost("someproxy");
+ final HttpRoute route = new HttpRoute(target, null, proxy, false);
+
+ final byte[] ip = new byte[] {10, 0, 0, 10};
+ Mockito.when(schemePortResolver.resolve(proxy)).thenReturn(8888);
+ Mockito.when(dnsResolver.resolve("someproxy")).thenReturn(new InetAddress[] {InetAddress.getByAddress(ip)});
+
+ final InetSocketAddress address = (InetSocketAddress) addressResolver.resolveRemoteAddress(route);
+
+ Assert.assertNotNull(address);
+ Assert.assertEquals(InetAddress.getByAddress(ip), address.getAddress());
+ Assert.assertEquals(8888, address.getPort());
+ }
+
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/localserver/HttpServerNio.java Tue Apr 2 20:10:35 2013
@@ -35,6 +35,7 @@ import org.apache.http.impl.nio.DefaultH
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.reactor.DefaultListeningIOReactor;
import org.apache.http.impl.nio.reactor.ExceptionEvent;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.NHttpServerEventHandler;
import org.apache.http.nio.reactor.IOEventDispatch;
@@ -52,9 +53,10 @@ public class HttpServerNio {
private ListenerEndpoint endpoint;
public HttpServerNio(
+ final IOReactorConfig ioReactorConfig,
final NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory) throws IOException {
super();
- this.ioReactor = new DefaultListeningIOReactor();
+ this.ioReactor = new DefaultListeningIOReactor(ioReactorConfig);
this.connFactory = connFactory;
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthentication.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthentication.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthentication.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthentication.java Tue Apr 2 20:10:35 2013
@@ -47,39 +47,35 @@ import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
+import org.apache.http.config.ConnectionConfig;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.TargetAuthenticationStrategy;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.localserver.BasicAuthTokenExtractor;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.localserver.ResponseBasicUnauthorized;
import org.apache.http.message.BasicHttpResponse;
-import org.apache.http.nio.NHttpConnection;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.entity.NByteArrayEntity;
import org.apache.http.nio.entity.NStringEntity;
-import org.apache.http.nio.protocol.BasicAsyncRequestConsumer;
import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.BasicAsyncResponseProducer;
import org.apache.http.nio.protocol.HttpAsyncExchange;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
-import org.apache.http.nio.protocol.HttpAsyncRequestConsumer;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandler;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
import org.apache.http.nio.protocol.HttpAsyncService;
+import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
-import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
@@ -99,7 +95,7 @@ public class TestClientAuthentication ex
@Before
public void setUp() throws Exception {
initServer();
- initClient();
+ initConnectionManager();
}
@After
@@ -127,8 +123,8 @@ public class TestClientAuthentication ex
@Override
protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
- final HttpParams params) throws Exception {
- return new DefaultNHttpServerConnectionFactory(params);
+ final ConnectionConfig config) throws Exception {
+ return new DefaultNHttpServerConnectionFactory(config);
}
@Override
@@ -137,15 +133,14 @@ public class TestClientAuthentication ex
}
private HttpHost start(
- final HttpAsyncRequestHandlerResolver requestHandlerResolver,
+ final HttpAsyncRequestHandlerMapper requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
final HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
requestHandlerResolver,
- expectationVerifier,
- this.serverParams);
+ expectationVerifier);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -178,7 +173,6 @@ public class TestClientAuthentication ex
final String creds = (String) context.getAttribute("creds");
if (creds == null || !creds.equals("test:test")) {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
- response.setEntity(new NStringEntity("Unauthorized"));
} else {
response.setStatusCode(HttpStatus.SC_OK);
final NStringEntity entity = new NStringEntity("success", Consts.ASCII);
@@ -278,12 +272,16 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationNoCreds() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(null);
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpGet httpget = new HttpGet("/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
@@ -297,13 +295,17 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationFailure() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "all-wrong"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpGet httpget = new HttpGet("/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
@@ -317,13 +319,17 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationSuccess() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpGet httpget = new HttpGet("/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
@@ -337,13 +343,17 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationSuccessNonPersistentConnection() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler(false)));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpGet httpget = new HttpGet("/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
@@ -355,78 +365,21 @@ public class TestClientAuthentication ex
Assert.assertEquals("test realm", authscope.getRealm());
}
- public class FaultyRequestHandler implements HttpAsyncRequestHandler<HttpRequest> {
-
- private final HttpRequestHandler handler;
-
- public FaultyRequestHandler(final HttpRequestHandler handler) {
- super();
- if (handler == null) {
- throw new IllegalArgumentException("Request handler may not be null");
- }
- this.handler = handler;
- }
-
- public HttpAsyncRequestConsumer<HttpRequest> processRequest(final HttpRequest request,
- final HttpContext context) {
- return new BasicAsyncRequestConsumer();
- }
-
- public void handle(
- final HttpRequest request,
- final HttpAsyncExchange httpexchange,
- final HttpContext context) throws HttpException, IOException {
- HttpResponse response = httpexchange.getResponse();
- this.handler.handle(request, httpexchange.getResponse(), context);
- httpexchange.submitResponse(new BasicAsyncResponseProducer(response) {
-
- @Override
- public void responseCompleted(final HttpContext context) {
- super.responseCompleted(context);
- NHttpConnection conn = (NHttpConnection)context.getAttribute(
- ExecutionContext.HTTP_CONNECTION);
- try {
- conn.shutdown();
- } catch (IOException e) {
- }
- }
-
- });
- }
-
- }
-
- @Test
- public void testBasicAuthenticationFaultyPersistentConnection() throws Exception {
- HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
- registry.register("*", new FaultyRequestHandler(new AuthHandler(true)));
- HttpHost target = start(registry, null);
-
- TestCredentialsProvider credsProvider = new TestCredentialsProvider(
- new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
-
- HttpGet httpget = new HttpGet("/");
- Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
- HttpResponse response = future.get();
- Assert.assertNotNull(response);
- Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
- AuthScope authscope = credsProvider.getAuthScope();
- Assert.assertNotNull(authscope);
- Assert.assertEquals("test realm", authscope.getRealm());
- }
-
@Test
public void testBasicAuthenticationSuccessWithNonRepeatableExpectContinue() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
final AuthExpectationVerifier expectationVerifier = new AuthExpectationVerifier();
- final HttpHost target = start(registry, expectationVerifier);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, expectationVerifier);
final HttpPut httpput = new HttpPut("/");
@@ -440,7 +393,7 @@ public class TestClientAuthentication ex
};
httpput.setEntity(entity);
- httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
+ httpput.setConfig(RequestConfig.custom().setExpectContinueEnabled(true).build());
final Future<HttpResponse> future = this.httpclient.execute(target, httpput, null);
final HttpResponse response = future.get();
@@ -450,14 +403,18 @@ public class TestClientAuthentication ex
@Test(expected=ExecutionException.class)
public void testBasicAuthenticationFailureWithNonRepeatableEntityExpectContinueOff() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpPut httpput = new HttpPut("/");
@@ -471,7 +428,7 @@ public class TestClientAuthentication ex
};
httpput.setEntity(requestEntity);
- httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
+ httpput.setConfig(RequestConfig.custom().setExpectContinueEnabled(false).build());
try {
final Future<HttpResponse> future = this.httpclient.execute(target, httpput, null);
@@ -486,14 +443,18 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationSuccessOnRepeatablePost() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
- this.httpclient.setCredentialsProvider(credsProvider);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpPost httppost = new HttpPost("/");
httppost.setEntity(new NStringEntity("some important stuff", Consts.ISO_8859_1));
@@ -509,9 +470,8 @@ public class TestClientAuthentication ex
@Test
public void testBasicAuthenticationCredentialsCaching() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
@@ -519,8 +479,13 @@ public class TestClientAuthentication ex
final TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();
- this.httpclient.setCredentialsProvider(credsProvider);
- this.httpclient.setTargetAuthenticationStrategy(authStrategy);
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setTargetAuthenticationStrategy(authStrategy)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
+
+ final HttpHost target = start(registry, null);
final HttpContext context = new BasicHttpContext();
@@ -541,9 +506,15 @@ public class TestClientAuthentication ex
@Test
public void testAuthenticationUserinfoInRequestSuccess() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
+
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .build();
+
final HttpHost target = start(registry, null);
+
final HttpGet httpget = new HttpGet("http://test:test@" + target.toHostString() + "/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
final HttpResponse response = future.get();
@@ -556,9 +527,15 @@ public class TestClientAuthentication ex
@Test
public void testAuthenticationUserinfoInRequestFailure() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
+
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .build();
+
final HttpHost target = start(registry, null);
+
final HttpGet httpget = new HttpGet("http://test:all-wrong@" + target.toHostString() + "/");
final Future<HttpResponse> future = this.httpclient.execute(target, httpget, null);
@@ -570,4 +547,4 @@ public class TestClientAuthentication ex
EntityUtils.consume(entity);
}
-}
+}
\ No newline at end of file
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthenticationFallBack.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthenticationFallBack.java?rev=1463728&r1=1463727&r2=1463728&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthenticationFallBack.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestClientAuthenticationFallBack.java Tue Apr 2 20:10:35 2013
@@ -46,21 +46,22 @@ import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.config.ConnectionConfig;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.impl.nio.DefaultNHttpServerConnectionFactory;
+import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.localserver.RequestBasicAuth;
import org.apache.http.nio.NHttpConnectionFactory;
import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerRegistry;
-import org.apache.http.nio.protocol.HttpAsyncRequestHandlerResolver;
+import org.apache.http.nio.protocol.HttpAsyncRequestHandlerMapper;
import org.apache.http.nio.protocol.HttpAsyncService;
+import org.apache.http.nio.protocol.UriHttpAsyncRequestHandlerMapper;
import org.apache.http.nio.reactor.IOReactorStatus;
import org.apache.http.nio.reactor.ListenerEndpoint;
-import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.ImmutableHttpProcessor;
@@ -79,7 +80,7 @@ public class TestClientAuthenticationFal
@Before
public void setUp() throws Exception {
initServer();
- initClient();
+ initConnectionManager();
}
@After
@@ -107,8 +108,8 @@ public class TestClientAuthenticationFal
@Override
protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
- final HttpParams params) throws Exception {
- return new DefaultNHttpServerConnectionFactory(params);
+ final ConnectionConfig config) throws Exception {
+ return new DefaultNHttpServerConnectionFactory(config);
}
@Override
@@ -117,15 +118,14 @@ public class TestClientAuthenticationFal
}
private HttpHost start(
- final HttpAsyncRequestHandlerResolver requestHandlerResolver,
+ final HttpAsyncRequestHandlerMapper requestHandlerResolver,
final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
final HttpAsyncService serviceHandler = new HttpAsyncService(
this.serverHttpProc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
requestHandlerResolver,
- expectationVerifier,
- this.serverParams);
+ expectationVerifier);
this.server.start(serviceHandler);
this.httpclient.start();
@@ -198,15 +198,18 @@ public class TestClientAuthenticationFal
@Test
public void testBasicAuthenticationSuccess() throws Exception {
- final HttpAsyncRequestHandlerRegistry registry = new HttpAsyncRequestHandlerRegistry();
+ final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
registry.register("*", new BasicAsyncRequestHandler(new AuthHandler()));
- final HttpHost target = start(registry, null);
final TestCredentialsProvider credsProvider = new TestCredentialsProvider(
new UsernamePasswordCredentials("test", "test"));
+ this.httpclient = HttpAsyncClients.custom()
+ .setConnectionManager(this.connMgr)
+ .setDefaultCredentialsProvider(credsProvider)
+ .build();
- this.httpclient.setCredentialsProvider(credsProvider);
+ final HttpHost target = start(registry, null);
final HttpGet httpget = new HttpGet("/");