hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1478320 - in /httpcomponents/httpasyncclient/trunk/httpasyncclient/src: main/java/org/apache/http/impl/nio/client/ test/java/org/apache/http/nio/client/integration/
Date Thu, 02 May 2013 10:35:06 GMT
Author: olegk
Date: Thu May  2 10:35:06 2013
New Revision: 1478320

URL: http://svn.apache.org/r1478320
Log:
Minimal HttpAsyncClient implementation

Added:
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/IOReactorUtils.java
      - copied, changed from r1466814, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
      - copied, changed from r1466814, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java
    httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
  (with props)
Modified:
    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/HttpAsyncClients.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/MinimalClientExec.java

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=1478320&r1=1478319&r2=1478320&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
Thu May  2 10:35:06 2013
@@ -89,13 +89,11 @@ import org.apache.http.impl.cookie.Netsc
 import org.apache.http.impl.cookie.RFC2109SpecFactory;
 import org.apache.http.impl.cookie.RFC2965SpecFactory;
 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.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.conn.ssl.SSLLayeringStrategy;
 import org.apache.http.nio.conn.ssl.SchemeLayeringStrategy;
 import org.apache.http.nio.reactor.ConnectingIOReactor;
-import org.apache.http.nio.reactor.IOReactorException;
 import org.apache.http.protocol.HttpProcessor;
 import org.apache.http.protocol.HttpProcessorBuilder;
 import org.apache.http.protocol.RequestContent;
@@ -336,14 +334,6 @@ public class HttpAsyncClientBuilder {
         return this;
     }
 
-    private ConnectingIOReactor createIOReactor(final IOReactorConfig config) {
-        try {
-            return new DefaultConnectingIOReactor(config);
-        } catch (final IOReactorException ex) {
-            throw new IllegalStateException(ex);
-        }
-    }
-
     public CloseableHttpAsyncClient build() {
         NHttpClientConnectionManager connManager = this.connManager;
         if (connManager == null) {
@@ -359,7 +349,7 @@ public class HttpAsyncClientBuilder {
                 }
                 sslLayeringStrategy = new SSLLayeringStrategy(sslcontext);
             }
-            final ConnectingIOReactor ioreactor = createIOReactor(
+            final ConnectingIOReactor ioreactor = IOReactorUtils.create(
                 defaultIOReactorConfig != null ? defaultIOReactorConfig : IOReactorConfig.DEFAULT);
             final PoolingNHttpClientConnectionManager poolingmgr = new PoolingNHttpClientConnectionManager(
                     ioreactor,

Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java?rev=1478320&r1=1478319&r2=1478320&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java
Thu May  2 10:35:06 2013
@@ -28,6 +28,10 @@
 package org.apache.http.impl.nio.client;
 
 import org.apache.http.annotation.Immutable;
+import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.conn.NHttpClientConnectionManager;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
 
 @Immutable
 public class HttpAsyncClients {
@@ -48,4 +52,18 @@ public class HttpAsyncClients {
         return HttpAsyncClientBuilder.create().useSystemProperties().build();
     }
 
+    public static CloseableHttpAsyncClient createMinimal() {
+        return new MinimalHttpAsyncClient(
+                new PoolingNHttpClientConnectionManager(IOReactorUtils.create(IOReactorConfig.DEFAULT)));
+    }
+
+    public static CloseableHttpAsyncClient createMinimal(final ConnectingIOReactor ioreactor)
{
+        return new MinimalHttpAsyncClient(
+                new PoolingNHttpClientConnectionManager(ioreactor));
+    }
+
+    public static CloseableHttpAsyncClient createMinimal(final NHttpClientConnectionManager
connManager) {
+        return new MinimalHttpAsyncClient(connManager);
+    }
+
 }

Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/IOReactorUtils.java
(from r1466814, httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/IOReactorUtils.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/IOReactorUtils.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java&r1=1466814&r2=1478320&rev=1478320&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/HttpAsyncClients.java
(original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/IOReactorUtils.java
Thu May  2 10:35:06 2013
@@ -24,28 +24,24 @@
  * <http://www.apache.org/>.
  *
  */
-
 package org.apache.http.impl.nio.client;
 
-import org.apache.http.annotation.Immutable;
-
-@Immutable
-public class HttpAsyncClients {
+import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
+import org.apache.http.impl.nio.reactor.IOReactorConfig;
+import org.apache.http.nio.reactor.ConnectingIOReactor;
+import org.apache.http.nio.reactor.IOReactorException;
 
-    private HttpAsyncClients() {
-        super();
-    }
-
-    public static HttpAsyncClientBuilder custom() {
-        return HttpAsyncClientBuilder.create();
-    }
+final class IOReactorUtils {
 
-    public static CloseableHttpAsyncClient createDefault() {
-        return HttpAsyncClientBuilder.create().build();
+    private IOReactorUtils() {
     }
 
-    public static CloseableHttpAsyncClient createSystem() {
-        return HttpAsyncClientBuilder.create().useSystemProperties().build();
+    public static ConnectingIOReactor create(final IOReactorConfig config) {
+        try {
+            return new DefaultConnectingIOReactor(config);
+        } catch (final IOReactorException ex) {
+            throw new IllegalStateException(ex);
+        }
     }
 
 }

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=1478320&r1=1478319&r2=1478320&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
Thu May  2 10:35:06 2013
@@ -36,7 +36,6 @@ import org.apache.http.auth.AuthState;
 import org.apache.http.client.CookieStore;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.concurrent.FutureCallback;
@@ -140,26 +139,26 @@ class InternalHttpAsyncClient extends Cl
     }
 
     private void setupContext(final HttpClientContext context) {
-        if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
-            context.setAttribute(ClientContext.TARGET_AUTH_STATE, new AuthState());
+        if (context.getAttribute(HttpClientContext.TARGET_AUTH_STATE) == null) {
+            context.setAttribute(HttpClientContext.TARGET_AUTH_STATE, new AuthState());
         }
-        if (context.getAttribute(ClientContext.PROXY_AUTH_STATE) == null) {
-            context.setAttribute(ClientContext.PROXY_AUTH_STATE, new AuthState());
+        if (context.getAttribute(HttpClientContext.PROXY_AUTH_STATE) == null) {
+            context.setAttribute(HttpClientContext.PROXY_AUTH_STATE, new AuthState());
         }
-        if (context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY) == null) {
-            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
+        if (context.getAttribute(HttpClientContext.AUTHSCHEME_REGISTRY) == null) {
+            context.setAttribute(HttpClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
         }
-        if (context.getAttribute(ClientContext.COOKIESPEC_REGISTRY) == null) {
-            context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
+        if (context.getAttribute(HttpClientContext.COOKIESPEC_REGISTRY) == null) {
+            context.setAttribute(HttpClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
         }
-        if (context.getAttribute(ClientContext.COOKIE_STORE) == null) {
-            context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
+        if (context.getAttribute(HttpClientContext.COOKIE_STORE) == null) {
+            context.setAttribute(HttpClientContext.COOKIE_STORE, this.cookieStore);
         }
-        if (context.getAttribute(ClientContext.CREDS_PROVIDER) == null) {
-            context.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
+        if (context.getAttribute(HttpClientContext.CREDS_PROVIDER) == null) {
+            context.setAttribute(HttpClientContext.CREDS_PROVIDER, this.credentialsProvider);
         }
-        if (context.getAttribute(ClientContext.REQUEST_CONFIG) == null) {
-            context.setAttribute(ClientContext.REQUEST_CONFIG, this.defaultConfig);
+        if (context.getAttribute(HttpClientContext.REQUEST_CONFIG) == null) {
+            context.setAttribute(HttpClientContext.REQUEST_CONFIG, this.defaultConfig);
         }
     }
 

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=1478320&r1=1478319&r2=1478320&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
Thu May  2 10:35:06 2013
@@ -36,18 +36,16 @@ import org.apache.http.ConnectionReuseSt
 import org.apache.http.HttpException;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
 import org.apache.http.HttpResponse;
-import org.apache.http.client.AuthenticationStrategy;
-import org.apache.http.client.RedirectStrategy;
-import org.apache.http.client.UserTokenHandler;
 import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.Configurable;
 import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.client.protocol.RequestClientConnControl;
 import org.apache.http.conn.ConnectionKeepAliveStrategy;
 import org.apache.http.conn.routing.HttpRoute;
-import org.apache.http.conn.routing.HttpRoutePlanner;
 import org.apache.http.nio.ContentDecoder;
 import org.apache.http.nio.ContentEncoder;
 import org.apache.http.nio.IOControl;
@@ -55,27 +53,36 @@ 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.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+import org.apache.http.util.VersionInfo;
 
 class MinimalClientExec implements InternalClientExec {
 
     private final Log log = LogFactory.getLog(getClass());
 
+    private final HttpProcessor httpProcessor;
     private final NHttpClientConnectionManager connmgr;
-    private final HttpRoutePlanner routePlanner;
+    private final ConnectionReuseStrategy connReuseStrategy;
     private final ConnectionKeepAliveStrategy keepaliveStrategy;
 
     public MinimalClientExec(
             final NHttpClientConnectionManager connmgr,
-            final HttpRoutePlanner routePlanner,
-            final ConnectionReuseStrategy reuseStrategy,
-            final ConnectionKeepAliveStrategy keepaliveStrategy,
-            final RedirectStrategy redirectStrategy,
-            final AuthenticationStrategy targetAuthStrategy,
-            final AuthenticationStrategy proxyAuthStrategy,
-            final UserTokenHandler userTokenHandler) {
+            final ConnectionReuseStrategy connReuseStrategy,
+            final ConnectionKeepAliveStrategy keepaliveStrategy) {
         super();
+        this.httpProcessor = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+                new RequestContent(),
+                new RequestTargetHost(),
+                new RequestClientConnControl(),
+                new RequestUserAgent(VersionInfo.getUserAgent(
+                        "Apache-HttpAsyncClient", "org.apache.http.nio.client", getClass()))
+        } );
         this.connmgr = connmgr;
-        this.routePlanner = routePlanner;
+        this.connReuseStrategy = connReuseStrategy;
         this.keepaliveStrategy = keepaliveStrategy;
     }
 
@@ -89,7 +96,7 @@ class MinimalClientExec implements Inter
 
         final HttpClientContext localContext = state.getLocalContext();
         final HttpRequestWrapper request = HttpRequestWrapper.wrap(original);
-        final HttpRoute route = this.routePlanner.determineRoute(target, request, localContext);
+        final HttpRoute route = new HttpRoute(target);
 
         state.setRoute(route);
         state.setMainRequest(request);
@@ -113,20 +120,22 @@ class MinimalClientExec implements Inter
             host = target;
         }
 
-        localContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST, host);
+        localContext.setAttribute(HttpClientContext.HTTP_REQUEST, request);
+        localContext.setAttribute(HttpClientContext.HTTP_TARGET_HOST, target);
         localContext.setAttribute(HttpClientContext.HTTP_ROUTE, route);
+        this.httpProcessor.process(request, localContext);
     }
 
     public HttpRequest generateRequest(
             final InternalState state,
             final InternalConnManager connManager) throws IOException, HttpException {
-        if (state.isRouteEstablished()) {
+        if (!state.isRouteEstablished()) {
             final HttpClientContext localContext = state.getLocalContext();
             final HttpRoute route = state.getRoute();
             final NHttpClientConnection managedConn = connManager.getConnection();
             this.connmgr.initialize(managedConn, route, localContext);
             this.connmgr.routeComplete(managedConn, route, localContext);
-
+            state.setRouteEstablished(true);
         }
         if (state.getCurrentRequest() == null) {
             state.setCurrentRequest(state.getMainRequest());
@@ -163,6 +172,11 @@ class MinimalClientExec implements Inter
         if (this.log.isDebugEnabled()) {
             this.log.debug("[exchange: " + state.getId() + "] Response received " + response.getStatusLine());
         }
+
+        final HttpClientContext context = state.getLocalContext();
+        context.setAttribute(HttpClientContext.HTTP_RESPONSE, response);
+        this.httpProcessor.process(response, context);
+
         state.setCurrentResponse(response);
         final HttpAsyncResponseConsumer<?> responseConsumer = state.getResponseConsumer();
         responseConsumer.responseReceived(response);
@@ -185,7 +199,7 @@ class MinimalClientExec implements Inter
         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()) {

Copied: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java
(from r1466814, 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/MinimalHttpAsyncClient.java?p2=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/MinimalHttpAsyncClient.java&p1=httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/InternalHttpAsyncClient.java&r1=1466814&r2=1478320&rev=1478320&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/MinimalHttpAsyncClient.java
Thu May  2 10:35:06 2013
@@ -31,17 +31,11 @@ import java.util.concurrent.Future;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.http.auth.AuthSchemeProvider;
-import org.apache.http.auth.AuthState;
-import org.apache.http.client.CookieStore;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.protocol.ClientContext;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.concurrent.BasicFuture;
 import org.apache.http.concurrent.FutureCallback;
-import org.apache.http.config.Lookup;
-import org.apache.http.cookie.CookieSpecProvider;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
 import org.apache.http.nio.conn.ClientAsyncConnectionManager;
 import org.apache.http.nio.conn.NHttpClientConnectionManager;
 import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
@@ -53,37 +47,23 @@ import org.apache.http.protocol.BasicHtt
 import org.apache.http.protocol.HttpContext;
 
 @SuppressWarnings("deprecation")
-class InternalHttpAsyncClient extends CloseableHttpAsyncClient {
+class MinimalHttpAsyncClient extends CloseableHttpAsyncClient {
 
     private final Log log = LogFactory.getLog(getClass());
 
     private final NHttpClientConnectionManager connmgr;
     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 Thread reactorThread;
 
     private volatile IOReactorStatus status;
 
-    public InternalHttpAsyncClient(
-            final NHttpClientConnectionManager connmgr,
-            final InternalClientExec exec,
-            final Lookup<CookieSpecProvider> cookieSpecRegistry,
-            final Lookup<AuthSchemeProvider> authSchemeRegistry,
-            final CookieStore cookieStore,
-            final CredentialsProvider credentialsProvider,
-            final RequestConfig defaultConfig) {
+    public MinimalHttpAsyncClient(
+            final NHttpClientConnectionManager connmgr) {
         super();
         this.connmgr = connmgr;
-        this.exec = exec;
-        this.cookieSpecRegistry = cookieSpecRegistry;
-        this.authSchemeRegistry = authSchemeRegistry;
-        this.cookieStore = cookieStore;
-        this.credentialsProvider = credentialsProvider;
-        this.defaultConfig = defaultConfig;
+        this.exec = new MinimalClientExec(connmgr,
+                DefaultConnectionReuseStrategy.INSTANCE,
+                DefaultConnectionKeepAliveStrategy.INSTANCE);
         this.reactorThread = new Thread() {
 
             @Override
@@ -139,30 +119,6 @@ class InternalHttpAsyncClient extends Cl
         shutdown();
     }
 
-    private void setupContext(final HttpClientContext context) {
-        if (context.getAttribute(ClientContext.TARGET_AUTH_STATE) == null) {
-            context.setAttribute(ClientContext.TARGET_AUTH_STATE, new AuthState());
-        }
-        if (context.getAttribute(ClientContext.PROXY_AUTH_STATE) == null) {
-            context.setAttribute(ClientContext.PROXY_AUTH_STATE, new AuthState());
-        }
-        if (context.getAttribute(ClientContext.AUTHSCHEME_REGISTRY) == null) {
-            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, this.authSchemeRegistry);
-        }
-        if (context.getAttribute(ClientContext.COOKIESPEC_REGISTRY) == null) {
-            context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, this.cookieSpecRegistry);
-        }
-        if (context.getAttribute(ClientContext.COOKIE_STORE) == null) {
-            context.setAttribute(ClientContext.COOKIE_STORE, this.cookieStore);
-        }
-        if (context.getAttribute(ClientContext.CREDS_PROVIDER) == null) {
-            context.setAttribute(ClientContext.CREDS_PROVIDER, this.credentialsProvider);
-        }
-        if (context.getAttribute(ClientContext.REQUEST_CONFIG) == null) {
-            context.setAttribute(ClientContext.REQUEST_CONFIG, this.defaultConfig);
-        }
-    }
-
     public <T> Future<T> execute(
             final HttpAsyncRequestProducer requestProducer,
             final HttpAsyncResponseConsumer<T> responseConsumer,
@@ -175,7 +131,6 @@ class InternalHttpAsyncClient extends Cl
         final BasicFuture<T> future = new BasicFuture<T>(callback);
         final HttpClientContext localcontext = HttpClientContext.adapt(
             context != null ? context : new BasicHttpContext());
-        setupContext(localcontext);
 
         final DefaultClientExchangeHandlerImpl<T> handler = new DefaultClientExchangeHandlerImpl<T>(
             this.log,

Added: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java?rev=1478320&view=auto
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
(added)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
Thu May  2 10:35:06 2013
@@ -0,0 +1,212 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.nio.client.integration;
+
+import java.net.InetSocketAddress;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Random;
+import java.util.concurrent.Future;
+
+import org.apache.http.HttpAsyncTestBase;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.config.ConnectionConfig;
+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.EchoHandler;
+import org.apache.http.localserver.RandomHandler;
+import org.apache.http.nio.NHttpConnectionFactory;
+import org.apache.http.nio.entity.NByteArrayEntity;
+import org.apache.http.nio.protocol.BasicAsyncRequestHandler;
+import org.apache.http.nio.protocol.HttpAsyncExpectationVerifier;
+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.util.EntityUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestHttpAsyncMinimal extends HttpAsyncTestBase {
+
+    @Before
+    public void setUp() throws Exception {
+        initServer();
+        initConnectionManager();
+        this.httpclient = HttpAsyncClients.createMinimal(this.connMgr);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        shutDownClient();
+        shutDownServer();
+    }
+
+    @Override
+    protected NHttpConnectionFactory<DefaultNHttpServerConnection> createServerConnectionFactory(
+            final ConnectionConfig config) throws Exception {
+        return new DefaultNHttpServerConnectionFactory(config);
+    }
+
+    @Override
+    protected String getSchemeName() {
+        return "http";
+    }
+
+    private HttpHost start(
+            final HttpAsyncRequestHandlerMapper requestHandlerResolver,
+            final HttpAsyncExpectationVerifier expectationVerifier) throws Exception {
+        final HttpAsyncService serviceHandler = new HttpAsyncService(
+                this.serverHttpProc,
+                new DefaultConnectionReuseStrategy(),
+                new DefaultHttpResponseFactory(),
+                requestHandlerResolver,
+                expectationVerifier);
+        this.server.start(serviceHandler);
+        this.httpclient.start();
+
+        final ListenerEndpoint endpoint = this.server.getListenerEndpoint();
+        endpoint.waitFor();
+
+        Assert.assertEquals("Test server status", IOReactorStatus.ACTIVE, this.server.getStatus());
+        final InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
+        final HttpHost target = new HttpHost("localhost", address.getPort(), getSchemeName());
+        return target;
+    }
+
+    private HttpHost start() throws Exception {
+        final UriHttpAsyncRequestHandlerMapper registry = new UriHttpAsyncRequestHandlerMapper();
+        registry.register("/echo/*", new BasicAsyncRequestHandler(new EchoHandler()));
+        registry.register("/random/*", new BasicAsyncRequestHandler(new RandomHandler()));
+        return start(registry, null);
+    }
+
+    @Test
+    public void testSingleGet() throws Exception {
+        final HttpHost target = start();
+        final HttpGet httpget = new HttpGet("/random/2048");
+        final Future<HttpResponse> future = this.httpclient.execute(target, httpget,
null);
+        final HttpResponse response = future.get();
+        Assert.assertNotNull(response);
+        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
+    }
+
+    @Test
+    public void testSinglePost() throws Exception {
+        final HttpHost target = start();
+        final byte[] b1 = new byte[1024];
+        final Random rnd = new Random(System.currentTimeMillis());
+        rnd.nextBytes(b1);
+
+        final HttpPost httppost = new HttpPost("/echo/stuff");
+        httppost.setEntity(new NByteArrayEntity(b1));
+
+        final Future<HttpResponse> future = this.httpclient.execute(target, httppost,
null);
+        final HttpResponse response = future.get();
+        Assert.assertNotNull(response);
+        Assert.assertEquals(200, response.getStatusLine().getStatusCode());
+        final HttpEntity entity = response.getEntity();
+        Assert.assertNotNull(entity);
+        final byte[] b2 = EntityUtils.toByteArray(entity);
+        Assert.assertArrayEquals(b1, b2);
+    }
+
+    @Test
+    public void testMultiplePostsOverMultipleConnections() throws Exception {
+        final HttpHost target = start();
+        final byte[] b1 = new byte[1024];
+        final Random rnd = new Random(System.currentTimeMillis());
+        rnd.nextBytes(b1);
+
+        final int reqCount = 20;
+
+        this.connMgr.setDefaultMaxPerRoute(reqCount);
+        this.connMgr.setMaxTotal(100);
+
+        final Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
+
+        for (int i = 0; i < reqCount; i++) {
+            final HttpPost httppost = new HttpPost("/echo/stuff");
+            httppost.setEntity(new NByteArrayEntity(b1));
+            queue.add(this.httpclient.execute(target, httppost, null));
+        }
+
+        while (!queue.isEmpty()) {
+            final Future<HttpResponse> future = queue.remove();
+            final HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(200, response.getStatusLine().getStatusCode());
+            final HttpEntity entity = response.getEntity();
+            Assert.assertNotNull(entity);
+            final byte[] b2 = EntityUtils.toByteArray(entity);
+            Assert.assertArrayEquals(b1, b2);
+        }
+    }
+
+    @Test
+    public void testMultiplePostsOverSingleConnection() throws Exception {
+        final HttpHost target = start();
+        final byte[] b1 = new byte[1024];
+        final Random rnd = new Random(System.currentTimeMillis());
+        rnd.nextBytes(b1);
+
+        final int reqCount = 20;
+
+        this.connMgr.setDefaultMaxPerRoute(1);
+        this.connMgr.setMaxTotal(100);
+
+        final Queue<Future<HttpResponse>> queue = new LinkedList<Future<HttpResponse>>();
+
+        for (int i = 0; i < reqCount; i++) {
+            final HttpPost httppost = new HttpPost("/echo/stuff");
+            httppost.setEntity(new NByteArrayEntity(b1));
+            queue.add(this.httpclient.execute(target, httppost, null));
+        }
+
+        while (!queue.isEmpty()) {
+            final Future<HttpResponse> future = queue.remove();
+            final HttpResponse response = future.get();
+            Assert.assertNotNull(response);
+            Assert.assertEquals(200, response.getStatusLine().getStatusCode());
+            final HttpEntity entity = response.getEntity();
+            Assert.assertNotNull(entity);
+            final byte[] b2 = EntityUtils.toByteArray(entity);
+            Assert.assertArrayEquals(b1, b2);
+        }
+    }
+
+}

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncMinimal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message