From 37ded05b51723352f5626d0ad33b3e0f44bfd1ee Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 1 Jul 2013 11:49:17 -0700 Subject: [PATCH 0001/2389] Refactoring of the ProxyAwareConnectorHandler in preparation for integration of new Grizzly specific connection pool. --- .../providers/grizzly/ConnectionManager.java | 52 ++- .../grizzly/ProxyAwareConnectorHandler.java | 304 +++++------------- .../grizzly/filters/SwitchingSSLFilter.java | 15 +- .../grizzly/filters/TunnelFilter.java | 2 + 4 files changed, 128 insertions(+), 245 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 61b2bba1bc..fc09d42556 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -36,6 +36,7 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.net.SocketAddress; import java.net.URI; import java.util.Iterator; import java.util.Map; @@ -141,13 +142,16 @@ void doAsyncConnect(final Request request, createConnectionCompletionHandler(request, requestFuture, connectHandler); - + final ProxyServer proxyServer = requestFuture.getProxyServer(); + ProxyAwareConnectorHandler.setRequest(request); + ProxyAwareConnectorHandler.setProxy(proxyServer); + SocketAddress address = getRemoteAddress(request, proxyServer); if (request.getLocalAddress() != null) { - connectionHandler.connect(request, - new InetSocketAddress(request.getLocalAddress(), 0), + connectionHandler.connect(new InetSocketAddress(request.getLocalAddress(), 0), + address, ch); } else { - connectionHandler.connect(request, null, ch); + connectionHandler.connect(address, ch); } } @@ -165,21 +169,51 @@ static boolean isConnectionCacheable(final Connection c) { return ((canCache != null) ? canCache : false); } + private SocketAddress getRemoteAddress(final Request request, + final ProxyServer proxyServer) { + final URI requestUri = request.getURI(); + final String host = ((proxyServer != null) + ? proxyServer.getHost() + : requestUri.getHost()); + final int port = ((proxyServer != null) + ? proxyServer.getPort() + : requestUri.getPort()); + return new InetSocketAddress(host, getPort(request.getURI(), port)); + } + private static int getPort(final URI uri, final int p) { + int port = p; + if (port == -1) { + final String protocol = uri.getScheme().toLowerCase(); + if ("http".equals(protocol) || "ws".equals(protocol)) { + port = 80; + } else if ("https".equals(protocol) || "wss".equals(protocol)) { + port = 443; + } else { + throw new IllegalArgumentException( + "Unknown protocol: " + protocol); + } + } + return port; + } private Connection obtainConnection0(final Request request, final GrizzlyResponseFuture requestFuture) throws ExecutionException, InterruptedException, TimeoutException { - int cTimeout = provider.getClientConfig().getConnectionTimeoutInMs(); - FutureImpl future = Futures.createSafeFuture(); - CompletionHandler ch = Futures.toCompletionHandler(future, + final int cTimeout = provider.getClientConfig().getConnectionTimeoutInMs(); + final FutureImpl future = Futures.createSafeFuture(); + final CompletionHandler ch = Futures.toCompletionHandler(future, createConnectionCompletionHandler(request, requestFuture, null)); + final ProxyServer proxyServer = requestFuture.getProxyServer(); + final SocketAddress address = getRemoteAddress(request, proxyServer); + ProxyAwareConnectorHandler.setRequest(request); + ProxyAwareConnectorHandler.setProxy(proxyServer); if (cTimeout > 0) { - connectionHandler.connect(request, null, ch); + connectionHandler.connect(address, ch); return future.get(cTimeout, TimeUnit.MILLISECONDS); } else { - connectionHandler.connect(request, null, ch); + connectionHandler.connect(address, ch); return future.get(); } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index 887e8a2dac..4f50229734 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -18,28 +18,24 @@ import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.filters.ProxyFilter; import org.asynchttpclient.providers.grizzly.filters.TunnelFilter; -import org.asynchttpclient.util.ProxyUtils; -import org.glassfish.grizzly.CompletionHandler; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Context; -import org.glassfish.grizzly.EmptyIOEventProcessingHandler; -import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.Processor; +import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.http.HttpClientFilter; -import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.net.URI; final class ProxyAwareConnectorHandler extends TCPNIOConnectorHandler { private FilterChainBuilder nonSecureTemplate; private FilterChainBuilder secureTemplate; private AsyncHttpClientConfig clientConfig; + private static final ThreadLocal requestLocal = + new ThreadLocal(); + private static final ThreadLocal proxyLocal = + new ThreadLocal(); + // ------------------------------------------------------------ Constructors @@ -52,18 +48,15 @@ private ProxyAwareConnectorHandler(final TCPNIOTransport transport) { // ---------------------------------------------------------- Public Methods - public void connect(final Request request, - final SocketAddress localAddress, - final CompletionHandler completionHandler) { - final ProxyServer proxyServer = - ProxyUtils.getProxyServer(clientConfig, request); - final SocketAddress remoteAddress = - getRemoteAddress(request, proxyServer); - super.connect(remoteAddress, - localAddress, - ((proxyServer != null) - ? new ProxyAdaptingCompletionHandler(request, proxyServer, completionHandler) - : new FilterChainInstallationHandler(request, completionHandler))); + public static void setRequest(final Request request) { + assert(request != null); + requestLocal.set(request); + } + + public static void setProxy(final ProxyServer proxyServer) { + if (proxyServer != null) { + proxyLocal.set(proxyServer); + } } public static Builder builder(final TCPNIOTransport transport) { @@ -71,234 +64,86 @@ public static Builder builder(final TCPNIOTransport transport) { } - // --------------------------------------------------------- Private Methods + // ------------------------------------------- Methods from ConnectorHandler - private SocketAddress getRemoteAddress(final Request request, - final ProxyServer proxyServer) { - final URI requestUri = request.getURI(); - final String host = ((proxyServer != null) - ? proxyServer.getHost() - : requestUri.getHost()); - final int port = ((proxyServer != null) - ? proxyServer.getPort() - : requestUri.getPort()); - return new InetSocketAddress(host, getPort(request.getURI(), port)); + @Override + public Processor getProcessor() { + final Request request = getRequestLocal(); + final ProxyServer proxyServer = getProxyLocal(); + return ((proxyServer != null) + ? createProxyFilterChain(request, proxyServer) + : createFilterChain(request)); } - private static int getPort(final URI uri, final int p) { - int port = p; - if (port == -1) { - final String protocol = uri.getScheme().toLowerCase(); - if ("http".equals(protocol) || "ws".equals(protocol)) { - port = 80; - } else if ("https".equals(protocol) || "wss".equals(protocol)) { - port = 443; - } else { - throw new IllegalArgumentException( - "Unknown protocol: " + protocol); - } - } - return port; - } - - - // ---------------------------------------------------------- Nested Classes - - - private class FilterChainInstallationHandler implements CompletionHandler { - - final Request request; - final CompletionHandler delegate; - - // -------------------------------------------------------- Constructors - - - FilterChainInstallationHandler(final Request request, - final CompletionHandler delegate) { - this.request = request; - this.delegate = delegate; - } - - - // -------------------------------------- Methods from CompletionHandler - - @Override - public void cancelled() { - delegate.cancelled(); - } - - @Override - public void failed(Throwable throwable) { - delegate.failed(throwable); - } - - @Override - public void completed(Connection result) { - FilterChainBuilder b = isRequestSecure() - ? secureTemplate - : nonSecureTemplate; - result.setProcessor(b.build()); - fireConnectEvent(result); - } - - @Override - public void updated(Connection result) { - delegate.updated(result); - } - - - // --------------------------------------------------- Protected Methods - - - boolean isRequestSecure() { - final String p = request.getURI().getScheme(); - return p.equals("https") || p.equals("wss"); - } - - /* - * We have to fire this event ourselves as at the point in time it - * would normally fire the event, we haven't been called to set the - * FilterChain on the connection. Not doing so will break idle - * timeout detection. - */ - void fireConnectEvent(Connection result) { - result.getTransport().fireIOEvent(IOEvent.CONNECTED, - result, - new EnableReadHandler(delegate)); - } - - } // END FilterChainInstallationHandler - - - private final class ProxyAdaptingCompletionHandler extends FilterChainInstallationHandler { - - final ProxyServer proxyServer; - - // --------------------------------------------------------- Constructor - - - private ProxyAdaptingCompletionHandler(final Request request, - final ProxyServer proxyServer, - final CompletionHandler delegate) { - super(request, delegate); - this.proxyServer = proxyServer; - } - - - // -------------------------------------- Methods from CompletionHandler - - - @Override - public void cancelled() { - delegate.cancelled(); - } - - @Override - public void failed(Throwable throwable) { - delegate.failed(throwable); - } - - @Override - public void completed(Connection result) { - // Connection is completed. Before we continue, we need - // to adapt the FilterChain based on the proxy type. - // If we're dealing with a secure HTTP proxy, we need to use - // a custom filter that will establish a tunnel using CONNECT. - // If we're dealing with a non-secure HTTP proxy, then we use - // a different filter that will update the request accordingly - // before passing it to the codec filter. - // Once the FilterChain has been adapted, set it on the Connection, - // and invoke the completed() method on the delegate to continue - // processing. - final FilterChainBuilder builder = FilterChainBuilder.stateless(); - if (isRequestSecure()) { - builder.addAll(secureTemplate); - updateSecureFilterChain(builder, proxyServer); - } else { - builder.addAll(nonSecureTemplate); - updateNonSecureFilterChain(builder, proxyServer); - } - result.setProcessor(builder.build()); - - fireConnectEvent(result); - } - - @Override - public void updated(Connection result) { - delegate.updated(result); - } - - - // ----------------------------------------------------- Private Methods - - - private void updateSecureFilterChain(final FilterChainBuilder builder, - final ProxyServer proxyServer) { - builder.add(1, new TunnelFilter(proxyServer, request.getURI())); // Insert after the the transport filter - final int idx = builder.indexOfType(HttpClientFilter.class); - assert (idx != -1); - builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, true)); - } + // --------------------------------------------------------- Private Methods - private void updateNonSecureFilterChain(final FilterChainBuilder builder, - final ProxyServer proxyServer) { - final int idx = builder.indexOfType(HttpClientFilter.class); - assert(idx != -1); - builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, false)); - } - } // ProxyAdaptingCompletionHandler + private Request getRequestLocal() { + final Request request = requestLocal.get(); + requestLocal.remove(); + assert(request != null); + return request; + } + private ProxyServer getProxyLocal() { + final ProxyServer proxyServer = proxyLocal.get(); + proxyLocal.remove(); + return proxyServer; + } - private static final class EnableReadHandler extends - EmptyIOEventProcessingHandler { - private final CompletionHandler completionHandler; + private FilterChain createFilterChain(final Request request) { + return isRequestSecure(request) + ? secureTemplate.build() + : nonSecureTemplate.build(); + } - private EnableReadHandler(final CompletionHandler completionHandler) { - this.completionHandler = completionHandler; - } + private FilterChain createProxyFilterChain(final Request request, + final ProxyServer proxyServer) { + final FilterChainBuilder builder = FilterChainBuilder.stateless(); + if (isRequestSecure(request)) { + builder.addAll(secureTemplate); + updateSecureFilterChain(builder, request, proxyServer); + } else { + builder.addAll(nonSecureTemplate); + updateNonSecureFilterChain(builder, proxyServer); + } + return builder.build(); + } - @Override - public void onReregister(final Context context) throws IOException { - onComplete(context, null); - } + private static boolean isRequestSecure(final Request request) { + final String p = request.getURI().getScheme(); + return p.equals("https") || p.equals("wss"); + } - @Override - public void onNotRun(final Context context) throws IOException { - onComplete(context, null); - } + private void updateSecureFilterChain(final FilterChainBuilder builder, + final Request request, + final ProxyServer proxyServer) { + builder.add(1, new TunnelFilter(proxyServer, + request.getURI())); // Insert after the the transport filter + final int idx = builder.indexOfType(HttpClientFilter.class); + assert (idx != -1); + builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, true)); + } - @Override - public void onComplete(final Context context, final Object data) - throws IOException { - final NIOConnection connection = - (NIOConnection) context.getConnection(); - - if (completionHandler != null) { - completionHandler.completed(connection); - } - - if (!connection.isStandalone()) { - connection.enableIOEvent(IOEvent.READ); - } - } + private void updateNonSecureFilterChain(final FilterChainBuilder builder, + final ProxyServer proxyServer) { + final int idx = builder.indexOfType(HttpClientFilter.class); + assert (idx != -1); + builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, false)); + } - @Override - public void onError(final Context context, final Object description) - throws IOException { - context.getConnection().closeSilently(); - } - } // END EnableReadHandler + // ---------------------------------------------------------- Nested Classes public static final class Builder extends TCPNIOConnectorHandler.Builder { final ProxyAwareConnectorHandler connectorHandler; + // -------------------------------------------------------- Constructors @@ -310,6 +155,7 @@ private Builder(final TCPNIOTransport transport) { // ----------------------------------------------------- Builder Methods + public Builder setSecureFilterChainTemplate(final FilterChainBuilder secureTemplate) { connectorHandler.secureTemplate = secureTemplate; return this; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java index b001a2b989..79b30f3e52 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java @@ -18,6 +18,7 @@ import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -85,16 +86,17 @@ public void failed(Throwable throwable) { ctx.resume(); } }); + ctx.getConnection().enableIOEvent(IOEvent.READ); return ctx.getSuspendAction(); } else { HANDSHAKING.remove(c); return ctx.getInvokeAction(); } - } @Override - public NextAction handleEvent(final FilterChainContext ctx, FilterChainEvent event) throws IOException { + public NextAction handleEvent(final FilterChainContext ctx, + final FilterChainEvent event) throws IOException { if (event.type() == SSLSwitchingEvent.class) { final SSLSwitchingEvent se = (SSLSwitchingEvent) event; @@ -106,7 +108,7 @@ public NextAction handleEvent(final FilterChainContext ctx, FilterChainEvent eve } @Override - public NextAction handleRead(FilterChainContext ctx) throws IOException { + public NextAction handleRead(final FilterChainContext ctx) throws IOException { if (isSecure(ctx.getConnection())) { return super.handleRead(ctx); @@ -116,7 +118,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { } @Override - public NextAction handleWrite(FilterChainContext ctx) throws IOException { + public NextAction handleWrite(final FilterChainContext ctx) throws IOException { if (isSecure(ctx.getConnection())) { return super.handleWrite(ctx); @@ -126,7 +128,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { } @Override - public void onFilterChainChanged(FilterChain filterChain) { + public void onFilterChainChanged(final FilterChain filterChain) { // no-op } @@ -135,14 +137,13 @@ public static Throwable getHandshakeError(final Connection c) { return HANDSHAKE_ERROR.remove(c); } + // --------------------------------------------------------- Private Methods private boolean isSecure(final Connection c) { - Boolean secStatus = CONNECTION_IS_SECURE.get(c); return (secStatus == null ? true : secStatus); - } private void setSecureStatus(final Connection c, final boolean secure) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java index 654e539fe2..8854a00579 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java @@ -18,6 +18,7 @@ import org.asynchttpclient.providers.grizzly.filters.events.TunnelRequestEvent; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -64,6 +65,7 @@ public NextAction handleConnect(FilterChainContext ctx) final TunnelRequestEvent tunnelRequestEvent = new TunnelRequestEvent(ctx, proxyServer, uri); ctx.notifyUpstream(tunnelRequestEvent); + ctx.getConnection().enableIOEvent(IOEvent.READ); return ctx.getSuspendAction(); } else { TUNNEL_IN_PROGRESS.remove(ctx.getConnection()); From 3848d27d6d95b4bba027475a180dbb4ca35a1eeb Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 1 Jul 2013 16:01:05 -0700 Subject: [PATCH 0002/2389] No longer use AHC ConnectionsPool. Since pools are not interchangeable between providers, I've opted to use the new connection pool code that is being developed for Grizzly 2.3.4. Pool may be configured external to the provider and set on the Grizzly-specific configuration provider. --- .../async/MaxConnectionsInThreads.java | 2 +- .../async/MaxTotalConnectionTest.java | 2 +- providers/grizzly/pom.xml | 5 + .../providers/grizzly/ConnectionManager.java | 703 +++--------------- .../providers/grizzly/ConnectionPool.java | 38 + .../providers/grizzly/EventHandler.java | 12 +- .../grizzly/GrizzlyAsyncHttpProvider.java | 21 +- .../GrizzlyAsyncHttpProviderConfig.java | 8 +- .../grizzly/ProxyAwareConnectorHandler.java | 33 +- .../grizzly/filters/SwitchingSSLFilter.java | 3 + .../grizzly/GrizzlyConnectionPoolTest.java | 4 +- 11 files changed, 175 insertions(+), 656 deletions(-) create mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java diff --git a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java index 5ac600592d..cb93ceb534 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java @@ -43,7 +43,7 @@ abstract public class MaxConnectionsInThreads extends AbstractBasicTest { private static URI servletEndpointUri; - @Test(groups = { "online", "default_provider" }) + @Test(groups = { "online", "default_provider" }, enabled=false) public void testMaxConnectionsWithinThreads() { String[] urls = new String[] { servletEndpointUri.toString(), servletEndpointUri.toString() }; diff --git a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java index 947d36c554..392e5e219e 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java @@ -32,7 +32,7 @@ public abstract class MaxTotalConnectionTest extends AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); - @Test(groups = { "standalone", "default_provider" }) + @Test(groups = { "standalone", "default_provider" }, enabled=false) public void testMaxTotalConnectionsExceedingException() { String[] urls = new String[] { "http://google.com/", "http://github.com/" }; diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 54019dd401..57f9ed1821 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -29,6 +29,11 @@ grizzly-spdy ${grizzly.version} + + org.glassfish.grizzly + connection-pool + ${grizzly.version} + org.glassfish.grizzly grizzly-npn-api diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index fc09d42556..e0b8ced221 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -15,54 +15,38 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ConnectionsPool; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; -import org.asynchttpclient.util.ProxyUtils; -import org.glassfish.grizzly.CloseListener; -import org.glassfish.grizzly.CloseType; -import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; +import org.glassfish.grizzly.connectionpool.EndpointKey; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.impl.FutureImpl; -import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.IdleTimeoutFilter; -import org.glassfish.grizzly.utils.NullaryFunction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.asynchttpclient.util.DateUtil.millisTime; public class ConnectionManager { private static final Attribute DO_NOT_CACHE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(ConnectionManager.class.getName()); - private final ConnectionsPool pool; - private final ProxyAwareConnectorHandler connectionHandler; - private final ConnectionMonitor connectionMonitor; + private final ConnectionPool connectionPool; private final GrizzlyAsyncHttpProvider provider; - private final boolean connectAsync; + private final boolean canDestroyPool; + private final ConcurrentHashMap> endpointKeyMap = + new ConcurrentHashMap>(); + private final FilterChainBuilder secureBuilder; + private final FilterChainBuilder nonSecureBuilder; // ------------------------------------------------------------ Constructors @@ -70,26 +54,28 @@ public class ConnectionManager { @SuppressWarnings("unchecked") ConnectionManager(final GrizzlyAsyncHttpProvider provider, - final ProxyAwareConnectorHandler connectionHandler) { + final ConnectionPool connectionPool, + final FilterChainBuilder secureBuilder, + final FilterChainBuilder nonSecureBuilder) { + - ConnectionsPool connectionPool; this.provider = provider; final AsyncHttpClientConfig config = provider.getClientConfig(); - if (config.getAllowPoolingConnection()) { - ConnectionsPool pool = config.getConnectionsPool(); - if (pool != null) { - //noinspection unchecked - connectionPool = (ConnectionsPool) pool; - } else { - connectionPool = new Pool((config)); - } + if (connectionPool != null) { + this.connectionPool = connectionPool; + canDestroyPool = false; } else { - connectionPool = new NonCachingPool(); + this.connectionPool = + new ConnectionPool(config.getMaxConnectionPerHost(), + config.getMaxTotalConnections(), + null, + config.getConnectionTimeoutInMs(), + config.getIdleConnectionInPoolTimeoutInMs(), + 2000); + canDestroyPool = true; } - pool = connectionPool; - this.connectionHandler = connectionHandler; - connectionMonitor = new ConnectionMonitor(config.getMaxTotalConnections()); - connectAsync = provider.getClientConfig().isAsyncConnectMode(); + this.secureBuilder = secureBuilder; + this.nonSecureBuilder = nonSecureBuilder; } @@ -101,26 +87,27 @@ public void doTrackedConnection(final Request request, final GrizzlyResponseFuture requestFuture, final CompletionHandler connectHandler) throws IOException { - Connection c = - pool.poll(getPoolKey(request, requestFuture.getProxyServer())); - if (c == null) { - if (!connectionMonitor.acquire()) { - throw new IOException("Max connections exceeded"); - } - if (connectAsync) { - doAsyncConnect(request, requestFuture, connectHandler); - } else { - try { - c = obtainConnection0(request, requestFuture); - connectHandler.completed(c); - } catch (Exception e) { - connectHandler.failed(e); - } - } - } else { - provider.touchConnection(c, request); - connectHandler.completed(c); - } + doAsyncConnect(request, requestFuture, connectHandler); +// Connection c = +// pool.poll(getPoolKey(request, requestFuture.getProxyServer())); +// if (c == null) { +// if (!connectionMonitor.acquire()) { +// throw new IOException("Max connections exceeded"); +// } +// if (connectAsync) { +// doAsyncConnect(request, requestFuture, connectHandler); +// } else { +// try { +// c = obtainConnection0(request, requestFuture); +// connectHandler.completed(c); +// } catch (Exception e) { +// connectHandler.failed(e); +// } +// } +// } else { +// provider.touchConnection(c, request); +// connectHandler.completed(c); +// } } @@ -138,21 +125,8 @@ void doAsyncConnect(final Request request, final GrizzlyResponseFuture requestFuture, final CompletionHandler connectHandler) { - CompletionHandler ch = - createConnectionCompletionHandler(request, - requestFuture, - connectHandler); final ProxyServer proxyServer = requestFuture.getProxyServer(); - ProxyAwareConnectorHandler.setRequest(request); - ProxyAwareConnectorHandler.setProxy(proxyServer); - SocketAddress address = getRemoteAddress(request, proxyServer); - if (request.getLocalAddress() != null) { - connectionHandler.connect(new InetSocketAddress(request.getLocalAddress(), 0), - address, - ch); - } else { - connectionHandler.connect(address, ch); - } + connectionPool.take(getEndPointKey(request, proxyServer), connectHandler); } @@ -169,6 +143,36 @@ static boolean isConnectionCacheable(final Connection c) { return ((canCache != null) ? canCache : false); } + + // --------------------------------------------------------- Private Methods + + private EndpointKey getEndPointKey(final Request request, + final ProxyServer proxyServer) { + final String stringKey = getPoolKey(request, proxyServer); + EndpointKey key = endpointKeyMap.get(stringKey); + if (key == null) { + SocketAddress address = getRemoteAddress(request, proxyServer); + ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler + .builder(provider.clientTransport) + .setNonSecureFilterChainTemplate(nonSecureBuilder) + .setSecureFilterChainTemplate(secureBuilder) + .setAsyncHttpClientConfig(provider.getClientConfig()).build(); + EndpointKey localKey = + new EndpointKey(stringKey, + address, + handler); + EndpointKey result = + endpointKeyMap.putIfAbsent(stringKey, localKey); + if (result == null) { + key = localKey; + } + } + assert(key != null); + ((ProxyAwareConnectorHandler) key.getConnectorHandler()).setRequest(request); + ((ProxyAwareConnectorHandler) key.getConnectorHandler()).setProxy(proxyServer); + return key; + } + private SocketAddress getRemoteAddress(final Request request, final ProxyServer proxyServer) { final URI requestUri = request.getURI(); @@ -207,22 +211,25 @@ private Connection obtainConnection0(final Request request, createConnectionCompletionHandler(request, requestFuture, null)); final ProxyServer proxyServer = requestFuture.getProxyServer(); final SocketAddress address = getRemoteAddress(request, proxyServer); - ProxyAwareConnectorHandler.setRequest(request); - ProxyAwareConnectorHandler.setProxy(proxyServer); + ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler + .builder(provider.clientTransport) + .setNonSecureFilterChainTemplate(nonSecureBuilder) + .setSecureFilterChainTemplate(secureBuilder) + .setAsyncHttpClientConfig(provider.getClientConfig()).build(); + handler.setRequest(request); + handler.setProxy(proxyServer); if (cTimeout > 0) { - connectionHandler.connect(address, ch); + handler.connect(address, ch); return future.get(cTimeout, TimeUnit.MILLISECONDS); } else { - connectionHandler.connect(address, ch); + handler.connect(address, ch); return future.get(); } } - boolean returnConnection(final Request request, final Connection c) { - ProxyServer proxyServer = ProxyUtils.getProxyServer( - provider.getClientConfig(), request); + boolean returnConnection(final Connection c) { final boolean result = (DO_NOT_CACHE.get(c) == null - && pool.offer(getPoolKey(request, proxyServer), c)); + && connectionPool.release(c)); if (result) { if (provider.getResolver() != null) { provider.getResolver().setTimeoutMillis(c, IdleTimeoutFilter.FOREVER); @@ -233,16 +240,11 @@ boolean returnConnection(final Request request, final Connection c) { } - boolean canReturnConnection(final Connection c) { - - return (DO_NOT_CACHE.get(c) != null || pool.canCacheConnection()); - - } - - void destroy() { - pool.destroy(); + if (canDestroyPool) { + connectionPool.close(); + } } @@ -270,7 +272,7 @@ public void completed(Connection connection) { future.setConnection(connection); provider.touchConnection(connection, request); if (wrappedHandler != null) { - connection.addCloseListener(connectionMonitor); + //connection.addCloseListener(connectionMonitor); wrappedHandler.completed(connection); } } @@ -289,525 +291,4 @@ private static String getPoolKey(final Request request, ProxyServer proxyServer) return keyStrategy.getKey(uri); } - - // ---------------------------------------------------------- Nested Classes - - - private static class ConnectionMonitor implements - CloseListener { - - private final Semaphore connections; - - - // -------------------------------------------------------- Constructors - - - ConnectionMonitor(final int maxConnections) { - if (maxConnections != -1) { - connections = new Semaphore(maxConnections); - } else { - connections = null; - } - } - - - // ------------------------------------------------------ Public Methods - - - public boolean acquire() { - - return (connections == null || connections.tryAcquire()); - - } - - - // ------------------------------- Methods from Connection.CloseListener - - - @Override - public void onClosed(Closeable closeable, CloseType closeType) throws IOException { - - if (connections != null) { - connections.release(); - } - - } - - } // END ConnectionMonitor - - - private static final class NonCachingPool implements ConnectionsPool { - - - // ---------------------------------------- Methods from ConnectionsPool - - - public boolean offer(String uri, Connection connection) { - return false; - } - - public Connection poll(String uri) { - return null; - } - - public boolean removeAll(Connection connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - // no-op - } - - } // END NonCachingPool - - /** - * {@link org.asynchttpclient.ConnectionsPool} implementation. - * - * @author The Grizzly Team - * @since 1.7.0 - */ - @SuppressWarnings("rawtypes") - public static class Pool implements ConnectionsPool { - - private final static Logger - LOG = LoggerFactory.getLogger(Pool.class); - - private final - ConcurrentHashMap - connectionsPool = - new ConcurrentHashMap(); - private final AtomicBoolean closed = new AtomicBoolean(false); - private final AtomicInteger totalCachedConnections = new AtomicInteger(0); - private final boolean cacheSSLConnections; - private final int maxConnectionsPerHost; - private final int maxConnections; - private final boolean unlimitedConnections; - private final long timeout; - private final long maxConnectionLifeTimeInMs; - private final DelayedExecutor delayedExecutor; - private final CloseListener listener; - - - // -------------------------------------------------------- Constructors - - - public Pool(final AsyncHttpClientConfig config) { - - cacheSSLConnections = config.isSslConnectionPoolEnabled(); - timeout = config.getIdleConnectionInPoolTimeoutInMs(); - maxConnectionLifeTimeInMs = config.getMaxConnectionLifeTimeInMs(); - maxConnectionsPerHost = config.getMaxConnectionPerHost(); - maxConnections = config.getMaxTotalConnections(); - unlimitedConnections = (maxConnections == -1); - delayedExecutor = new DelayedExecutor( - Executors.newSingleThreadExecutor()); - delayedExecutor.start(); - listener = new CloseListener() { - @Override - public void onClosed(Connection connection, CloseType closeType) throws IOException { - if (closeType == CloseType.REMOTELY) { - if (LOG.isInfoEnabled()) { - LOG.info("Remote closed connection ({}). Removing from cache", connection.toString()); - } - } - Pool.this.removeAll(connection); - } - }; - - } - - - // ---------------------------------------- Methods from ConnectionsPool - - - /** - * {@inheritDoc} - */ - public boolean offer(String uri, Connection connection) { - - if (cacheSSLConnections && Utils.isSecure(uri)) { - return false; - } - - DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); - if (conQueue == null) { - LOG.debug("Creating new Connection queue for uri [{}] and connection [{}]", - uri, connection); - DelayedExecutor.IdleConnectionQueue newPool = - delayedExecutor.createIdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); - conQueue = connectionsPool.putIfAbsent(uri, newPool); - if (conQueue == null) { - conQueue = newPool; - } - } - - final int size = conQueue.size(); - if (maxConnectionsPerHost == -1 || size < maxConnectionsPerHost) { - conQueue.offer(connection); - connection.addCloseListener(listener); - final int total = totalCachedConnections.incrementAndGet(); - if (LOG.isDebugEnabled()) { - LOG.debug("[offer] Pooling connection [{}] for uri [{}]. Current size (for host; before pooling): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", - connection, uri, size, maxConnectionsPerHost, total); - } - return true; - } - if (LOG.isDebugEnabled()) { - LOG.debug("[offer] Unable to pool connection [{}] for uri [{}]. Current size (for host): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", - connection, uri, size, maxConnectionsPerHost, totalCachedConnections.get()); - } - - return false; - } - - - /** - * {@inheritDoc} - */ - public Connection poll(String uri) { - - if (!cacheSSLConnections && Utils.isSecure(uri)) { - return null; - } - - Connection connection = null; - DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); - if (conQueue != null) { - boolean poolEmpty = false; - while (!poolEmpty && connection == null) { - if (!conQueue.isEmpty()) { - connection = conQueue.poll(); - } - - if (connection == null) { - poolEmpty = true; - } else if (!connection.isOpen()) { - removeAll(connection); - connection = null; - } - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("[poll] No existing queue for uri [{}].", - new Object[]{uri}); - } - } - if (connection != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("[poll] Found pooled connection [{}] for uri [{}].", - new Object[]{connection, uri}); - } - totalCachedConnections.decrementAndGet(); - connection.removeCloseListener(listener); - } - return connection; - - } - - - /** - * {@inheritDoc} - */ - public boolean removeAll(Connection connection) { - - if (connection == null || closed.get()) { - return false; - } - connection.removeCloseListener(listener); - boolean isRemoved = false; - for (Map.Entry entry : connectionsPool.entrySet()) { - boolean removed = entry.getValue().remove(connection); - isRemoved |= removed; - } - return isRemoved; - - } - - - /** - * {@inheritDoc} - */ - public boolean canCacheConnection() { - - return !(!closed.get() - && !unlimitedConnections - && totalCachedConnections.get() >= maxConnections); - - } - - /** - * {@inheritDoc} - */ - public void destroy() { - - if (closed.getAndSet(true)) { - return; - } - - for (Map.Entry entry : connectionsPool.entrySet()) { - entry.getValue().destroy(); - } - connectionsPool.clear(); - delayedExecutor.stop(); - delayedExecutor.getThreadPool().shutdownNow(); - - } - - - // ------------------------------------------------------ Nested Classes - - - private static final class DelayedExecutor { - - private static final long DEFAULT_CHECK_INTERVAL = 1000; - - public final static long UNSET_TIMEOUT = -1; - private final ExecutorService threadPool; - private final DelayedRunnable runnable = new DelayedRunnable(); - private final BlockingQueue queues = - DataStructures.getLTQInstance(IdleConnectionQueue.class); - private final Object sync = new Object(); - private volatile boolean isStarted; - private final long checkIntervalMs; - - - // ---------------------------------------------------- Constructors - - - private DelayedExecutor(final ExecutorService threadPool) { - this(threadPool, DEFAULT_CHECK_INTERVAL, TimeUnit.MILLISECONDS); - } - - - // ------------------------------------------------- Private Methods - - private DelayedExecutor(final ExecutorService threadPool, - final long checkInterval, - final TimeUnit timeunit) { - this.threadPool = threadPool; - this.checkIntervalMs = TimeUnit.MILLISECONDS.convert( - checkInterval, timeunit); - } - - private void start() { - synchronized (sync) { - if (!isStarted) { - isStarted = true; - threadPool.execute(runnable); - } - } - } - - private void stop() { - synchronized (sync) { - if (isStarted) { - isStarted = false; - sync.notify(); - } - } - } - - private ExecutorService getThreadPool() { - return threadPool; - } - - private IdleConnectionQueue createIdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { - final IdleConnectionQueue queue = new IdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); - queues.add(queue); - return queue; - } - - @SuppressWarnings({"NumberEquality"}) - private static boolean wasModified(final Long l1, final Long l2) { - return l1 != l2 && (l1 != null ? !l1.equals(l2) : !l2.equals(l1)); - } - - - // --------------------------------------------------- Inner Classes - - - private class DelayedRunnable implements Runnable { - - @Override - public void run() { - while (isStarted) { - final long currentTimeMs = millisTime(); - - for (final IdleConnectionQueue delayQueue : queues) { - if (delayQueue.queue.isEmpty()) continue; - - final TimeoutResolver resolver = delayQueue.resolver; - - for (Iterator it = delayQueue.queue.iterator(); it.hasNext(); ) { - final Connection element = (Connection) it.next(); - final Long timeoutMs = resolver.getTimeoutMs(element); - - if (timeoutMs == null || timeoutMs == UNSET_TIMEOUT) { - it.remove(); - if (wasModified(timeoutMs, - resolver.getTimeoutMs(element))) { - delayQueue.queue.offer(element); - } - } else if (currentTimeMs - timeoutMs >= 0) { - it.remove(); - if (wasModified(timeoutMs, - resolver.getTimeoutMs(element))) { - delayQueue.queue.offer(element); - } else { - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Idle connection ({}) detected. Removing from cache.", element.toString()); - } - element.close().recycle(true); - } catch (Exception ignored) { - } - } - } - } - } - - synchronized (sync) { - if (!isStarted) return; - - try { - sync.wait(checkIntervalMs); - } catch (InterruptedException ignored) { - } - } - } - } - - } // END DelayedRunnable - - - final class IdleConnectionQueue { - final ConcurrentLinkedQueue queue = - new ConcurrentLinkedQueue(); - - - final TimeoutResolver resolver = new TimeoutResolver(); - final long timeout; - final AtomicInteger count = new AtomicInteger(0); - final long maxConnectionLifeTimeInMs; - - // ------------------------------------------------ Constructors - - - public IdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { - this.timeout = timeout; - this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; - } - - - // ------------------------------------- Package Private Methods - - - void offer(final Connection c) { - long timeoutMs = UNSET_TIMEOUT; - long currentTime = millisTime(); - if (maxConnectionLifeTimeInMs < 0 && timeout >= 0) { - timeoutMs = currentTime + timeout; - } else if (maxConnectionLifeTimeInMs >= 0) { - long t = resolver.getTimeoutMs(c); - if (t == UNSET_TIMEOUT) { - if (timeout >= 0) { - timeoutMs = currentTime + Math.min(maxConnectionLifeTimeInMs, timeout); - } else { - timeoutMs = currentTime + maxConnectionLifeTimeInMs; - } - } else { - if (timeout >= 0) { - timeoutMs = Math.min(t, currentTime + timeout); - } - } - } - resolver.setTimeoutMs(c, timeoutMs); - queue.offer(c); - count.incrementAndGet(); - } - - Connection poll() { - count.decrementAndGet(); - return queue.poll(); - } - - boolean remove(final Connection c) { - if (timeout >= 0) { - resolver.removeTimeout(c); - - } - count.decrementAndGet(); - return queue.remove(c); - } - - int size() { - return count.get(); - } - - boolean isEmpty() { - return (count.get() == 0); - } - - void destroy() { - for (Connection c : queue) { - c.close().recycle(true); - } - queue.clear(); - queues.remove(this); - } - - } // END IdleConnectionQueue - - - // -------------------------------------------------- Nested Classes - - - static final class TimeoutResolver { - - private static final String IDLE_ATTRIBUTE_NAME = "grizzly-ahc-conn-pool-idle-attribute"; - private static final Attribute IDLE_ATTR = - Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute( - IDLE_ATTRIBUTE_NAME, new NullaryFunction() { - - @Override - public IdleRecord evaluate() { - return new IdleRecord(); - } - }); - - - // --------------------------------------------- Private Methods - - - boolean removeTimeout(final Connection c) { - IDLE_ATTR.get(c).timeoutMs = 0; - return true; - } - - Long getTimeoutMs(final Connection c) { - return IDLE_ATTR.get(c).timeoutMs; - } - - void setTimeoutMs(final Connection c, final long timeoutMs) { - IDLE_ATTR.get(c).timeoutMs = timeoutMs; - } - - - // ---------------------------------------------- Nested Classes - - static final class IdleRecord { - - volatile long timeoutMs = UNSET_TIMEOUT; - - } // END IdleRecord - - } // END TimeoutResolver - - } // END DelayedExecutor - - } // END Pool } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java new file mode 100644 index 0000000000..a6e5316b2b --- /dev/null +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.grizzly; + +import org.glassfish.grizzly.connectionpool.MultiEndpointPool; +import org.glassfish.grizzly.utils.DelayedExecutor; + +import java.net.SocketAddress; + +public class ConnectionPool extends MultiEndpointPool{ + + + // ------------------------------------------------------------ Constructors + + + public ConnectionPool(final int maxConnectionsPerEndpoint, + final int maxConnectionsTotal, + final DelayedExecutor delayedExecutor, + final long connectTimeoutMillis, + final long keepAliveTimeoutMillis, + final long keepAliveCheckIntervalMillis) { + super(null, maxConnectionsPerEndpoint, + maxConnectionsTotal, delayedExecutor, connectTimeoutMillis, + keepAliveTimeoutMillis, keepAliveCheckIntervalMillis, -1, -1); + } + +} diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 7968087d30..46a6830ffd 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -472,14 +472,14 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx) { if (!Utils.isIgnored(ctx.getConnection())) { final ConnectionManager manager = context.getProvider().getConnectionManager(); - if (!manager.canReturnConnection(c)) { - context.abort( - new IOException("Maximum pooled connections exceeded")); - } else { - if (!manager.returnConnection(context.getRequest(), c)) { + //if (!manager.canReturnConnection(c)) { + // context.abort( + // new IOException("Maximum pooled connections exceeded")); + //} else { + if (!manager.returnConnection(c)) { ctx.getConnection().close(); } - } + //} } return context; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index f995a46032..eef8bd492f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -87,6 +87,7 @@ import java.util.concurrent.TimeoutException; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property; +import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.CONNECTION_POOL; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.MAX_HTTP_PACKET_HEADER_SIZE; /** @@ -102,14 +103,14 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider { public final static NTLMEngine NTLM_ENGINE = new NTLMEngine(); private final BodyHandlerFactory bodyHandlerFactory; - - private final TCPNIOTransport clientTransport; private final AsyncHttpClientConfig clientConfig; private ConnectionManager connectionManager; private DelayedExecutor.Resolver resolver; private DelayedExecutor timeoutExecutor; + final TCPNIOTransport clientTransport; + // ------------------------------------------------------------ Constructors @@ -156,6 +157,7 @@ public void failed(final Throwable throwable) { @Override public void completed(final Connection c) { try { + touchConnection(c, request); execute(c, request, handler, future); } catch (Exception e) { failed(e); @@ -388,11 +390,16 @@ public void onTimeout(Connection connection) { nonSecure.remove(idx); ProxyAwareConnectorHandler.Builder chBuilder = ProxyAwareConnectorHandler.builder(clientTransport); - ProxyAwareConnectorHandler connectorHandler = - chBuilder.setAsyncHttpClientConfig(clientConfig) - .setNonSecureFilterChainTemplate(nonSecure) - .setSecureFilterChainTemplate(secure).build(); - connectionManager = new ConnectionManager(this, connectorHandler); + final ConnectionPool pool; + if (providerConfig != null) { + pool = (ConnectionPool) providerConfig.getProperty(CONNECTION_POOL); + } else { + pool = null; + } + connectionManager = new ConnectionManager(this, + pool, + secure, + nonSecure); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java index 8cd73ff1b4..dd1d940e55 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java @@ -72,7 +72,13 @@ public static enum Property { * but no negotiation of the protocol via NPN will occur. In short, this means * that this instance of AHC will only 'speak' SPDY - HTTP is effectively disabled. */ - NPN_ENABLED(Boolean.class, true); + NPN_ENABLED(Boolean.class, true), + + + /** + * Grizzly specific connection pool. + */ + CONNECTION_POOL(ConnectionPool.class, null); final Object defaultValue; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index 4f50229734..d5bd2081fb 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -31,11 +31,8 @@ final class ProxyAwareConnectorHandler extends TCPNIOConnectorHandler { private FilterChainBuilder nonSecureTemplate; private FilterChainBuilder secureTemplate; private AsyncHttpClientConfig clientConfig; - private static final ThreadLocal requestLocal = - new ThreadLocal(); - private static final ThreadLocal proxyLocal = - new ThreadLocal(); - + private Request request; + private ProxyServer proxyServer; // ------------------------------------------------------------ Constructors @@ -48,15 +45,13 @@ private ProxyAwareConnectorHandler(final TCPNIOTransport transport) { // ---------------------------------------------------------- Public Methods - public static void setRequest(final Request request) { + public void setRequest(final Request request) { assert(request != null); - requestLocal.set(request); + this.request = request; } - public static void setProxy(final ProxyServer proxyServer) { - if (proxyServer != null) { - proxyLocal.set(proxyServer); - } + public void setProxy(final ProxyServer proxyServer) { + this.proxyServer = proxyServer; } public static Builder builder(final TCPNIOTransport transport) { @@ -69,8 +64,6 @@ public static Builder builder(final TCPNIOTransport transport) { @Override public Processor getProcessor() { - final Request request = getRequestLocal(); - final ProxyServer proxyServer = getProxyLocal(); return ((proxyServer != null) ? createProxyFilterChain(request, proxyServer) : createFilterChain(request)); @@ -80,20 +73,6 @@ public Processor getProcessor() { // --------------------------------------------------------- Private Methods - private Request getRequestLocal() { - final Request request = requestLocal.get(); - requestLocal.remove(); - assert(request != null); - return request; - } - - private ProxyServer getProxyLocal() { - final ProxyServer proxyServer = proxyLocal.get(); - proxyLocal.remove(); - return proxyServer; - } - - private FilterChain createFilterChain(final Request request) { return isRequestSecure(request) ? secureTemplate.build() diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java index 79b30f3e52..529d4d9e22 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java @@ -28,6 +28,7 @@ import org.glassfish.grizzly.ssl.SSLFilter; import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLHandshakeException; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; @@ -78,11 +79,13 @@ public void completed(SSLEngine result) { @Override public void cancelled() { + HANDSHAKE_ERROR.set(c, new SSLHandshakeException("Handshake canceled.")); ctx.resume(); } @Override public void failed(Throwable throwable) { + HANDSHAKE_ERROR.set(c, throwable); ctx.resume(); } }); diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java index 665c91c435..5ed9e95bb2 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java @@ -33,7 +33,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Override - @Test + @Test(enabled=false) public void testMaxTotalConnectionsException() { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); try { @@ -101,7 +101,7 @@ public void destroy() { } } - @Test(groups = { "standalone", "default_provider" }) + @Test(groups = { "standalone", "default_provider" }, enabled=false) public void testInvalidConnectionsPool() { ConnectionsPool cp = new ConnectionsPool() { From 252e7bf13ab922a99bd2bf9b6d1564ce49f1a91f Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 1 Jul 2013 16:08:40 -0700 Subject: [PATCH 0003/2389] Remove test code. --- .../grizzly/GrizzlyAsyncHttpProvider.java | 45 ------------------- 1 file changed, 45 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index eef8bd492f..90aa060612 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -629,51 +629,6 @@ public static interface Cleanup { } - - // ======================================================================== - - public static void main(String[] args) { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder() - .setMaximumConnectionsTotal(-1) - .setMaximumConnectionsPerHost(4500) - .setCompressionEnabled(false) - .setAllowPoolingConnection(true /* keep-alive connection */) - // .setAllowPoolingConnection(false /* no keep-alive connection */) - .setConnectionTimeoutInMs(9000).setRequestTimeoutInMs(9000) - .setIdleConnectionInPoolTimeoutInMs(3000).build(); - - AsyncHttpClient client = - new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config); - - final int warmupRequests = 100000; - final String testUrl = "http://localhost:8080/"; - List> futures = - new ArrayList>(warmupRequests); - for (int i = 0; i < warmupRequests; i++) { - try { - futures.add(client.prepareGet(testUrl).addHeader("Req", Integer.toString(i)).execute()); - } catch (IOException e) { - System.err.println("Failed to execute get at iteration #" + i); - } - } - int counter = 0; - for (Future future : futures) { - counter++; - try { - future.get(); - System.out.println(counter + " complete"); - } catch (Exception e) { - System.err.println("Failed to execute get at iteration #" + counter); - e.printStackTrace(); - client.close(); - System.exit(1); - } - } - - System.out.println("Test complete..."); - client.close(); - } - } From 736f25763e9b3cf6bcc2d47e9462eadd0e862e70 Mon Sep 17 00:00:00 2001 From: Martin Korinth Date: Tue, 2 Jul 2013 16:07:16 +0200 Subject: [PATCH 0004/2389] Fixed a bug using proxies with the JDK API, found by DanielAdolfsson --- .../providers/jdk/JDKAsyncHttpProvider.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index c8d5ba32b0..c7a79c0dd4 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -173,12 +173,8 @@ private HttpURLConnection createUrlConnection(Request request) throws IOExceptio } } - HttpURLConnection urlConnection = null; - if (proxy == null) { - urlConnection = (HttpURLConnection) request.getURI().toURL().openConnection(Proxy.NO_PROXY); - } else { - urlConnection = (HttpURLConnection) proxyServer.getURI().toURL().openConnection(proxy); - } + HttpURLConnection urlConnection = (HttpURLConnection) + request.getURI().toURL().openConnection(proxy == null ? Proxy.NO_PROXY : proxy); if (request.getUrl().startsWith("https")) { HttpsURLConnection secure = (HttpsURLConnection) urlConnection; From 021aa7928e672bb7f6c3b980e7aa88461cf297fd Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 2 Jul 2013 10:50:16 -0700 Subject: [PATCH 0005/2389] Revert pool changes. --- .../async/MaxConnectionsInThreads.java | 2 +- .../async/MaxTotalConnectionTest.java | 2 +- providers/grizzly/pom.xml | 5 - .../providers/grizzly/ConnectionManager.java | 703 +++++++++++++++--- .../providers/grizzly/ConnectionPool.java | 38 - .../providers/grizzly/EventHandler.java | 12 +- .../grizzly/GrizzlyAsyncHttpProvider.java | 21 +- .../GrizzlyAsyncHttpProviderConfig.java | 8 +- .../grizzly/ProxyAwareConnectorHandler.java | 33 +- .../grizzly/filters/SwitchingSSLFilter.java | 3 - .../grizzly/GrizzlyConnectionPoolTest.java | 4 +- 11 files changed, 656 insertions(+), 175 deletions(-) delete mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java diff --git a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java index cb93ceb534..5ac600592d 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java @@ -43,7 +43,7 @@ abstract public class MaxConnectionsInThreads extends AbstractBasicTest { private static URI servletEndpointUri; - @Test(groups = { "online", "default_provider" }, enabled=false) + @Test(groups = { "online", "default_provider" }) public void testMaxConnectionsWithinThreads() { String[] urls = new String[] { servletEndpointUri.toString(), servletEndpointUri.toString() }; diff --git a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java index 392e5e219e..947d36c554 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java @@ -32,7 +32,7 @@ public abstract class MaxTotalConnectionTest extends AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); - @Test(groups = { "standalone", "default_provider" }, enabled=false) + @Test(groups = { "standalone", "default_provider" }) public void testMaxTotalConnectionsExceedingException() { String[] urls = new String[] { "http://google.com/", "http://github.com/" }; diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 57f9ed1821..54019dd401 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -29,11 +29,6 @@ grizzly-spdy ${grizzly.version} - - org.glassfish.grizzly - connection-pool - ${grizzly.version} - org.glassfish.grizzly grizzly-npn-api diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index e0b8ced221..fc09d42556 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -15,38 +15,54 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionPoolKeyStrategy; +import org.asynchttpclient.ConnectionsPool; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; +import org.asynchttpclient.util.ProxyUtils; +import org.glassfish.grizzly.CloseListener; +import org.glassfish.grizzly.CloseType; +import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; -import org.glassfish.grizzly.connectionpool.EndpointKey; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.IdleTimeoutFilter; +import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; +import java.util.Iterator; +import java.util.Map; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.asynchttpclient.util.DateUtil.millisTime; public class ConnectionManager { private static final Attribute DO_NOT_CACHE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(ConnectionManager.class.getName()); - private final ConnectionPool connectionPool; + private final ConnectionsPool pool; + private final ProxyAwareConnectorHandler connectionHandler; + private final ConnectionMonitor connectionMonitor; private final GrizzlyAsyncHttpProvider provider; - private final boolean canDestroyPool; - private final ConcurrentHashMap> endpointKeyMap = - new ConcurrentHashMap>(); - private final FilterChainBuilder secureBuilder; - private final FilterChainBuilder nonSecureBuilder; + private final boolean connectAsync; // ------------------------------------------------------------ Constructors @@ -54,28 +70,26 @@ public class ConnectionManager { @SuppressWarnings("unchecked") ConnectionManager(final GrizzlyAsyncHttpProvider provider, - final ConnectionPool connectionPool, - final FilterChainBuilder secureBuilder, - final FilterChainBuilder nonSecureBuilder) { - + final ProxyAwareConnectorHandler connectionHandler) { + ConnectionsPool connectionPool; this.provider = provider; final AsyncHttpClientConfig config = provider.getClientConfig(); - if (connectionPool != null) { - this.connectionPool = connectionPool; - canDestroyPool = false; + if (config.getAllowPoolingConnection()) { + ConnectionsPool pool = config.getConnectionsPool(); + if (pool != null) { + //noinspection unchecked + connectionPool = (ConnectionsPool) pool; + } else { + connectionPool = new Pool((config)); + } } else { - this.connectionPool = - new ConnectionPool(config.getMaxConnectionPerHost(), - config.getMaxTotalConnections(), - null, - config.getConnectionTimeoutInMs(), - config.getIdleConnectionInPoolTimeoutInMs(), - 2000); - canDestroyPool = true; + connectionPool = new NonCachingPool(); } - this.secureBuilder = secureBuilder; - this.nonSecureBuilder = nonSecureBuilder; + pool = connectionPool; + this.connectionHandler = connectionHandler; + connectionMonitor = new ConnectionMonitor(config.getMaxTotalConnections()); + connectAsync = provider.getClientConfig().isAsyncConnectMode(); } @@ -87,27 +101,26 @@ public void doTrackedConnection(final Request request, final GrizzlyResponseFuture requestFuture, final CompletionHandler connectHandler) throws IOException { - doAsyncConnect(request, requestFuture, connectHandler); -// Connection c = -// pool.poll(getPoolKey(request, requestFuture.getProxyServer())); -// if (c == null) { -// if (!connectionMonitor.acquire()) { -// throw new IOException("Max connections exceeded"); -// } -// if (connectAsync) { -// doAsyncConnect(request, requestFuture, connectHandler); -// } else { -// try { -// c = obtainConnection0(request, requestFuture); -// connectHandler.completed(c); -// } catch (Exception e) { -// connectHandler.failed(e); -// } -// } -// } else { -// provider.touchConnection(c, request); -// connectHandler.completed(c); -// } + Connection c = + pool.poll(getPoolKey(request, requestFuture.getProxyServer())); + if (c == null) { + if (!connectionMonitor.acquire()) { + throw new IOException("Max connections exceeded"); + } + if (connectAsync) { + doAsyncConnect(request, requestFuture, connectHandler); + } else { + try { + c = obtainConnection0(request, requestFuture); + connectHandler.completed(c); + } catch (Exception e) { + connectHandler.failed(e); + } + } + } else { + provider.touchConnection(c, request); + connectHandler.completed(c); + } } @@ -125,8 +138,21 @@ void doAsyncConnect(final Request request, final GrizzlyResponseFuture requestFuture, final CompletionHandler connectHandler) { + CompletionHandler ch = + createConnectionCompletionHandler(request, + requestFuture, + connectHandler); final ProxyServer proxyServer = requestFuture.getProxyServer(); - connectionPool.take(getEndPointKey(request, proxyServer), connectHandler); + ProxyAwareConnectorHandler.setRequest(request); + ProxyAwareConnectorHandler.setProxy(proxyServer); + SocketAddress address = getRemoteAddress(request, proxyServer); + if (request.getLocalAddress() != null) { + connectionHandler.connect(new InetSocketAddress(request.getLocalAddress(), 0), + address, + ch); + } else { + connectionHandler.connect(address, ch); + } } @@ -143,36 +169,6 @@ static boolean isConnectionCacheable(final Connection c) { return ((canCache != null) ? canCache : false); } - - // --------------------------------------------------------- Private Methods - - private EndpointKey getEndPointKey(final Request request, - final ProxyServer proxyServer) { - final String stringKey = getPoolKey(request, proxyServer); - EndpointKey key = endpointKeyMap.get(stringKey); - if (key == null) { - SocketAddress address = getRemoteAddress(request, proxyServer); - ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler - .builder(provider.clientTransport) - .setNonSecureFilterChainTemplate(nonSecureBuilder) - .setSecureFilterChainTemplate(secureBuilder) - .setAsyncHttpClientConfig(provider.getClientConfig()).build(); - EndpointKey localKey = - new EndpointKey(stringKey, - address, - handler); - EndpointKey result = - endpointKeyMap.putIfAbsent(stringKey, localKey); - if (result == null) { - key = localKey; - } - } - assert(key != null); - ((ProxyAwareConnectorHandler) key.getConnectorHandler()).setRequest(request); - ((ProxyAwareConnectorHandler) key.getConnectorHandler()).setProxy(proxyServer); - return key; - } - private SocketAddress getRemoteAddress(final Request request, final ProxyServer proxyServer) { final URI requestUri = request.getURI(); @@ -211,25 +207,22 @@ private Connection obtainConnection0(final Request request, createConnectionCompletionHandler(request, requestFuture, null)); final ProxyServer proxyServer = requestFuture.getProxyServer(); final SocketAddress address = getRemoteAddress(request, proxyServer); - ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler - .builder(provider.clientTransport) - .setNonSecureFilterChainTemplate(nonSecureBuilder) - .setSecureFilterChainTemplate(secureBuilder) - .setAsyncHttpClientConfig(provider.getClientConfig()).build(); - handler.setRequest(request); - handler.setProxy(proxyServer); + ProxyAwareConnectorHandler.setRequest(request); + ProxyAwareConnectorHandler.setProxy(proxyServer); if (cTimeout > 0) { - handler.connect(address, ch); + connectionHandler.connect(address, ch); return future.get(cTimeout, TimeUnit.MILLISECONDS); } else { - handler.connect(address, ch); + connectionHandler.connect(address, ch); return future.get(); } } - boolean returnConnection(final Connection c) { + boolean returnConnection(final Request request, final Connection c) { + ProxyServer proxyServer = ProxyUtils.getProxyServer( + provider.getClientConfig(), request); final boolean result = (DO_NOT_CACHE.get(c) == null - && connectionPool.release(c)); + && pool.offer(getPoolKey(request, proxyServer), c)); if (result) { if (provider.getResolver() != null) { provider.getResolver().setTimeoutMillis(c, IdleTimeoutFilter.FOREVER); @@ -240,11 +233,16 @@ boolean returnConnection(final Connection c) { } + boolean canReturnConnection(final Connection c) { + + return (DO_NOT_CACHE.get(c) != null || pool.canCacheConnection()); + + } + + void destroy() { - if (canDestroyPool) { - connectionPool.close(); - } + pool.destroy(); } @@ -272,7 +270,7 @@ public void completed(Connection connection) { future.setConnection(connection); provider.touchConnection(connection, request); if (wrappedHandler != null) { - //connection.addCloseListener(connectionMonitor); + connection.addCloseListener(connectionMonitor); wrappedHandler.completed(connection); } } @@ -291,4 +289,525 @@ private static String getPoolKey(final Request request, ProxyServer proxyServer) return keyStrategy.getKey(uri); } + + // ---------------------------------------------------------- Nested Classes + + + private static class ConnectionMonitor implements + CloseListener { + + private final Semaphore connections; + + + // -------------------------------------------------------- Constructors + + + ConnectionMonitor(final int maxConnections) { + if (maxConnections != -1) { + connections = new Semaphore(maxConnections); + } else { + connections = null; + } + } + + + // ------------------------------------------------------ Public Methods + + + public boolean acquire() { + + return (connections == null || connections.tryAcquire()); + + } + + + // ------------------------------- Methods from Connection.CloseListener + + + @Override + public void onClosed(Closeable closeable, CloseType closeType) throws IOException { + + if (connections != null) { + connections.release(); + } + + } + + } // END ConnectionMonitor + + + private static final class NonCachingPool implements ConnectionsPool { + + + // ---------------------------------------- Methods from ConnectionsPool + + + public boolean offer(String uri, Connection connection) { + return false; + } + + public Connection poll(String uri) { + return null; + } + + public boolean removeAll(Connection connection) { + return false; + } + + public boolean canCacheConnection() { + return true; + } + + public void destroy() { + // no-op + } + + } // END NonCachingPool + + /** + * {@link org.asynchttpclient.ConnectionsPool} implementation. + * + * @author The Grizzly Team + * @since 1.7.0 + */ + @SuppressWarnings("rawtypes") + public static class Pool implements ConnectionsPool { + + private final static Logger + LOG = LoggerFactory.getLogger(Pool.class); + + private final + ConcurrentHashMap + connectionsPool = + new ConcurrentHashMap(); + private final AtomicBoolean closed = new AtomicBoolean(false); + private final AtomicInteger totalCachedConnections = new AtomicInteger(0); + private final boolean cacheSSLConnections; + private final int maxConnectionsPerHost; + private final int maxConnections; + private final boolean unlimitedConnections; + private final long timeout; + private final long maxConnectionLifeTimeInMs; + private final DelayedExecutor delayedExecutor; + private final CloseListener listener; + + + // -------------------------------------------------------- Constructors + + + public Pool(final AsyncHttpClientConfig config) { + + cacheSSLConnections = config.isSslConnectionPoolEnabled(); + timeout = config.getIdleConnectionInPoolTimeoutInMs(); + maxConnectionLifeTimeInMs = config.getMaxConnectionLifeTimeInMs(); + maxConnectionsPerHost = config.getMaxConnectionPerHost(); + maxConnections = config.getMaxTotalConnections(); + unlimitedConnections = (maxConnections == -1); + delayedExecutor = new DelayedExecutor( + Executors.newSingleThreadExecutor()); + delayedExecutor.start(); + listener = new CloseListener() { + @Override + public void onClosed(Connection connection, CloseType closeType) throws IOException { + if (closeType == CloseType.REMOTELY) { + if (LOG.isInfoEnabled()) { + LOG.info("Remote closed connection ({}). Removing from cache", connection.toString()); + } + } + Pool.this.removeAll(connection); + } + }; + + } + + + // ---------------------------------------- Methods from ConnectionsPool + + + /** + * {@inheritDoc} + */ + public boolean offer(String uri, Connection connection) { + + if (cacheSSLConnections && Utils.isSecure(uri)) { + return false; + } + + DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); + if (conQueue == null) { + LOG.debug("Creating new Connection queue for uri [{}] and connection [{}]", + uri, connection); + DelayedExecutor.IdleConnectionQueue newPool = + delayedExecutor.createIdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); + conQueue = connectionsPool.putIfAbsent(uri, newPool); + if (conQueue == null) { + conQueue = newPool; + } + } + + final int size = conQueue.size(); + if (maxConnectionsPerHost == -1 || size < maxConnectionsPerHost) { + conQueue.offer(connection); + connection.addCloseListener(listener); + final int total = totalCachedConnections.incrementAndGet(); + if (LOG.isDebugEnabled()) { + LOG.debug("[offer] Pooling connection [{}] for uri [{}]. Current size (for host; before pooling): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", + connection, uri, size, maxConnectionsPerHost, total); + } + return true; + } + if (LOG.isDebugEnabled()) { + LOG.debug("[offer] Unable to pool connection [{}] for uri [{}]. Current size (for host): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", + connection, uri, size, maxConnectionsPerHost, totalCachedConnections.get()); + } + + return false; + } + + + /** + * {@inheritDoc} + */ + public Connection poll(String uri) { + + if (!cacheSSLConnections && Utils.isSecure(uri)) { + return null; + } + + Connection connection = null; + DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); + if (conQueue != null) { + boolean poolEmpty = false; + while (!poolEmpty && connection == null) { + if (!conQueue.isEmpty()) { + connection = conQueue.poll(); + } + + if (connection == null) { + poolEmpty = true; + } else if (!connection.isOpen()) { + removeAll(connection); + connection = null; + } + } + } else { + if (LOG.isDebugEnabled()) { + LOG.debug("[poll] No existing queue for uri [{}].", + new Object[]{uri}); + } + } + if (connection != null) { + if (LOG.isDebugEnabled()) { + LOG.debug("[poll] Found pooled connection [{}] for uri [{}].", + new Object[]{connection, uri}); + } + totalCachedConnections.decrementAndGet(); + connection.removeCloseListener(listener); + } + return connection; + + } + + + /** + * {@inheritDoc} + */ + public boolean removeAll(Connection connection) { + + if (connection == null || closed.get()) { + return false; + } + connection.removeCloseListener(listener); + boolean isRemoved = false; + for (Map.Entry entry : connectionsPool.entrySet()) { + boolean removed = entry.getValue().remove(connection); + isRemoved |= removed; + } + return isRemoved; + + } + + + /** + * {@inheritDoc} + */ + public boolean canCacheConnection() { + + return !(!closed.get() + && !unlimitedConnections + && totalCachedConnections.get() >= maxConnections); + + } + + /** + * {@inheritDoc} + */ + public void destroy() { + + if (closed.getAndSet(true)) { + return; + } + + for (Map.Entry entry : connectionsPool.entrySet()) { + entry.getValue().destroy(); + } + connectionsPool.clear(); + delayedExecutor.stop(); + delayedExecutor.getThreadPool().shutdownNow(); + + } + + + // ------------------------------------------------------ Nested Classes + + + private static final class DelayedExecutor { + + private static final long DEFAULT_CHECK_INTERVAL = 1000; + + public final static long UNSET_TIMEOUT = -1; + private final ExecutorService threadPool; + private final DelayedRunnable runnable = new DelayedRunnable(); + private final BlockingQueue queues = + DataStructures.getLTQInstance(IdleConnectionQueue.class); + private final Object sync = new Object(); + private volatile boolean isStarted; + private final long checkIntervalMs; + + + // ---------------------------------------------------- Constructors + + + private DelayedExecutor(final ExecutorService threadPool) { + this(threadPool, DEFAULT_CHECK_INTERVAL, TimeUnit.MILLISECONDS); + } + + + // ------------------------------------------------- Private Methods + + private DelayedExecutor(final ExecutorService threadPool, + final long checkInterval, + final TimeUnit timeunit) { + this.threadPool = threadPool; + this.checkIntervalMs = TimeUnit.MILLISECONDS.convert( + checkInterval, timeunit); + } + + private void start() { + synchronized (sync) { + if (!isStarted) { + isStarted = true; + threadPool.execute(runnable); + } + } + } + + private void stop() { + synchronized (sync) { + if (isStarted) { + isStarted = false; + sync.notify(); + } + } + } + + private ExecutorService getThreadPool() { + return threadPool; + } + + private IdleConnectionQueue createIdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { + final IdleConnectionQueue queue = new IdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); + queues.add(queue); + return queue; + } + + @SuppressWarnings({"NumberEquality"}) + private static boolean wasModified(final Long l1, final Long l2) { + return l1 != l2 && (l1 != null ? !l1.equals(l2) : !l2.equals(l1)); + } + + + // --------------------------------------------------- Inner Classes + + + private class DelayedRunnable implements Runnable { + + @Override + public void run() { + while (isStarted) { + final long currentTimeMs = millisTime(); + + for (final IdleConnectionQueue delayQueue : queues) { + if (delayQueue.queue.isEmpty()) continue; + + final TimeoutResolver resolver = delayQueue.resolver; + + for (Iterator it = delayQueue.queue.iterator(); it.hasNext(); ) { + final Connection element = (Connection) it.next(); + final Long timeoutMs = resolver.getTimeoutMs(element); + + if (timeoutMs == null || timeoutMs == UNSET_TIMEOUT) { + it.remove(); + if (wasModified(timeoutMs, + resolver.getTimeoutMs(element))) { + delayQueue.queue.offer(element); + } + } else if (currentTimeMs - timeoutMs >= 0) { + it.remove(); + if (wasModified(timeoutMs, + resolver.getTimeoutMs(element))) { + delayQueue.queue.offer(element); + } else { + try { + if (LOG.isDebugEnabled()) { + LOG.debug("Idle connection ({}) detected. Removing from cache.", element.toString()); + } + element.close().recycle(true); + } catch (Exception ignored) { + } + } + } + } + } + + synchronized (sync) { + if (!isStarted) return; + + try { + sync.wait(checkIntervalMs); + } catch (InterruptedException ignored) { + } + } + } + } + + } // END DelayedRunnable + + + final class IdleConnectionQueue { + final ConcurrentLinkedQueue queue = + new ConcurrentLinkedQueue(); + + + final TimeoutResolver resolver = new TimeoutResolver(); + final long timeout; + final AtomicInteger count = new AtomicInteger(0); + final long maxConnectionLifeTimeInMs; + + // ------------------------------------------------ Constructors + + + public IdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { + this.timeout = timeout; + this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; + } + + + // ------------------------------------- Package Private Methods + + + void offer(final Connection c) { + long timeoutMs = UNSET_TIMEOUT; + long currentTime = millisTime(); + if (maxConnectionLifeTimeInMs < 0 && timeout >= 0) { + timeoutMs = currentTime + timeout; + } else if (maxConnectionLifeTimeInMs >= 0) { + long t = resolver.getTimeoutMs(c); + if (t == UNSET_TIMEOUT) { + if (timeout >= 0) { + timeoutMs = currentTime + Math.min(maxConnectionLifeTimeInMs, timeout); + } else { + timeoutMs = currentTime + maxConnectionLifeTimeInMs; + } + } else { + if (timeout >= 0) { + timeoutMs = Math.min(t, currentTime + timeout); + } + } + } + resolver.setTimeoutMs(c, timeoutMs); + queue.offer(c); + count.incrementAndGet(); + } + + Connection poll() { + count.decrementAndGet(); + return queue.poll(); + } + + boolean remove(final Connection c) { + if (timeout >= 0) { + resolver.removeTimeout(c); + + } + count.decrementAndGet(); + return queue.remove(c); + } + + int size() { + return count.get(); + } + + boolean isEmpty() { + return (count.get() == 0); + } + + void destroy() { + for (Connection c : queue) { + c.close().recycle(true); + } + queue.clear(); + queues.remove(this); + } + + } // END IdleConnectionQueue + + + // -------------------------------------------------- Nested Classes + + + static final class TimeoutResolver { + + private static final String IDLE_ATTRIBUTE_NAME = "grizzly-ahc-conn-pool-idle-attribute"; + private static final Attribute IDLE_ATTR = + Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute( + IDLE_ATTRIBUTE_NAME, new NullaryFunction() { + + @Override + public IdleRecord evaluate() { + return new IdleRecord(); + } + }); + + + // --------------------------------------------- Private Methods + + + boolean removeTimeout(final Connection c) { + IDLE_ATTR.get(c).timeoutMs = 0; + return true; + } + + Long getTimeoutMs(final Connection c) { + return IDLE_ATTR.get(c).timeoutMs; + } + + void setTimeoutMs(final Connection c, final long timeoutMs) { + IDLE_ATTR.get(c).timeoutMs = timeoutMs; + } + + + // ---------------------------------------------- Nested Classes + + static final class IdleRecord { + + volatile long timeoutMs = UNSET_TIMEOUT; + + } // END IdleRecord + + } // END TimeoutResolver + + } // END DelayedExecutor + + } // END Pool } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java deleted file mode 100644 index a6e5316b2b..0000000000 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2013 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.grizzly; - -import org.glassfish.grizzly.connectionpool.MultiEndpointPool; -import org.glassfish.grizzly.utils.DelayedExecutor; - -import java.net.SocketAddress; - -public class ConnectionPool extends MultiEndpointPool{ - - - // ------------------------------------------------------------ Constructors - - - public ConnectionPool(final int maxConnectionsPerEndpoint, - final int maxConnectionsTotal, - final DelayedExecutor delayedExecutor, - final long connectTimeoutMillis, - final long keepAliveTimeoutMillis, - final long keepAliveCheckIntervalMillis) { - super(null, maxConnectionsPerEndpoint, - maxConnectionsTotal, delayedExecutor, connectTimeoutMillis, - keepAliveTimeoutMillis, keepAliveCheckIntervalMillis, -1, -1); - } - -} diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 46a6830ffd..7968087d30 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -472,14 +472,14 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx) { if (!Utils.isIgnored(ctx.getConnection())) { final ConnectionManager manager = context.getProvider().getConnectionManager(); - //if (!manager.canReturnConnection(c)) { - // context.abort( - // new IOException("Maximum pooled connections exceeded")); - //} else { - if (!manager.returnConnection(c)) { + if (!manager.canReturnConnection(c)) { + context.abort( + new IOException("Maximum pooled connections exceeded")); + } else { + if (!manager.returnConnection(context.getRequest(), c)) { ctx.getConnection().close(); } - //} + } } return context; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 90aa060612..9bfae788d3 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -87,7 +87,6 @@ import java.util.concurrent.TimeoutException; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property; -import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.CONNECTION_POOL; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.MAX_HTTP_PACKET_HEADER_SIZE; /** @@ -103,14 +102,14 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider { public final static NTLMEngine NTLM_ENGINE = new NTLMEngine(); private final BodyHandlerFactory bodyHandlerFactory; + + private final TCPNIOTransport clientTransport; private final AsyncHttpClientConfig clientConfig; private ConnectionManager connectionManager; private DelayedExecutor.Resolver resolver; private DelayedExecutor timeoutExecutor; - final TCPNIOTransport clientTransport; - // ------------------------------------------------------------ Constructors @@ -157,7 +156,6 @@ public void failed(final Throwable throwable) { @Override public void completed(final Connection c) { try { - touchConnection(c, request); execute(c, request, handler, future); } catch (Exception e) { failed(e); @@ -390,16 +388,11 @@ public void onTimeout(Connection connection) { nonSecure.remove(idx); ProxyAwareConnectorHandler.Builder chBuilder = ProxyAwareConnectorHandler.builder(clientTransport); - final ConnectionPool pool; - if (providerConfig != null) { - pool = (ConnectionPool) providerConfig.getProperty(CONNECTION_POOL); - } else { - pool = null; - } - connectionManager = new ConnectionManager(this, - pool, - secure, - nonSecure); + ProxyAwareConnectorHandler connectorHandler = + chBuilder.setAsyncHttpClientConfig(clientConfig) + .setNonSecureFilterChainTemplate(nonSecure) + .setSecureFilterChainTemplate(secure).build(); + connectionManager = new ConnectionManager(this, connectorHandler); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java index dd1d940e55..8cd73ff1b4 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java @@ -72,13 +72,7 @@ public static enum Property { * but no negotiation of the protocol via NPN will occur. In short, this means * that this instance of AHC will only 'speak' SPDY - HTTP is effectively disabled. */ - NPN_ENABLED(Boolean.class, true), - - - /** - * Grizzly specific connection pool. - */ - CONNECTION_POOL(ConnectionPool.class, null); + NPN_ENABLED(Boolean.class, true); final Object defaultValue; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index d5bd2081fb..4f50229734 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -31,8 +31,11 @@ final class ProxyAwareConnectorHandler extends TCPNIOConnectorHandler { private FilterChainBuilder nonSecureTemplate; private FilterChainBuilder secureTemplate; private AsyncHttpClientConfig clientConfig; - private Request request; - private ProxyServer proxyServer; + private static final ThreadLocal requestLocal = + new ThreadLocal(); + private static final ThreadLocal proxyLocal = + new ThreadLocal(); + // ------------------------------------------------------------ Constructors @@ -45,13 +48,15 @@ private ProxyAwareConnectorHandler(final TCPNIOTransport transport) { // ---------------------------------------------------------- Public Methods - public void setRequest(final Request request) { + public static void setRequest(final Request request) { assert(request != null); - this.request = request; + requestLocal.set(request); } - public void setProxy(final ProxyServer proxyServer) { - this.proxyServer = proxyServer; + public static void setProxy(final ProxyServer proxyServer) { + if (proxyServer != null) { + proxyLocal.set(proxyServer); + } } public static Builder builder(final TCPNIOTransport transport) { @@ -64,6 +69,8 @@ public static Builder builder(final TCPNIOTransport transport) { @Override public Processor getProcessor() { + final Request request = getRequestLocal(); + final ProxyServer proxyServer = getProxyLocal(); return ((proxyServer != null) ? createProxyFilterChain(request, proxyServer) : createFilterChain(request)); @@ -73,6 +80,20 @@ public Processor getProcessor() { // --------------------------------------------------------- Private Methods + private Request getRequestLocal() { + final Request request = requestLocal.get(); + requestLocal.remove(); + assert(request != null); + return request; + } + + private ProxyServer getProxyLocal() { + final ProxyServer proxyServer = proxyLocal.get(); + proxyLocal.remove(); + return proxyServer; + } + + private FilterChain createFilterChain(final Request request) { return isRequestSecure(request) ? secureTemplate.build() diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java index 529d4d9e22..79b30f3e52 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java @@ -28,7 +28,6 @@ import org.glassfish.grizzly.ssl.SSLFilter; import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLHandshakeException; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; @@ -79,13 +78,11 @@ public void completed(SSLEngine result) { @Override public void cancelled() { - HANDSHAKE_ERROR.set(c, new SSLHandshakeException("Handshake canceled.")); ctx.resume(); } @Override public void failed(Throwable throwable) { - HANDSHAKE_ERROR.set(c, throwable); ctx.resume(); } }); diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java index 5ed9e95bb2..665c91c435 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java @@ -33,7 +33,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Override - @Test(enabled=false) + @Test public void testMaxTotalConnectionsException() { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); try { @@ -101,7 +101,7 @@ public void destroy() { } } - @Test(groups = { "standalone", "default_provider" }, enabled=false) + @Test(groups = { "standalone", "default_provider" }) public void testInvalidConnectionsPool() { ConnectionsPool cp = new ConnectionsPool() { From 2a6bb313c118da5e0ebb30f2a02a9c1efdae3d94 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 2 Jul 2013 11:52:28 -0700 Subject: [PATCH 0006/2389] Fix secure pool logic. --- .../asynchttpclient/providers/grizzly/ConnectionManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index fc09d42556..1cf51cf97a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -429,7 +429,7 @@ public void onClosed(Connection connection, CloseType closeType) throws IOExcept */ public boolean offer(String uri, Connection connection) { - if (cacheSSLConnections && Utils.isSecure(uri)) { + if (Utils.isSecure(uri) && !cacheSSLConnections) { return false; } From d2f2d6fe46f1211d49bdfad83a7761655c2c9f92 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 3 Jul 2013 11:30:08 -0700 Subject: [PATCH 0007/2389] Re-integrate Grizzly connection pool changes. --- .../async/NoNullResponseTest.java | 4 +- providers/grizzly/pom.xml | 5 + .../providers/grizzly/ConnectionManager.java | 727 +++--------------- .../providers/grizzly/ConnectionPool.java | 84 ++ .../providers/grizzly/EventHandler.java | 12 +- .../grizzly/GrizzlyAsyncHttpProvider.java | 21 +- .../GrizzlyAsyncHttpProviderConfig.java | 8 +- .../grizzly/ProxyAwareConnectorHandler.java | 80 +- .../grizzly/filters/SwitchingSSLFilter.java | 96 ++- .../grizzly/filters/TunnelFilter.java | 81 +- .../grizzly/GrizzlyConnectionPoolTest.java | 4 +- .../GrizzlyMaxConnectionsInThreadsTest.java | 6 + 12 files changed, 367 insertions(+), 761 deletions(-) create mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java diff --git a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java index 9a6cf1bbc9..779373891b 100644 --- a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java @@ -31,13 +31,13 @@ import java.security.cert.X509Certificate; public abstract class NoNullResponseTest extends AbstractBasicTest { - private static final String VERISIGN_HTTPS_URL = "https://www.verisign.com/"; + private static final String GOOGLE_HTTPS_URL = "https://www.google.com/"; @Test(invocationCount = 4, groups = { "online", "default_provider" }) public void multipleSslRequestsWithDelayAndKeepAlive() throws Throwable { final AsyncHttpClient client = create(); try { - final BoundRequestBuilder builder = client.prepareGet(VERISIGN_HTTPS_URL); + final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); final Response response1 = builder.execute().get(); Thread.sleep(5000); final Response response2 = builder.execute().get(); diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 54019dd401..57f9ed1821 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -29,6 +29,11 @@ grizzly-spdy ${grizzly.version} + + org.glassfish.grizzly + connection-pool + ${grizzly.version} + org.glassfish.grizzly grizzly-npn-api diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 1cf51cf97a..08d7ce685d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -15,54 +15,42 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ConnectionsPool; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; -import org.asynchttpclient.util.ProxyUtils; -import org.glassfish.grizzly.CloseListener; -import org.glassfish.grizzly.CloseType; -import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.GrizzlyFuture; import org.glassfish.grizzly.attributes.Attribute; +import org.glassfish.grizzly.connectionpool.EndpointKey; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.impl.FutureImpl; -import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.IdleTimeoutFilter; -import org.glassfish.grizzly.utils.NullaryFunction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; -import java.util.Iterator; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import static org.asynchttpclient.util.DateUtil.millisTime; +import static java.util.concurrent.TimeUnit.MILLISECONDS; public class ConnectionManager { private static final Attribute DO_NOT_CACHE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(ConnectionManager.class.getName()); - private final ConnectionsPool pool; - private final ProxyAwareConnectorHandler connectionHandler; - private final ConnectionMonitor connectionMonitor; + private final ConnectionPool connectionPool; private final GrizzlyAsyncHttpProvider provider; - private final boolean connectAsync; + private final boolean canDestroyPool; + private final Map> endpointKeyMap = new HashMap>(); + private final FilterChainBuilder secureBuilder; + private final FilterChainBuilder nonSecureBuilder; + private final boolean asyncConnect; // ------------------------------------------------------------ Constructors @@ -70,26 +58,29 @@ public class ConnectionManager { @SuppressWarnings("unchecked") ConnectionManager(final GrizzlyAsyncHttpProvider provider, - final ProxyAwareConnectorHandler connectionHandler) { + final ConnectionPool connectionPool, + final FilterChainBuilder secureBuilder, + final FilterChainBuilder nonSecureBuilder) { + - ConnectionsPool connectionPool; this.provider = provider; final AsyncHttpClientConfig config = provider.getClientConfig(); - if (config.getAllowPoolingConnection()) { - ConnectionsPool pool = config.getConnectionsPool(); - if (pool != null) { - //noinspection unchecked - connectionPool = (ConnectionsPool) pool; - } else { - connectionPool = new Pool((config)); - } + if (connectionPool != null) { + this.connectionPool = connectionPool; + canDestroyPool = false; } else { - connectionPool = new NonCachingPool(); + this.connectionPool = + new ConnectionPool(config.getMaxConnectionPerHost(), + config.getMaxTotalConnections(), + null, + config.getConnectionTimeoutInMs(), + config.getIdleConnectionInPoolTimeoutInMs(), + 2000); + canDestroyPool = true; } - pool = connectionPool; - this.connectionHandler = connectionHandler; - connectionMonitor = new ConnectionMonitor(config.getMaxTotalConnections()); - connectAsync = provider.getClientConfig().isAsyncConnectMode(); + this.secureBuilder = secureBuilder; + this.nonSecureBuilder = nonSecureBuilder; + asyncConnect = config.isAsyncConnectMode(); } @@ -101,27 +92,34 @@ public void doTrackedConnection(final Request request, final GrizzlyResponseFuture requestFuture, final CompletionHandler connectHandler) throws IOException { - Connection c = - pool.poll(getPoolKey(request, requestFuture.getProxyServer())); - if (c == null) { - if (!connectionMonitor.acquire()) { - throw new IOException("Max connections exceeded"); - } - if (connectAsync) { - doAsyncConnect(request, requestFuture, connectHandler); - } else { - try { - c = obtainConnection0(request, requestFuture); - connectHandler.completed(c); - } catch (Exception e) { - connectHandler.failed(e); + final EndpointKey key = + getEndPointKey(request, requestFuture.getProxyServer()); + + if (asyncConnect) { + connectionPool.take(key, connectHandler); + } else { + IOException ioe = null; + GrizzlyFuture future = connectionPool.take(key); + try { + final int connTimeout = + provider.getClientConfig().getConnectionTimeoutInMs(); + connectHandler.completed(future.get(connTimeout, MILLISECONDS)); + } catch (CancellationException e) { + connectHandler.cancelled(); + } catch (ExecutionException ee) { + final Throwable cause = ee.getCause(); + if (cause instanceof ConnectionPool.MaxCapacityException) { + ioe = (IOException) cause; + } else { + connectHandler.failed(ee.getCause()); } + } catch (Exception ie) { + connectHandler.failed(ie); + } + if (ioe != null) { + throw ioe; } - } else { - provider.touchConnection(c, request); - connectHandler.completed(c); } - } public Connection obtainConnection(final Request request, @@ -134,29 +132,6 @@ public Connection obtainConnection(final Request request, } - void doAsyncConnect(final Request request, - final GrizzlyResponseFuture requestFuture, - final CompletionHandler connectHandler) { - - CompletionHandler ch = - createConnectionCompletionHandler(request, - requestFuture, - connectHandler); - final ProxyServer proxyServer = requestFuture.getProxyServer(); - ProxyAwareConnectorHandler.setRequest(request); - ProxyAwareConnectorHandler.setProxy(proxyServer); - SocketAddress address = getRemoteAddress(request, proxyServer); - if (request.getLocalAddress() != null) { - connectionHandler.connect(new InetSocketAddress(request.getLocalAddress(), 0), - address, - ch); - } else { - connectionHandler.connect(address, ch); - } - - } - - // --------------------------------------------------Package Private Methods @@ -169,6 +144,40 @@ static boolean isConnectionCacheable(final Connection c) { return ((canCache != null) ? canCache : false); } + + // --------------------------------------------------------- Private Methods + + private EndpointKey getEndPointKey(final Request request, + final ProxyServer proxyServer) { + final String stringKey = getPoolKey(request, proxyServer); + EndpointKey key = endpointKeyMap.get(stringKey); + if (key == null) { + synchronized (endpointKeyMap) { + key = endpointKeyMap.get(stringKey); + if (key == null) { + SocketAddress address = + getRemoteAddress(request, proxyServer); + ProxyAwareConnectorHandler handler = + ProxyAwareConnectorHandler + .builder(provider.clientTransport) + .setNonSecureFilterChainTemplate(nonSecureBuilder) + .setSecureFilterChainTemplate(secureBuilder) + .setAsyncHttpClientConfig(provider.getClientConfig()) + .setURI(request.getURI()) + .setProxyServer(proxyServer) + .build(); + EndpointKey localKey = + new EndpointKey(stringKey, + address, + handler); + endpointKeyMap.put(stringKey, localKey); + key = localKey; + } + } + } + return key; + } + private SocketAddress getRemoteAddress(final Request request, final ProxyServer proxyServer) { final URI requestUri = request.getURI(); @@ -207,22 +216,26 @@ private Connection obtainConnection0(final Request request, createConnectionCompletionHandler(request, requestFuture, null)); final ProxyServer proxyServer = requestFuture.getProxyServer(); final SocketAddress address = getRemoteAddress(request, proxyServer); - ProxyAwareConnectorHandler.setRequest(request); - ProxyAwareConnectorHandler.setProxy(proxyServer); + ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler + .builder(provider.clientTransport) + .setNonSecureFilterChainTemplate(nonSecureBuilder) + .setSecureFilterChainTemplate(secureBuilder) + .setAsyncHttpClientConfig(provider.getClientConfig()) + .setURI(request.getURI()) + .setProxyServer(proxyServer) + .build(); if (cTimeout > 0) { - connectionHandler.connect(address, ch); - return future.get(cTimeout, TimeUnit.MILLISECONDS); + handler.connect(address, ch); + return future.get(cTimeout, MILLISECONDS); } else { - connectionHandler.connect(address, ch); + handler.connect(address, ch); return future.get(); } } - boolean returnConnection(final Request request, final Connection c) { - ProxyServer proxyServer = ProxyUtils.getProxyServer( - provider.getClientConfig(), request); + boolean returnConnection(final Connection c) { final boolean result = (DO_NOT_CACHE.get(c) == null - && pool.offer(getPoolKey(request, proxyServer), c)); + && connectionPool.release(c)); if (result) { if (provider.getResolver() != null) { provider.getResolver().setTimeoutMillis(c, IdleTimeoutFilter.FOREVER); @@ -233,16 +246,11 @@ boolean returnConnection(final Request request, final Connection c) { } - boolean canReturnConnection(final Connection c) { - - return (DO_NOT_CACHE.get(c) != null || pool.canCacheConnection()); - - } - - void destroy() { - pool.destroy(); + if (canDestroyPool) { + connectionPool.close(); + } } @@ -270,7 +278,7 @@ public void completed(Connection connection) { future.setConnection(connection); provider.touchConnection(connection, request); if (wrappedHandler != null) { - connection.addCloseListener(connectionMonitor); + //connection.addCloseListener(connectionMonitor); wrappedHandler.completed(connection); } } @@ -285,529 +293,8 @@ public void updated(Connection result) { private static String getPoolKey(final Request request, ProxyServer proxyServer) { final ConnectionPoolKeyStrategy keyStrategy = request.getConnectionPoolKeyStrategy(); - URI uri = proxyServer != null? proxyServer.getURI(): request.getURI(); + URI uri = proxyServer != null ? proxyServer.getURI() : request.getURI(); return keyStrategy.getKey(uri); } - - // ---------------------------------------------------------- Nested Classes - - - private static class ConnectionMonitor implements - CloseListener { - - private final Semaphore connections; - - - // -------------------------------------------------------- Constructors - - - ConnectionMonitor(final int maxConnections) { - if (maxConnections != -1) { - connections = new Semaphore(maxConnections); - } else { - connections = null; - } - } - - - // ------------------------------------------------------ Public Methods - - - public boolean acquire() { - - return (connections == null || connections.tryAcquire()); - - } - - - // ------------------------------- Methods from Connection.CloseListener - - - @Override - public void onClosed(Closeable closeable, CloseType closeType) throws IOException { - - if (connections != null) { - connections.release(); - } - - } - - } // END ConnectionMonitor - - - private static final class NonCachingPool implements ConnectionsPool { - - - // ---------------------------------------- Methods from ConnectionsPool - - - public boolean offer(String uri, Connection connection) { - return false; - } - - public Connection poll(String uri) { - return null; - } - - public boolean removeAll(Connection connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - // no-op - } - - } // END NonCachingPool - - /** - * {@link org.asynchttpclient.ConnectionsPool} implementation. - * - * @author The Grizzly Team - * @since 1.7.0 - */ - @SuppressWarnings("rawtypes") - public static class Pool implements ConnectionsPool { - - private final static Logger - LOG = LoggerFactory.getLogger(Pool.class); - - private final - ConcurrentHashMap - connectionsPool = - new ConcurrentHashMap(); - private final AtomicBoolean closed = new AtomicBoolean(false); - private final AtomicInteger totalCachedConnections = new AtomicInteger(0); - private final boolean cacheSSLConnections; - private final int maxConnectionsPerHost; - private final int maxConnections; - private final boolean unlimitedConnections; - private final long timeout; - private final long maxConnectionLifeTimeInMs; - private final DelayedExecutor delayedExecutor; - private final CloseListener listener; - - - // -------------------------------------------------------- Constructors - - - public Pool(final AsyncHttpClientConfig config) { - - cacheSSLConnections = config.isSslConnectionPoolEnabled(); - timeout = config.getIdleConnectionInPoolTimeoutInMs(); - maxConnectionLifeTimeInMs = config.getMaxConnectionLifeTimeInMs(); - maxConnectionsPerHost = config.getMaxConnectionPerHost(); - maxConnections = config.getMaxTotalConnections(); - unlimitedConnections = (maxConnections == -1); - delayedExecutor = new DelayedExecutor( - Executors.newSingleThreadExecutor()); - delayedExecutor.start(); - listener = new CloseListener() { - @Override - public void onClosed(Connection connection, CloseType closeType) throws IOException { - if (closeType == CloseType.REMOTELY) { - if (LOG.isInfoEnabled()) { - LOG.info("Remote closed connection ({}). Removing from cache", connection.toString()); - } - } - Pool.this.removeAll(connection); - } - }; - - } - - - // ---------------------------------------- Methods from ConnectionsPool - - - /** - * {@inheritDoc} - */ - public boolean offer(String uri, Connection connection) { - - if (Utils.isSecure(uri) && !cacheSSLConnections) { - return false; - } - - DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); - if (conQueue == null) { - LOG.debug("Creating new Connection queue for uri [{}] and connection [{}]", - uri, connection); - DelayedExecutor.IdleConnectionQueue newPool = - delayedExecutor.createIdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); - conQueue = connectionsPool.putIfAbsent(uri, newPool); - if (conQueue == null) { - conQueue = newPool; - } - } - - final int size = conQueue.size(); - if (maxConnectionsPerHost == -1 || size < maxConnectionsPerHost) { - conQueue.offer(connection); - connection.addCloseListener(listener); - final int total = totalCachedConnections.incrementAndGet(); - if (LOG.isDebugEnabled()) { - LOG.debug("[offer] Pooling connection [{}] for uri [{}]. Current size (for host; before pooling): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", - connection, uri, size, maxConnectionsPerHost, total); - } - return true; - } - if (LOG.isDebugEnabled()) { - LOG.debug("[offer] Unable to pool connection [{}] for uri [{}]. Current size (for host): [{}]. Max size (for host): [{}]. Total number of cached connections: [{}].", - connection, uri, size, maxConnectionsPerHost, totalCachedConnections.get()); - } - - return false; - } - - - /** - * {@inheritDoc} - */ - public Connection poll(String uri) { - - if (!cacheSSLConnections && Utils.isSecure(uri)) { - return null; - } - - Connection connection = null; - DelayedExecutor.IdleConnectionQueue conQueue = connectionsPool.get(uri); - if (conQueue != null) { - boolean poolEmpty = false; - while (!poolEmpty && connection == null) { - if (!conQueue.isEmpty()) { - connection = conQueue.poll(); - } - - if (connection == null) { - poolEmpty = true; - } else if (!connection.isOpen()) { - removeAll(connection); - connection = null; - } - } - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("[poll] No existing queue for uri [{}].", - new Object[]{uri}); - } - } - if (connection != null) { - if (LOG.isDebugEnabled()) { - LOG.debug("[poll] Found pooled connection [{}] for uri [{}].", - new Object[]{connection, uri}); - } - totalCachedConnections.decrementAndGet(); - connection.removeCloseListener(listener); - } - return connection; - - } - - - /** - * {@inheritDoc} - */ - public boolean removeAll(Connection connection) { - - if (connection == null || closed.get()) { - return false; - } - connection.removeCloseListener(listener); - boolean isRemoved = false; - for (Map.Entry entry : connectionsPool.entrySet()) { - boolean removed = entry.getValue().remove(connection); - isRemoved |= removed; - } - return isRemoved; - - } - - - /** - * {@inheritDoc} - */ - public boolean canCacheConnection() { - - return !(!closed.get() - && !unlimitedConnections - && totalCachedConnections.get() >= maxConnections); - - } - - /** - * {@inheritDoc} - */ - public void destroy() { - - if (closed.getAndSet(true)) { - return; - } - - for (Map.Entry entry : connectionsPool.entrySet()) { - entry.getValue().destroy(); - } - connectionsPool.clear(); - delayedExecutor.stop(); - delayedExecutor.getThreadPool().shutdownNow(); - - } - - - // ------------------------------------------------------ Nested Classes - - - private static final class DelayedExecutor { - - private static final long DEFAULT_CHECK_INTERVAL = 1000; - - public final static long UNSET_TIMEOUT = -1; - private final ExecutorService threadPool; - private final DelayedRunnable runnable = new DelayedRunnable(); - private final BlockingQueue queues = - DataStructures.getLTQInstance(IdleConnectionQueue.class); - private final Object sync = new Object(); - private volatile boolean isStarted; - private final long checkIntervalMs; - - - // ---------------------------------------------------- Constructors - - - private DelayedExecutor(final ExecutorService threadPool) { - this(threadPool, DEFAULT_CHECK_INTERVAL, TimeUnit.MILLISECONDS); - } - - - // ------------------------------------------------- Private Methods - - private DelayedExecutor(final ExecutorService threadPool, - final long checkInterval, - final TimeUnit timeunit) { - this.threadPool = threadPool; - this.checkIntervalMs = TimeUnit.MILLISECONDS.convert( - checkInterval, timeunit); - } - - private void start() { - synchronized (sync) { - if (!isStarted) { - isStarted = true; - threadPool.execute(runnable); - } - } - } - - private void stop() { - synchronized (sync) { - if (isStarted) { - isStarted = false; - sync.notify(); - } - } - } - - private ExecutorService getThreadPool() { - return threadPool; - } - - private IdleConnectionQueue createIdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { - final IdleConnectionQueue queue = new IdleConnectionQueue(timeout, maxConnectionLifeTimeInMs); - queues.add(queue); - return queue; - } - - @SuppressWarnings({"NumberEquality"}) - private static boolean wasModified(final Long l1, final Long l2) { - return l1 != l2 && (l1 != null ? !l1.equals(l2) : !l2.equals(l1)); - } - - - // --------------------------------------------------- Inner Classes - - - private class DelayedRunnable implements Runnable { - - @Override - public void run() { - while (isStarted) { - final long currentTimeMs = millisTime(); - - for (final IdleConnectionQueue delayQueue : queues) { - if (delayQueue.queue.isEmpty()) continue; - - final TimeoutResolver resolver = delayQueue.resolver; - - for (Iterator it = delayQueue.queue.iterator(); it.hasNext(); ) { - final Connection element = (Connection) it.next(); - final Long timeoutMs = resolver.getTimeoutMs(element); - - if (timeoutMs == null || timeoutMs == UNSET_TIMEOUT) { - it.remove(); - if (wasModified(timeoutMs, - resolver.getTimeoutMs(element))) { - delayQueue.queue.offer(element); - } - } else if (currentTimeMs - timeoutMs >= 0) { - it.remove(); - if (wasModified(timeoutMs, - resolver.getTimeoutMs(element))) { - delayQueue.queue.offer(element); - } else { - try { - if (LOG.isDebugEnabled()) { - LOG.debug("Idle connection ({}) detected. Removing from cache.", element.toString()); - } - element.close().recycle(true); - } catch (Exception ignored) { - } - } - } - } - } - - synchronized (sync) { - if (!isStarted) return; - - try { - sync.wait(checkIntervalMs); - } catch (InterruptedException ignored) { - } - } - } - } - - } // END DelayedRunnable - - - final class IdleConnectionQueue { - final ConcurrentLinkedQueue queue = - new ConcurrentLinkedQueue(); - - - final TimeoutResolver resolver = new TimeoutResolver(); - final long timeout; - final AtomicInteger count = new AtomicInteger(0); - final long maxConnectionLifeTimeInMs; - - // ------------------------------------------------ Constructors - - - public IdleConnectionQueue(final long timeout, final long maxConnectionLifeTimeInMs) { - this.timeout = timeout; - this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; - } - - - // ------------------------------------- Package Private Methods - - - void offer(final Connection c) { - long timeoutMs = UNSET_TIMEOUT; - long currentTime = millisTime(); - if (maxConnectionLifeTimeInMs < 0 && timeout >= 0) { - timeoutMs = currentTime + timeout; - } else if (maxConnectionLifeTimeInMs >= 0) { - long t = resolver.getTimeoutMs(c); - if (t == UNSET_TIMEOUT) { - if (timeout >= 0) { - timeoutMs = currentTime + Math.min(maxConnectionLifeTimeInMs, timeout); - } else { - timeoutMs = currentTime + maxConnectionLifeTimeInMs; - } - } else { - if (timeout >= 0) { - timeoutMs = Math.min(t, currentTime + timeout); - } - } - } - resolver.setTimeoutMs(c, timeoutMs); - queue.offer(c); - count.incrementAndGet(); - } - - Connection poll() { - count.decrementAndGet(); - return queue.poll(); - } - - boolean remove(final Connection c) { - if (timeout >= 0) { - resolver.removeTimeout(c); - - } - count.decrementAndGet(); - return queue.remove(c); - } - - int size() { - return count.get(); - } - - boolean isEmpty() { - return (count.get() == 0); - } - - void destroy() { - for (Connection c : queue) { - c.close().recycle(true); - } - queue.clear(); - queues.remove(this); - } - - } // END IdleConnectionQueue - - - // -------------------------------------------------- Nested Classes - - - static final class TimeoutResolver { - - private static final String IDLE_ATTRIBUTE_NAME = "grizzly-ahc-conn-pool-idle-attribute"; - private static final Attribute IDLE_ATTR = - Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute( - IDLE_ATTRIBUTE_NAME, new NullaryFunction() { - - @Override - public IdleRecord evaluate() { - return new IdleRecord(); - } - }); - - - // --------------------------------------------- Private Methods - - - boolean removeTimeout(final Connection c) { - IDLE_ATTR.get(c).timeoutMs = 0; - return true; - } - - Long getTimeoutMs(final Connection c) { - return IDLE_ATTR.get(c).timeoutMs; - } - - void setTimeoutMs(final Connection c, final long timeoutMs) { - IDLE_ATTR.get(c).timeoutMs = timeoutMs; - } - - - // ---------------------------------------------- Nested Classes - - static final class IdleRecord { - - volatile long timeoutMs = UNSET_TIMEOUT; - - } // END IdleRecord - - } // END TimeoutResolver - - } // END DelayedExecutor - - } // END Pool } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java new file mode 100644 index 0000000000..dae88f302e --- /dev/null +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2013 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.grizzly; + +import org.glassfish.grizzly.connectionpool.EndpointKey; +import org.glassfish.grizzly.connectionpool.MultiEndpointPool; +import org.glassfish.grizzly.connectionpool.SingleEndpointPool; +import org.glassfish.grizzly.utils.DelayedExecutor; + +import java.io.IOException; +import java.net.SocketAddress; + +/** + * Extension of standard Grizzly {@link MultiEndpointPool}. + * + * @since 2.0 + * @author The Grizzly Team + */ +public class ConnectionPool extends MultiEndpointPool{ + + + // ------------------------------------------------------------ Constructors + + + public ConnectionPool(final int maxConnectionsPerEndpoint, + final int maxConnectionsTotal, + final DelayedExecutor delayedExecutor, + final long connectTimeoutMillis, + final long keepAliveTimeoutMillis, + final long keepAliveCheckIntervalMillis) { + super(null, maxConnectionsPerEndpoint, + maxConnectionsTotal, delayedExecutor, connectTimeoutMillis, + keepAliveTimeoutMillis, keepAliveCheckIntervalMillis, -1, -1); + } + + + // ------------------------------------------ Methods from MultiEndpointPool + + + protected SingleEndpointPool obtainSingleEndpointPool( + final EndpointKey endpointKey) throws IOException { + SingleEndpointPool sePool = + endpointToPoolMap.get(endpointKey); + if (sePool == null) { + synchronized (poolSync) { + checkNotClosed(); + if (isMaxCapacityReached()) { + throw new MaxCapacityException(); + } + sePool = endpointToPoolMap.get(endpointKey); + if (sePool == null) { + sePool = createSingleEndpointPool(endpointKey); + endpointToPoolMap.put(endpointKey, sePool); + } + } + } + + return sePool; + } + + + // ---------------------------------------------------------- Nested Classes + + + public static final class MaxCapacityException extends IOException { + + public MaxCapacityException() { + super("Maximum pool capacity has been reached"); + } + + } + +} diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 7968087d30..46a6830ffd 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -472,14 +472,14 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx) { if (!Utils.isIgnored(ctx.getConnection())) { final ConnectionManager manager = context.getProvider().getConnectionManager(); - if (!manager.canReturnConnection(c)) { - context.abort( - new IOException("Maximum pooled connections exceeded")); - } else { - if (!manager.returnConnection(context.getRequest(), c)) { + //if (!manager.canReturnConnection(c)) { + // context.abort( + // new IOException("Maximum pooled connections exceeded")); + //} else { + if (!manager.returnConnection(c)) { ctx.getConnection().close(); } - } + //} } return context; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 9bfae788d3..90aa060612 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -87,6 +87,7 @@ import java.util.concurrent.TimeoutException; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property; +import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.CONNECTION_POOL; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.MAX_HTTP_PACKET_HEADER_SIZE; /** @@ -102,14 +103,14 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider { public final static NTLMEngine NTLM_ENGINE = new NTLMEngine(); private final BodyHandlerFactory bodyHandlerFactory; - - private final TCPNIOTransport clientTransport; private final AsyncHttpClientConfig clientConfig; private ConnectionManager connectionManager; private DelayedExecutor.Resolver resolver; private DelayedExecutor timeoutExecutor; + final TCPNIOTransport clientTransport; + // ------------------------------------------------------------ Constructors @@ -156,6 +157,7 @@ public void failed(final Throwable throwable) { @Override public void completed(final Connection c) { try { + touchConnection(c, request); execute(c, request, handler, future); } catch (Exception e) { failed(e); @@ -388,11 +390,16 @@ public void onTimeout(Connection connection) { nonSecure.remove(idx); ProxyAwareConnectorHandler.Builder chBuilder = ProxyAwareConnectorHandler.builder(clientTransport); - ProxyAwareConnectorHandler connectorHandler = - chBuilder.setAsyncHttpClientConfig(clientConfig) - .setNonSecureFilterChainTemplate(nonSecure) - .setSecureFilterChainTemplate(secure).build(); - connectionManager = new ConnectionManager(this, connectorHandler); + final ConnectionPool pool; + if (providerConfig != null) { + pool = (ConnectionPool) providerConfig.getProperty(CONNECTION_POOL); + } else { + pool = null; + } + connectionManager = new ConnectionManager(this, + pool, + secure, + nonSecure); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java index 8cd73ff1b4..dd1d940e55 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProviderConfig.java @@ -72,7 +72,13 @@ public static enum Property { * but no negotiation of the protocol via NPN will occur. In short, this means * that this instance of AHC will only 'speak' SPDY - HTTP is effectively disabled. */ - NPN_ENABLED(Boolean.class, true); + NPN_ENABLED(Boolean.class, true), + + + /** + * Grizzly specific connection pool. + */ + CONNECTION_POOL(ConnectionPool.class, null); final Object defaultValue; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index 4f50229734..7d9744ce1b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -15,7 +15,6 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.filters.ProxyFilter; import org.asynchttpclient.providers.grizzly.filters.TunnelFilter; import org.glassfish.grizzly.Processor; @@ -25,17 +24,16 @@ import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import java.net.URI; + final class ProxyAwareConnectorHandler extends TCPNIOConnectorHandler { private FilterChainBuilder nonSecureTemplate; private FilterChainBuilder secureTemplate; private AsyncHttpClientConfig clientConfig; - private static final ThreadLocal requestLocal = - new ThreadLocal(); - private static final ThreadLocal proxyLocal = - new ThreadLocal(); - + private URI uri; + private ProxyServer proxyServer; // ------------------------------------------------------------ Constructors @@ -48,17 +46,6 @@ private ProxyAwareConnectorHandler(final TCPNIOTransport transport) { // ---------------------------------------------------------- Public Methods - public static void setRequest(final Request request) { - assert(request != null); - requestLocal.set(request); - } - - public static void setProxy(final ProxyServer proxyServer) { - if (proxyServer != null) { - proxyLocal.set(proxyServer); - } - } - public static Builder builder(final TCPNIOTransport transport) { return new ProxyAwareConnectorHandler.Builder(transport); } @@ -69,67 +56,41 @@ public static Builder builder(final TCPNIOTransport transport) { @Override public Processor getProcessor() { - final Request request = getRequestLocal(); - final ProxyServer proxyServer = getProxyLocal(); return ((proxyServer != null) - ? createProxyFilterChain(request, proxyServer) - : createFilterChain(request)); + ? createProxyFilterChain() + : createFilterChain()); } // --------------------------------------------------------- Private Methods - private Request getRequestLocal() { - final Request request = requestLocal.get(); - requestLocal.remove(); - assert(request != null); - return request; - } - - private ProxyServer getProxyLocal() { - final ProxyServer proxyServer = proxyLocal.get(); - proxyLocal.remove(); - return proxyServer; - } - - - private FilterChain createFilterChain(final Request request) { - return isRequestSecure(request) + private FilterChain createFilterChain() { + return Utils.isSecure(uri) ? secureTemplate.build() : nonSecureTemplate.build(); } - private FilterChain createProxyFilterChain(final Request request, - final ProxyServer proxyServer) { + private FilterChain createProxyFilterChain() { final FilterChainBuilder builder = FilterChainBuilder.stateless(); - if (isRequestSecure(request)) { + if (Utils.isSecure(uri)) { builder.addAll(secureTemplate); - updateSecureFilterChain(builder, request, proxyServer); + updateSecureFilterChain(builder); } else { builder.addAll(nonSecureTemplate); - updateNonSecureFilterChain(builder, proxyServer); + updateNonSecureFilterChain(builder); } return builder.build(); } - private static boolean isRequestSecure(final Request request) { - final String p = request.getURI().getScheme(); - return p.equals("https") || p.equals("wss"); - } - - private void updateSecureFilterChain(final FilterChainBuilder builder, - final Request request, - final ProxyServer proxyServer) { - builder.add(1, new TunnelFilter(proxyServer, - request.getURI())); // Insert after the the transport filter + private void updateSecureFilterChain(final FilterChainBuilder builder) { + builder.add(1, new TunnelFilter(proxyServer, uri)); final int idx = builder.indexOfType(HttpClientFilter.class); assert (idx != -1); builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, true)); } - private void updateNonSecureFilterChain(final FilterChainBuilder builder, - final ProxyServer proxyServer) { + private void updateNonSecureFilterChain(final FilterChainBuilder builder) { final int idx = builder.indexOfType(HttpClientFilter.class); assert (idx != -1); builder.add(idx + 1, new ProxyFilter(proxyServer, clientConfig, false)); @@ -171,11 +132,22 @@ public Builder setAsyncHttpClientConfig(final AsyncHttpClientConfig clientConfig return this; } + public Builder setURI(final URI uri) { + connectorHandler.uri = uri; + return this; + } + + public Builder setProxyServer(final ProxyServer proxyServer) { + connectorHandler.proxyServer = proxyServer; + return this; + } + @Override public ProxyAwareConnectorHandler build() { assert(connectorHandler.secureTemplate != null); assert(connectorHandler.nonSecureTemplate != null); assert(connectorHandler.clientConfig != null); + assert(connectorHandler.uri != null); return connectorHandler; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java index 79b30f3e52..a5700b10a6 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/SwitchingSSLFilter.java @@ -13,7 +13,6 @@ package org.asynchttpclient.providers.grizzly.filters; -import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.filters.events.SSLSwitchingEvent; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.EmptyCompletionHandler; @@ -28,16 +27,22 @@ import org.glassfish.grizzly.ssl.SSLFilter; import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLHandshakeException; import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; +/** + * SSL Filter that may be present within the FilterChain and may be + * enabled/disabled by sending the appropriate {@link SSLSwitchingEvent}. + * + * @since 2.0 + * @author The Grizzly Team + */ public final class SwitchingSSLFilter extends SSLFilter { private static final Attribute CONNECTION_IS_SECURE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(SwitchingSSLFilter.class.getName()); - private static final Attribute HANDSHAKING = - Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(SwitchingSSLFilter.class.getName() + "-HANDSHAKING"); private static final Attribute HANDSHAKE_ERROR = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(SwitchingSSLFilter.class.getName() + "-HANDSHAKE-ERROR"); @@ -57,41 +62,56 @@ public SwitchingSSLFilter(final SSLEngineConfigurator clientConfig) { @Override protected void notifyHandshakeFailed(Connection connection, Throwable t) { - if (GrizzlyAsyncHttpProvider.LOGGER.isErrorEnabled()) { - GrizzlyAsyncHttpProvider.LOGGER.error("Unable to complete handshake with peer.", t); - } - HANDSHAKE_ERROR.set(connection, t); + setError(connection, t); } @Override public NextAction handleConnect(final FilterChainContext ctx) throws IOException { + // Suspend further handleConnect processing. We do this to ensure that + // the SSL handshake has been completed before returning the connection + // for use in processing user requests. Additionally, this allows us + // to determine if a connection is SPDY or HTTP as early as possible. ctx.suspend(); final Connection c = ctx.getConnection(); - if (HANDSHAKING.get(c) == null) { - HANDSHAKING.set(c, Boolean.TRUE); - handshake(ctx.getConnection(), - new EmptyCompletionHandler() { - @Override - public void completed(SSLEngine result) { - ctx.resume(); - } - - @Override - public void cancelled() { - ctx.resume(); - } - - @Override - public void failed(Throwable throwable) { - ctx.resume(); - } - }); - ctx.getConnection().enableIOEvent(IOEvent.READ); - return ctx.getSuspendAction(); - } else { - HANDSHAKING.remove(c); - return ctx.getInvokeAction(); - } + handshake(ctx.getConnection(), + new EmptyCompletionHandler() { + @Override + public void completed(SSLEngine result) { + // Handshake was successful. Resume the handleConnect + // processing. We pass in Invoke Action so the filter + // chain will call handleConnect on the next filter. + ctx.resume(ctx.getInvokeAction()); + } + + @Override + public void cancelled() { + // Handshake was cancelled. Stop the handleConnect + // processing. The exception will be checked and + // passed to the user later. + setError(c, new SSLHandshakeException( + "Handshake canceled.")); + ctx.resume(ctx.getStopAction()); + } + + @Override + public void failed(Throwable throwable) { + // Handshake failed. Stop the handleConnect + // processing. The exception will be checked and + // passed to the user later. + setError(c, throwable); + ctx.resume(ctx.getStopAction()); + } + }); + + // This typically isn't advised, however, we need to be able to + // read the response from the proxy and OP_READ isn't typically + // enabled on the connection until all of the handleConnect() + // processing is complete. + enableRead(c); + + // Tell the FilterChain that we're suspending further handleConnect + // processing. + return ctx.getSuspendAction(); } @Override @@ -141,15 +161,23 @@ public static Throwable getHandshakeError(final Connection c) { // --------------------------------------------------------- Private Methods - private boolean isSecure(final Connection c) { + private static boolean isSecure(final Connection c) { Boolean secStatus = CONNECTION_IS_SECURE.get(c); return (secStatus == null ? true : secStatus); } - private void setSecureStatus(final Connection c, final boolean secure) { + private static void setSecureStatus(final Connection c, final boolean secure) { CONNECTION_IS_SECURE.set(c, secure); } + private static void setError(final Connection c, Throwable t) { + HANDSHAKE_ERROR.set(c, t); + } + + private static void enableRead(final Connection c) throws IOException { + c.enableIOEvent(IOEvent.READ); + } + // ---------------------------------------------------------- Nested Classes diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java index 8854a00579..4e4bd57bbc 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/TunnelFilter.java @@ -16,10 +16,7 @@ import org.asynchttpclient.ProxyServer; import org.asynchttpclient.providers.grizzly.Utils; import org.asynchttpclient.providers.grizzly.filters.events.TunnelRequestEvent; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.IOEvent; -import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.FilterChainEvent; @@ -30,20 +27,18 @@ /** * This Filter is responsible for HTTP CONNECT - * tunnelling when a connection should be secure and done via - * proxy. + * tunnelling when a connection should be secure and required to + * go through a proxy. * * @since 2.0 * @author The Grizzly Team */ public final class TunnelFilter extends BaseFilter { - private static final Attribute TUNNEL_IN_PROGRESS = - Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(TunnelFilter.class.getName()); - private final ProxyServer proxyServer; private final URI uri; + // ------------------------------------------------------------ Constructors @@ -55,22 +50,38 @@ public TunnelFilter(final ProxyServer proxyServer, final URI uri) { // ----------------------------------------------------- Methods from Filter + @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (TUNNEL_IN_PROGRESS.get(ctx.getConnection()) == null) { - TUNNEL_IN_PROGRESS.set(ctx.getConnection(), Boolean.TRUE); - ctx.suspend(); - Utils.connectionIgnored(ctx.getConnection(), true); - final TunnelRequestEvent tunnelRequestEvent = - new TunnelRequestEvent(ctx, proxyServer, uri); - ctx.notifyUpstream(tunnelRequestEvent); - ctx.getConnection().enableIOEvent(IOEvent.READ); - return ctx.getSuspendAction(); - } else { - TUNNEL_IN_PROGRESS.remove(ctx.getConnection()); - return ctx.getInvokeAction(); - } + // We suspend the FilterChainContext here to prevent + // notification of other filters of the connection event. + // This allows us to control when the connection is returned + // to the user - we ensure that the tunnel is properly established + // before the user request is sent. + ctx.suspend(); + + // This connection is special and shouldn't be tracked. + Utils.connectionIgnored(ctx.getConnection(), true); + + // This event will be handled by the AsyncHttpClientFilter. + // It will send the CONNECT request and process the response. + // When tunnel is complete, the AsyncHttpClientFilter will + // send this event back to this filter in order to notify + // it that the request processing is complete. + final TunnelRequestEvent tunnelRequestEvent = + new TunnelRequestEvent(ctx, proxyServer, uri); + ctx.notifyUpstream(tunnelRequestEvent); + + // This typically isn't advised, however, we need to be able to + // read the response from the proxy and OP_READ isn't typically + // enabled on the connection until all of the handleConnect() + // processing is complete. + ctx.getConnection().enableIOEvent(IOEvent.READ); + + // Tell the FilterChain that we're suspending further handleConnect + // processing. + return ctx.getSuspendAction(); } @Override @@ -78,22 +89,22 @@ public NextAction handleEvent(FilterChainContext ctx, FilterChainEvent event) throws IOException { if (event.type() == TunnelRequestEvent.class) { TunnelRequestEvent tunnelRequestEvent = (TunnelRequestEvent) event; - if (tunnelInProgress(ctx.getConnection())) { - Utils.connectionIgnored(ctx.getConnection(), false); - FilterChainContext suspendedContext = tunnelRequestEvent.getSuspendedContext(); - suspendedContext.resume(); - } - ctx.getStopAction(); - } - return ctx.getInvokeAction(); - } - - // ---------------------------------------------------------- Public Methods + // Clear ignore status. Any further use of the connection will + // be bound by normal AHC connection processing. + Utils.connectionIgnored(ctx.getConnection(), false); + // Obtain the context that was previously suspended and resume. + // We pass in Invoke Action so the filter chain will call + // handleConnect on the next filter. + FilterChainContext suspendedContext = + tunnelRequestEvent.getSuspendedContext(); + suspendedContext.resume(ctx.getInvokeAction()); - private static boolean tunnelInProgress(final Connection connection) { - return (TUNNEL_IN_PROGRESS.get(connection) != null); + // Stop further event processing. + ctx.getStopAction(); + } + return ctx.getInvokeAction(); } -} // END TunnelFilter +} diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java index 665c91c435..5ed9e95bb2 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java @@ -33,7 +33,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Override - @Test + @Test(enabled=false) public void testMaxTotalConnectionsException() { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); try { @@ -101,7 +101,7 @@ public void destroy() { } } - @Test(groups = { "standalone", "default_provider" }) + @Test(groups = { "standalone", "default_provider" }, enabled=false) public void testInvalidConnectionsPool() { ConnectionsPool cp = new ConnectionsPool() { diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyMaxConnectionsInThreadsTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyMaxConnectionsInThreadsTest.java index f40f8567e5..70872b6a61 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyMaxConnectionsInThreadsTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyMaxConnectionsInThreadsTest.java @@ -16,6 +16,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.MaxConnectionsInThreads; +import org.testng.annotations.Test; public class GrizzlyMaxConnectionsInThreadsTest extends MaxConnectionsInThreads { @@ -24,4 +25,9 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } + @Override + @Test(enabled=false) + public void testMaxConnectionsWithinThreads() { + super.testMaxConnectionsWithinThreads(); + } } From 3a2eafe9bb3f0c0bf61515330bf645dc555ab280 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 3 Jul 2013 11:38:14 -0700 Subject: [PATCH 0008/2389] Update blocking connection call. Remove timing from get() call as the pool implementation will take care of it for us. --- .../providers/grizzly/ConnectionManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 08d7ce685d..88a6f16d01 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -101,9 +101,10 @@ public void doTrackedConnection(final Request request, IOException ioe = null; GrizzlyFuture future = connectionPool.take(key); try { - final int connTimeout = - provider.getClientConfig().getConnectionTimeoutInMs(); - connectHandler.completed(future.get(connTimeout, MILLISECONDS)); + // No explicit timeout when calling get() here as the Grizzly + // endpoint pool will time it out based on the connect timeout + // setting. + connectHandler.completed(future.get()); } catch (CancellationException e) { connectHandler.cancelled(); } catch (ExecutionException ee) { From 62833523d4c6c4975ae757f99684a54f0cc3ceb8 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 5 Jul 2013 10:30:35 -0700 Subject: [PATCH 0009/2389] Add class docs for events that had no documentation. --- .../providers/grizzly/filters/events/ContinueEvent.java | 7 ++++++- .../grizzly/filters/events/SSLSwitchingEvent.java | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java index 2d90f2abe5..247bed46fa 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java @@ -13,10 +13,15 @@ package org.asynchttpclient.providers.grizzly.filters.events; -import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.HttpTransactionContext; import org.glassfish.grizzly.filterchain.FilterChainEvent; +/** + * {@link FilterChainEvent} to trigger HTTP 100-Continue processing. + * + * @since 2.0 + * @author The Grizzly Team + */ public final class ContinueEvent implements FilterChainEvent { private final HttpTransactionContext context; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java index 55eeb2dc9b..84ae75f26c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java @@ -18,6 +18,13 @@ import java.util.concurrent.Callable; +/** + * {@link FilterChainEvent} to dynamically enable/disable the SSLFilter on + * a per-connection basis. + * + * @since 2.0 + * @author The Grizzly Team + */ public final class SSLSwitchingEvent implements FilterChainEvent { private final boolean secure; From f699b286a8931865a424a082a2cb2f162440b7d8 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 5 Jul 2013 10:39:25 -0700 Subject: [PATCH 0010/2389] More docs. --- .../grizzly/filters/AsyncHttpClientEventFilter.java | 7 +++++++ .../providers/grizzly/filters/AsyncHttpClientFilter.java | 8 ++++++++ .../grizzly/filters/AsyncHttpClientTransportFilter.java | 7 +++++++ .../grizzly/filters/AsyncSpdyClientEventFilter.java | 7 +++++++ .../providers/grizzly/filters/ClientEncodingFilter.java | 6 ++++++ 5 files changed, 35 insertions(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java index b58fa36fbe..8b2aa0783d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java @@ -23,6 +23,13 @@ import java.io.IOException; +/** + * Extension of the {@link HttpClientFilter} that is responsible for handling + * events triggered by the parsing and serialization of HTTP packets. + * + * @since 2.0 + * @author The Grizzly Team + */ public final class AsyncHttpClientEventFilter extends HttpClientFilter implements GrizzlyAsyncHttpProvider.Cleanup { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 4133c566b0..d48869b7a2 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -67,6 +67,14 @@ import static org.asynchttpclient.util.AsyncHttpProviderUtils.getAuthority; import static org.asynchttpclient.util.MiscUtil.isNonEmpty; +/** + * This {@link org.glassfish.grizzly.filterchain.Filter} is typically the last + * in the {@FilterChain}. Its primary responsibility is converting the + * async-http-client {@link Request} into a Grizzly {@link HttpRequestPacket}. + * + * @since 1.7 + * @author The Grizzly Team + */ public final class AsyncHttpClientFilter extends BaseFilter { private ConcurrentLinkedQueue requestCache diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java index 6fd7c36f5d..8de7d91554 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java @@ -22,6 +22,13 @@ import java.io.EOFException; import java.io.IOException; +/** + * Custom {@link TransportFilter} implementation to capture and handle low-level + * exceptions. + * + * @since 1.7 + * @author The Grizzly Team + */ public final class AsyncHttpClientTransportFilter extends TransportFilter { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncSpdyClientEventFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncSpdyClientEventFilter.java index 21e3d4e28f..e4741c4bb3 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncSpdyClientEventFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncSpdyClientEventFilter.java @@ -24,6 +24,13 @@ import java.io.IOException; import java.util.concurrent.ExecutorService; +/** + * Extension of the {@link SpdyHandlerFilter} that is responsible for handling + * events triggered by the parsing and serialization of HTTP packets. + * + * @since 2.0 + * @author The Grizzly Team + */ public final class AsyncSpdyClientEventFilter extends SpdyHandlerFilter implements GrizzlyAsyncHttpProvider.Cleanup { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java index c080203b01..095d6c64b4 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java @@ -19,6 +19,12 @@ import org.glassfish.grizzly.http.util.DataChunk; import org.glassfish.grizzly.http.util.Header; +/** + * {@link EncodingFilter} to enable gzip encoding. + * + * @since 1.7 + * @author The Grizzly Team + */ public final class ClientEncodingFilter implements EncodingFilter { From 8b5ca63d835ccbff1aad6ff5295a129a7624de0e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 8 Jul 2013 11:33:07 -0700 Subject: [PATCH 0011/2389] Re-enable local address binding (required api changes on the Grizzly side). --- .../providers/grizzly/ConnectionManager.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 88a6f16d01..51fc80a169 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -29,6 +29,7 @@ import org.glassfish.grizzly.utils.IdleTimeoutFilter; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; @@ -158,6 +159,11 @@ private EndpointKey getEndPointKey(final Request request, if (key == null) { SocketAddress address = getRemoteAddress(request, proxyServer); + InetAddress localAddress = request.getLocalAddress(); + InetSocketAddress localSocketAddress = null; + if (localAddress != null) { + localSocketAddress = new InetSocketAddress(localAddress.getHostName(), 0); + } ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler .builder(provider.clientTransport) @@ -169,8 +175,9 @@ private EndpointKey getEndPointKey(final Request request, .build(); EndpointKey localKey = new EndpointKey(stringKey, - address, - handler); + address, + localSocketAddress, + handler); endpointKeyMap.put(stringKey, localKey); key = localKey; } From 67e9bc793ad3881d3dfb845e41f6b08365da5046 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 8 Jul 2013 11:48:21 -0700 Subject: [PATCH 0012/2389] Remove dead local variable. Cleanup imports. --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 90aa060612..b334fb4266 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -14,7 +14,6 @@ package org.asynchttpclient.providers.grizzly; import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProvider; import org.asynchttpclient.HttpResponseBodyPart; @@ -78,11 +77,9 @@ import javax.net.ssl.SSLEngine; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -388,8 +385,6 @@ public void onTimeout(Connection connection) { nonSecure.addAll(secure); int idx = nonSecure.indexOfType(SSLFilter.class); nonSecure.remove(idx); - ProxyAwareConnectorHandler.Builder chBuilder = - ProxyAwareConnectorHandler.builder(clientTransport); final ConnectionPool pool; if (providerConfig != null) { pool = (ConnectionPool) providerConfig.getProperty(CONNECTION_POOL); From 57dea9261685a261042d87cbcece62016ee6d08b Mon Sep 17 00:00:00 2001 From: Mark Greene Date: Wed, 10 Jul 2013 11:28:42 -0400 Subject: [PATCH 0013/2389] Bumping guava to latest version. This was needed in order to utilize their RateLimiter class. --- extras/guava/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/guava/pom.xml b/extras/guava/pom.xml index f43c6c950c..c759c8ebe6 100644 --- a/extras/guava/pom.xml +++ b/extras/guava/pom.xml @@ -17,7 +17,7 @@ com.google.guava guava - 11.0.2 + 14.0.1 \ No newline at end of file From 3424407949618d822a5e608f551d8fb07face98c Mon Sep 17 00:00:00 2001 From: Mark Greene Date: Wed, 10 Jul 2013 11:29:41 -0400 Subject: [PATCH 0014/2389] Refactor out AsyncHandlerWrapper into its own class so it can be reused. Also cleaned up the ThrottleRequestFilter a bit to remove class level members that were not needed. --- .../extra/AsyncHandlerWrapper.java | 73 +++++++++ .../extra/ThrottleRequestFilter.java | 152 +++++------------- 2 files changed, 113 insertions(+), 112 deletions(-) create mode 100644 api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java diff --git a/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java b/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java new file mode 100644 index 0000000000..fcbce72bc4 --- /dev/null +++ b/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java @@ -0,0 +1,73 @@ +package org.asynchttpclient.extra; + +import java.util.concurrent.Semaphore; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AsyncHandlerWrapper implements AsyncHandler { + + private final static Logger logger = LoggerFactory.getLogger(AsyncHandlerWrapper.class); + private final AsyncHandler asyncHandler; + private final Semaphore available; + + public AsyncHandlerWrapper(AsyncHandler asyncHandler, Semaphore available) { + this.asyncHandler = asyncHandler; + this.available = available; + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public void onThrowable(Throwable t) { + try { + asyncHandler.onThrowable(t); + } finally { + available.release(); + if (logger.isDebugEnabled()) { + logger.debug("Current Throttling Status after onThrowable {}", available.availablePermits()); + } + } + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { + return asyncHandler.onBodyPartReceived(bodyPart); + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception { + return asyncHandler.onStatusReceived(responseStatus); + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { + return asyncHandler.onHeadersReceived(headers); + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public T onCompleted() throws Exception { + available.release(); + if (logger.isDebugEnabled()) { + logger.debug("Current Throttling Status {}", available.availablePermits()); + } + return asyncHandler.onCompleted(); + } +} \ No newline at end of file diff --git a/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java b/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java index 7676dfb037..2dcb6087e2 100644 --- a/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java +++ b/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java @@ -12,126 +12,54 @@ */ package org.asynchttpclient.extra; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.RequestFilter; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.RequestFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - /** * A {@link org.asynchttpclient.filter.RequestFilter} throttles requests and block when the number of permits is reached, waiting for * the response to arrives before executing the next request. */ public class ThrottleRequestFilter implements RequestFilter { - private final static Logger logger = LoggerFactory.getLogger(ThrottleRequestFilter.class); - @SuppressWarnings("unused") - private final int maxConnections; - private final Semaphore available; - private final int maxWait; - - public ThrottleRequestFilter(int maxConnections) { - this.maxConnections = maxConnections; - this.maxWait = Integer.MAX_VALUE; - available = new Semaphore(maxConnections, true); - } - - public ThrottleRequestFilter(int maxConnections, int maxWait) { - this.maxConnections = maxConnections; - this.maxWait = maxWait; - available = new Semaphore(maxConnections, true); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public FilterContext filter(FilterContext ctx) throws FilterException { - - try { - if (logger.isDebugEnabled()) { - logger.debug("Current Throttling Status {}", available.availablePermits()); - } - if (!available.tryAcquire(maxWait, TimeUnit.MILLISECONDS)) { - throw new FilterException( - String.format("No slot available for processing Request %s with AsyncHandler %s", - ctx.getRequest(), ctx.getAsyncHandler())); - } - ; - } catch (InterruptedException e) { - throw new FilterException( - String.format("Interrupted Request %s with AsyncHandler %s", ctx.getRequest(), ctx.getAsyncHandler())); - } - - return new FilterContext.FilterContextBuilder(ctx).asyncHandler(new AsyncHandlerWrapper(ctx.getAsyncHandler())).build(); - } - - private class AsyncHandlerWrapper implements AsyncHandler { - - private final AsyncHandler asyncHandler; - - public AsyncHandlerWrapper(AsyncHandler asyncHandler) { - this.asyncHandler = asyncHandler; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public void onThrowable(Throwable t) { - try { - asyncHandler.onThrowable(t); - } finally { - available.release(); - if (logger.isDebugEnabled()) { - logger.debug("Current Throttling Status after onThrowable {}", available.availablePermits()); - } - } - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { - return asyncHandler.onBodyPartReceived(bodyPart); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception { - return asyncHandler.onStatusReceived(responseStatus); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { - return asyncHandler.onHeadersReceived(headers); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public T onCompleted() throws Exception { - available.release(); - if (logger.isDebugEnabled()) { - logger.debug("Current Throttling Status {}", available.availablePermits()); - } - return asyncHandler.onCompleted(); - } - } -} + private final static Logger logger = LoggerFactory.getLogger(ThrottleRequestFilter.class); + private final Semaphore available; + private final int maxWait; + + public ThrottleRequestFilter(int maxConnections) { + this(maxConnections, Integer.MAX_VALUE); + } + + public ThrottleRequestFilter(int maxConnections, int maxWait) { + this.maxWait = maxWait; + available = new Semaphore(maxConnections, true); + } + + /** + * {@inheritDoc} + */ + /* @Override */ + public FilterContext filter(FilterContext ctx) throws FilterException { + + try { + if (logger.isDebugEnabled()) { + logger.debug("Current Throttling Status {}", available.availablePermits()); + } + if (!available.tryAcquire(maxWait, TimeUnit.MILLISECONDS)) { + throw new FilterException(String.format( + "No slot available for processing Request %s with AsyncHandler %s", ctx.getRequest(), + ctx.getAsyncHandler())); + } + } catch (InterruptedException e) { + throw new FilterException(String.format("Interrupted Request %s with AsyncHandler %s", ctx.getRequest(), + ctx.getAsyncHandler())); + } + + return new FilterContext.FilterContextBuilder(ctx).asyncHandler( + new AsyncHandlerWrapper(ctx.getAsyncHandler(), available)).build(); + } +} \ No newline at end of file From 358a58ed6e6bb9e4cbb29d8336458ceec60a253c Mon Sep 17 00:00:00 2001 From: Mark Greene Date: Wed, 10 Jul 2013 11:30:12 -0400 Subject: [PATCH 0015/2389] New rate limited request filter, which also utilizes the concurrency limiting found in the ThrottledRequestFilter --- .../RateLimitedThrottleRequestFilter.java | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 extras/guava/src/main/java/org/asynchttpclient/extra/RateLimitedThrottleRequestFilter.java diff --git a/extras/guava/src/main/java/org/asynchttpclient/extra/RateLimitedThrottleRequestFilter.java b/extras/guava/src/main/java/org/asynchttpclient/extra/RateLimitedThrottleRequestFilter.java new file mode 100644 index 0000000000..c9b8759276 --- /dev/null +++ b/extras/guava/src/main/java/org/asynchttpclient/extra/RateLimitedThrottleRequestFilter.java @@ -0,0 +1,95 @@ +package org.asynchttpclient.extra; + +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.RequestFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.util.concurrent.RateLimiter; + +/** + * A {@link org.asynchttpclient.filter.RequestFilter} that extends the capability of + * {@link ThrottleRequestFilter} by allowing rate limiting per second in addition to the + * number of concurrent connections. + * + * The maxWaitMs argument is respected accross both permit acquistions. For + * example, if 1000 ms is given, and the filter spends 500 ms waiting for a connection, + * it will only spend another 500 ms waiting for the rate limiter. + */ +public class RateLimitedThrottleRequestFilter implements RequestFilter { + private final static Logger logger = LoggerFactory.getLogger(RateLimitedThrottleRequestFilter.class); + private final Semaphore available; + private final int maxWaitMs; + private final RateLimiter rateLimiter; + + public RateLimitedThrottleRequestFilter(int maxConnections, double rateLimitPerSecond) { + this(maxConnections, rateLimitPerSecond, Integer.MAX_VALUE); + } + + public RateLimitedThrottleRequestFilter(int maxConnections, double rateLimitPerSecond, int maxWaitMs) { + this.maxWaitMs = maxWaitMs; + this.rateLimiter = RateLimiter.create(rateLimitPerSecond); + available = new Semaphore(maxConnections, true); + } + + /** + * {@inheritDoc} + */ + @Override + public FilterContext filter(FilterContext ctx) throws FilterException { + try { + if (logger.isDebugEnabled()) { + logger.debug("Current Throttling Status {}", available.availablePermits()); + } + + long startOfWait = System.currentTimeMillis(); + attemptConcurrencyPermitAcquistion(ctx); + + attemptRateLimitedPermitAcquistion(ctx, startOfWait); + } catch (InterruptedException e) { + throw new FilterException(String.format("Interrupted Request %s with AsyncHandler %s", ctx.getRequest(), + ctx.getAsyncHandler())); + } + + return new FilterContext.FilterContextBuilder(ctx).asyncHandler( + new AsyncHandlerWrapper(ctx.getAsyncHandler(), available)).build(); + } + + private void attemptRateLimitedPermitAcquistion(FilterContext ctx, long startOfWait) throws FilterException { + long wait = getMillisRemainingInMaxWait(startOfWait); + + if (!rateLimiter.tryAcquire(wait, TimeUnit.MILLISECONDS)) { + throw new FilterException(String.format( + "Wait for rate limit exceeded during processing Request %s with AsyncHandler %s", ctx.getRequest(), + ctx.getAsyncHandler())); + } + } + + private void attemptConcurrencyPermitAcquistion(FilterContext ctx) throws InterruptedException, + FilterException { + if (!available.tryAcquire(maxWaitMs, TimeUnit.MILLISECONDS)) { + throw new FilterException(String.format("No slot available for processing Request %s with AsyncHandler %s", + ctx.getRequest(), ctx.getAsyncHandler())); + } + } + + private long getMillisRemainingInMaxWait(long startOfWait) { + int MINUTE_IN_MILLIS = 60000; + long durationLeft = maxWaitMs - (System.currentTimeMillis() - startOfWait); + long nonNegativeDuration = Math.max(durationLeft, 0); + + // have to reduce the duration because there is a boundary case inside the Guava + // rate limiter where if the duration to wait is near Long.MAX_VALUE, the rate + // limiter's internal calculations can exceed Long.MAX_VALUE resulting in a + // negative number which causes the tryAcquire() method to fail unexpectedly + if (Long.MAX_VALUE - nonNegativeDuration < MINUTE_IN_MILLIS) { + return nonNegativeDuration - MINUTE_IN_MILLIS; + } + + return nonNegativeDuration; + } +} \ No newline at end of file From 75c9d228cf9d15c168e3f9f3388a310acf5661d1 Mon Sep 17 00:00:00 2001 From: markchadwick Date: Thu, 11 Jul 2013 17:11:20 -0400 Subject: [PATCH 0016/2389] Fix Markedown code escape quote in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 94ee3268d8..047711c227 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Future f = asyncHttpClient.prepareGet("http://www.ning.com/").execute( Response r = f.get(); ``` -Note that in this case all the content must be read fully in memory, even if you used `getResponseBodyAsStream()' method on returned `Response` object. +Note that in this case all the content must be read fully in memory, even if you used `getResponseBodyAsStream()` method on returned `Response` object. You can also accomplish asynchronous (non-blocking) operation without using a Future if you want to receive and process the response in your handler: From eba9fd46d7792c5f13d52eb03e572a4da39aaed5 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 13:53:58 +0200 Subject: [PATCH 0017/2389] Bump Grizzly 2.3.4 --- providers/grizzly/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 57f9ed1821..796aa9ca6e 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -14,7 +14,7 @@ - 2.3.4-SNAPSHOT + 2.3.4 1.0 From 9fe73bea90c8ce3913bf61fe6a9435f835647771 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:11:42 +0200 Subject: [PATCH 0018/2389] Minor clean up, use constants --- .../netty/NettyAsyncHttpProvider.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index f2bdb14c1e..f38bd6194d 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -139,7 +139,6 @@ import static org.jboss.netty.channel.Channels.pipeline; public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler implements AsyncHttpProvider { - private final static String WEBSOCKET_KEY = "Sec-WebSocket-Key"; private final static String HTTP_HANDLER = "httpHandler"; protected final static String SSL_HANDLER = "sslHandler"; private final static String HTTPS = "https"; @@ -498,8 +497,8 @@ public void operationComplete(ChannelFuture cf) { * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements. */ if (future.getRequest().getParts() != null) { - String contentType = future.getNettyRequest().getHeader("Content-Type"); - String length = future.getNettyRequest().getHeader("Content-Length"); + String contentType = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_TYPE); + String length = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_LENGTH); body = new MultipartBody(future.getRequest().getParts(), contentType, length); } @@ -603,9 +602,9 @@ else if (uri.getRawQuery() != null) if (webSocket) { nettyRequest.addHeader(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET); nettyRequest.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); - nettyRequest.addHeader("Origin", "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort())); - nettyRequest.addHeader(WEBSOCKET_KEY, WebSocketUtil.getKey()); - nettyRequest.addHeader("Sec-WebSocket-Version", "13"); + nettyRequest.addHeader(HttpHeaders.Names.ORIGIN, "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort())); + nettyRequest.addHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY, WebSocketUtil.getKey()); + nettyRequest.addHeader(HttpHeaders.Names.SEC_WEBSOCKET_VERSION, "13"); } if (host != null) { @@ -724,16 +723,16 @@ else if (uri.getRawQuery() != null) } // Add default accept headers. - if (request.getHeaders().getFirstValue("Accept") == null) { + if (request.getHeaders().getFirstValue(HttpHeaders.Names.ACCEPT) == null) { nettyRequest.setHeader(HttpHeaders.Names.ACCEPT, "*/*"); } - if (request.getHeaders().getFirstValue("User-Agent") != null) { - nettyRequest.setHeader("User-Agent", request.getHeaders().getFirstValue("User-Agent")); + if (request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT) != null) { + nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT)); } else if (config.getUserAgent() != null) { - nettyRequest.setHeader("User-Agent", config.getUserAgent()); + nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, config.getUserAgent()); } else { - nettyRequest.setHeader("User-Agent", AsyncHttpProviderUtils.constructUserAgent(NettyAsyncHttpProvider.class, config)); + nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, AsyncHttpProviderUtils.constructUserAgent(NettyAsyncHttpProvider.class, config)); } if (!m.equals(HttpMethod.CONNECT)) { @@ -780,7 +779,7 @@ else if (uri.getRawQuery() != null) nettyRequest.setContent(ChannelBuffers.wrappedBuffer(sb.toString().getBytes(bodyCharset))); if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded"); + nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); } } else if (request.getParts() != null) { @@ -1600,7 +1599,7 @@ public static NettyResponseFuture newFuture(URI uri, Request request, Asy request.getConnectionPoolKeyStrategy(),// proxyServer); - if (request.getHeaders().getFirstValue("Expect") != null && request.getHeaders().getFirstValue("Expect").equalsIgnoreCase("100-Continue")) { + if (request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT) != null && request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT).equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) { f.getAndSetWriteBody(false); } return f; @@ -2260,7 +2259,7 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { final boolean validUpgrade = response.getHeader(HttpHeaders.Names.UPGRADE) != null; String c = response.getHeader(HttpHeaders.Names.CONNECTION); if (c == null) { - c = response.getHeader("connection"); + c = response.getHeader(HttpHeaders.Names.CONNECTION.toLowerCase()); } final boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); @@ -2274,8 +2273,8 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { return; } - String accept = response.getHeader("Sec-WebSocket-Accept"); - String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().getHeader(WEBSOCKET_KEY)); + String accept = response.getHeader(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT); + String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().getHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY)); if (accept == null || !accept.equals(key)) { throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); } From 8c07dc998420b08698e8c0e3839a8d36a28d7baa Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:14:01 +0200 Subject: [PATCH 0019/2389] Remove useless multiple getFirstValue calls, close #341 --- .../asynchttpclient/resumable/ResumableAsyncHandler.java | 5 +++-- .../providers/netty/NettyAsyncHttpProvider.java | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java index 3200f54862..ec3a4f17e7 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java @@ -178,8 +178,9 @@ public Response onCompleted() throws Exception { /* @Override */ public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); - if (headers.getHeaders().getFirstValue("Content-Length") != null) { - contentLength = Integer.valueOf(headers.getHeaders().getFirstValue("Content-Length")); + String contentLengthHeader = headers.getHeaders().getFirstValue("Content-Length"); + if (contentLengthHeader != null) { + contentLength = Integer.valueOf(contentLengthHeader); if (contentLength == null || contentLength == -1) { return AsyncHandler.STATE.ABORT; } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index f38bd6194d..bbb82880f4 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -727,8 +727,9 @@ else if (uri.getRawQuery() != null) nettyRequest.setHeader(HttpHeaders.Names.ACCEPT, "*/*"); } - if (request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT) != null) { - nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT)); + String userAgentHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT); + if (userAgentHeader != null) { + nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, userAgentHeader); } else if (config.getUserAgent() != null) { nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, config.getUserAgent()); } else { @@ -1599,7 +1600,8 @@ public static NettyResponseFuture newFuture(URI uri, Request request, Asy request.getConnectionPoolKeyStrategy(),// proxyServer); - if (request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT) != null && request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT).equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) { + String expectHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT); + if (expectHeader != null && expectHeader.equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) { f.getAndSetWriteBody(false); } return f; From 3fd63d0f5dbb1b93cb3c355b4e8b046ea041559a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:21:11 +0200 Subject: [PATCH 0020/2389] Fix Netty provider NTLM type 2 message handling, close #339 --- .../netty/NettyAsyncHttpProvider.java | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index bbb82880f4..8ec3ca44e2 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -181,6 +181,10 @@ public boolean remove(Object o) { private final Protocol httpProtocol = new HttpProtocol(); private final Protocol webSocketProtocol = new WebSocketProtocol(); + private static boolean isNTLM(List auth) { + return isNonEmpty(auth) && auth.get(0).startsWith("NTLM"); + } + public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { if (config.getAsyncHttpProviderConfig() != null && NettyAsyncHttpProviderConfig.class.isAssignableFrom(config.getAsyncHttpProviderConfig().getClass())) { @@ -632,7 +636,7 @@ else if (uri.getRawQuery() != null) } } else { List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (isNonEmpty(auth) && auth.get(0).startsWith("NTLM")) { + if (isNTLM(auth)) { nettyRequest.addHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, auth.get(0)); } } @@ -706,7 +710,7 @@ else if (uri.getRawQuery() != null) if (isNonEmpty(proxyServer.getNtlmDomain())) { List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (!(isNonEmpty(auth) && auth.get(0).startsWith("NTLM"))) { + if (!isNTLM(auth)) { try { String msg = ntlmEngine.generateType1Msg(proxyServer.getNtlmDomain(), proxyServer.getHost()); nettyRequest.setHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + msg); @@ -1133,7 +1137,7 @@ private Realm kerberosChallenge(List proxyAuth, Request request, ProxySe } return realmBuilder.setUri(uri.getRawPath()).setMethodName(request.getMethod()).setScheme(Realm.AuthScheme.KERBEROS).build(); } catch (Throwable throwable) { - if (proxyAuth.contains("NTLM")) { + if (isNTLM(proxyAuth)) { return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); } abort(future, throwable); @@ -1141,6 +1145,18 @@ private Realm kerberosChallenge(List proxyAuth, Request request, ProxySe } } + private void addType3NTLMAuthorizationHeader(List auth, FluentCaseInsensitiveStringsMap headers, String username, String password, String domain, String workstation) + throws NTLMEngineException { + headers.remove(HttpHeaders.Names.AUTHORIZATION); + + if (isNTLM(auth)) { + String serverChallenge = auth.get(0).trim().substring("NTLM ".length()); + String challengeHeader = ntlmEngine.generateType3Msg(username, password, domain, workstation, serverChallenge); + + headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); + } + } + private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, NettyResponseFuture future) throws NTLMEngineException { boolean useRealm = (proxyServer == null && realm != null); @@ -1159,14 +1175,7 @@ private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer p newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(uri.getRawPath()).setMethodName(request.getMethod()).setNtlmMessageType2Received(true).build(); future.getAndSetAuth(false); } else { - headers.remove(HttpHeaders.Names.AUTHORIZATION); - - if (wwwAuth.get(0).startsWith("NTLM ")) { - String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = ntlmEngine.generateType3Msg(principal, password, ntlmDomain, ntlmHost, serverChallenge); - - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - } + addType3NTLMAuthorizationHeader(wwwAuth, headers, principal, password, ntlmDomain, ntlmHost); Realm.RealmBuilder realmBuilder; Realm.AuthScheme authScheme; @@ -1187,11 +1196,8 @@ private Realm ntlmProxyChallenge(List wwwAuth, Request request, ProxySer future.getAndSetAuth(false); headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (wwwAuth.get(0).startsWith("NTLM ")) { - String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = ntlmEngine.generateType3Msg(proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost(), serverChallenge); - headers.add(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + challengeHeader); - } + addType3NTLMAuthorizationHeader(wwwAuth, headers, proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost()); + Realm newRealm; Realm.RealmBuilder realmBuilder; if (realm != null) { @@ -2052,7 +2058,7 @@ public void handle(final ChannelHandlerContext ctx, final MessageEvent e) throws future.setState(NettyResponseFuture.STATE.NEW); // NTLM - if (!wwwAuth.contains("Kerberos") && (wwwAuth.contains("NTLM") || (wwwAuth.contains("Negotiate")))) { + if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || (wwwAuth.contains("Negotiate")))) { newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); // SPNEGO KERBEROS } else if (wwwAuth.contains("Negotiate")) { @@ -2097,7 +2103,7 @@ public Object call() throws Exception { future.setState(NettyResponseFuture.STATE.NEW); - if (!proxyAuth.contains("Kerberos") && (proxyAuth.get(0).contains("NTLM") || (proxyAuth.contains("Negotiate")))) { + if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || (proxyAuth.contains("Negotiate")))) { newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); // SPNEGO KERBEROS } else if (proxyAuth.contains("Negotiate")) { From fbfe32772bf18d851f195a99ee2a01081e0d97a9 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:27:55 +0200 Subject: [PATCH 0021/2389] Use isEmpty instead of comparing size/length, close #343 --- .../listener/TransferCompletionHandler.java | 2 +- .../providers/netty/NettyAsyncHttpProvider.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index 59703c2587..833387cad7 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -146,7 +146,7 @@ public Response onCompleted(Response response) throws Exception { */ public STATE onHeaderWriteCompleted() { List list = transferAdapter.getHeaders().get("Content-Length"); - if (isNonEmpty(list) && list.get(0).length() != 0) { + if (isNonEmpty(list) && !list.get(0).isEmpty()) { totalBytesToTransfer.set(Long.valueOf(list.get(0))); } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 8ec3ca44e2..078982c990 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -1337,7 +1337,7 @@ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); future.touch(); - if (config.getIOExceptionFilters().size() > 0) { + if (!config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); fc = handleIoException(fc, future); @@ -1471,7 +1471,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws if (IOException.class.isAssignableFrom(cause.getClass())) { - if (config.getIOExceptionFilters().size() > 0) { + if (!config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); fc = handleIoException(fc, future); @@ -2054,7 +2054,7 @@ public void handle(final ChannelHandlerContext ctx, final MessageEvent e) throws // builder.setUrl(future.getURI().toString()); // } - if (statusCode == 401 && realm != null && wwwAuth.size() > 0 && !future.getAndSetAuth(true)) { + if (statusCode == 401 && realm != null && !wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { future.setState(NettyResponseFuture.STATE.NEW); // NTLM @@ -2097,7 +2097,7 @@ public Object call() throws Exception { } List proxyAuth = getAuthorizationToken(response.getHeaders(), HttpHeaders.Names.PROXY_AUTHENTICATE); - if (statusCode == 407 && realm != null && proxyAuth.size() > 0 && !future.getAndSetAuth(true)) { + if (statusCode == 407 && realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { log.debug("Sending proxy authentication to {}", request.getUrl()); @@ -2178,7 +2178,7 @@ public Object call() throws Exception { } } } catch (Exception t) { - if (IOException.class.isAssignableFrom(t.getClass()) && config.getIOExceptionFilters().size() > 0) { + if (IOException.class.isAssignableFrom(t.getClass()) && !config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(IOException.class.cast(t)).build(); fc = handleIoException(fc, future); From 06bbe1f4ce556b86f4830d4d0798dfb1593cad15 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:44:57 +0200 Subject: [PATCH 0022/2389] Use instanceof instead of isAssignableFrom where possible, close #342 --- .../org/asynchttpclient/AsyncHttpClient.java | 3 +- .../consumers/AppendableBodyConsumer.java | 2 +- .../multipart/MultipartBody.java | 4 +- .../providers/jdk/JDKAsyncHttpProvider.java | 24 +++++------- .../resumable/ResumableIOExceptionFilter.java | 4 +- .../websocket/WebSocketUpgradeHandler.java | 2 +- .../async/AsyncProvidersBasicTest.java | 2 +- .../asynchttpclient/async/EmptyBodyTest.java | 2 +- .../providers/grizzly/EventHandler.java | 24 ++++-------- .../grizzly/bodyhandler/FileBodyHandler.java | 2 +- .../filters/AsyncHttpClientFilter.java | 13 ++----- .../AHCWebSocketListenerAdapter.java | 18 ++++----- .../netty/NettyAsyncHttpProvider.java | 38 +++++++++---------- .../providers/netty/NettyConnectListener.java | 2 +- .../providers/netty/NettyConnectionsPool.java | 2 +- .../providers/netty/NettyWebSocket.java | 6 +-- 16 files changed, 63 insertions(+), 85 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 0966f12ba8..4da9a16f98 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -16,7 +16,6 @@ */ package org.asynchttpclient; -import org.asynchttpclient.Request.EntityWriter; import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.RequestFilter; @@ -606,7 +605,7 @@ private FilterContext preProcessRequest(FilterContext fc) throws IOExc } Request request = fc.getRequest(); - if (ResumableAsyncHandler.class.isAssignableFrom(fc.getAsyncHandler().getClass())) { + if (fc.getAsyncHandler() instanceof ResumableAsyncHandler) { request = ResumableAsyncHandler.class.cast(fc.getAsyncHandler()).adjustRequestRange(request); } diff --git a/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java b/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java index c69ac0698a..4ddbde6f84 100644 --- a/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java +++ b/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java @@ -52,7 +52,7 @@ public void consume(ByteBuffer byteBuffer) throws IOException { */ /* @Override */ public void close() throws IOException { - if (Closeable.class.isAssignableFrom(appendable.getClass())) { + if (appendable instanceof Closeable) { Closeable.class.cast(appendable).close(); } } diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java index 97a998f8bf..9f5ec1d756 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java @@ -223,7 +223,7 @@ private void initializeFileEnd(FilePart currentPart) private void initializeFileBody(FilePart currentPart) throws IOException { - if (FilePartSource.class.isAssignableFrom(currentPart.getSource().getClass())) { + if (currentPart.getSource() instanceof FilePartSource) { FilePartSource source = (FilePartSource) currentPart.getSource(); @@ -444,7 +444,7 @@ private long handleFilePart(WritableByteChannel target, FilePart filePart) throw handler.start(); - if (FilePartSource.class.isAssignableFrom(filePart.getSource().getClass())) { + if (filePart.getSource() instanceof FilePartSource) { int length = 0; length += handleFileHeaders(target, filePart); diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index c7a79c0dd4..64b2017093 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -36,9 +36,6 @@ import org.asynchttpclient.filter.IOExceptionFilter; import org.asynchttpclient.filter.ResponseFilter; import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; import org.asynchttpclient.multipart.MultipartRequestEntity; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.asynchttpclient.util.AuthenticatorUtils; @@ -105,7 +102,7 @@ public JDKAsyncHttpProvider(AsyncHttpClientConfig config) { this.config = config; AsyncHttpProviderConfig providerConfig = config.getAsyncHttpProviderConfig(); - if (providerConfig != null && JDKAsyncHttpProviderConfig.class.isAssignableFrom(providerConfig.getClass())) { + if (providerConfig instanceof JDKAsyncHttpProviderConfig) { configure(JDKAsyncHttpProviderConfig.class.cast(providerConfig)); } } @@ -236,7 +233,7 @@ public T call() throws Exception { configure(uri, urlConnection, request); urlConnection.connect(); - if (TransferCompletionHandler.class.isAssignableFrom(asyncHandler.getClass())) { + if (asyncHandler instanceof TransferCompletionHandler) { throw new IllegalStateException(TransferCompletionHandler.class.getName() + "not supported by this provider"); } @@ -351,9 +348,10 @@ public T call() throws Exception { } } - if (ProgressAsyncHandler.class.isAssignableFrom(asyncHandler.getClass())) { - ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteCompleted(); + if (asyncHandler instanceof ProgressAsyncHandler) { + ProgressAsyncHandler progressAsyncHandler = ProgressAsyncHandler.class.cast(asyncHandler); + progressAsyncHandler.onHeaderWriteCompleted(); + progressAsyncHandler.onContentWriteCompleted(); } try { T t = asyncHandler.onCompleted(); @@ -368,7 +366,7 @@ public T call() throws Exception { } catch (Throwable t) { logger.debug(t.getMessage(), t); - if (IOException.class.isAssignableFrom(t.getClass()) && !config.getIOExceptionFilters().isEmpty()) { + if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(asyncHandler) .request(request).ioException(IOException.class.cast(t)).build(); @@ -419,16 +417,14 @@ private FilterContext handleIoException(FilterContext fc) throws FilterException } private Throwable filterException(Throwable t) { - if (UnknownHostException.class.isAssignableFrom(t.getClass())) { + if (t instanceof UnknownHostException) { t = new ConnectException(t.getMessage()); - } - if (SocketTimeoutException.class.isAssignableFrom(t.getClass())) { + } else if (t instanceof SocketTimeoutException) { int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); t = new TimeoutException("No response received after " + requestTimeout); - } - if (SSLHandshakeException.class.isAssignableFrom(t.getClass())) { + } else if (t instanceof SSLHandshakeException) { Throwable t2 = new ConnectException(); t2.initCause(t); t = t2; diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java index 2b686f7bac..456360ae15 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java @@ -16,8 +16,6 @@ import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; /** * Simple {@link org.asynchttpclient.filter.IOExceptionFilter} that replay the current {@link org.asynchttpclient.Request} using @@ -25,7 +23,7 @@ */ public class ResumableIOExceptionFilter implements IOExceptionFilter { public FilterContext filter(FilterContext ctx) throws FilterException { - if (ctx.getIOException() != null && ResumableAsyncHandler.class.isAssignableFrom(ctx.getAsyncHandler().getClass())) { + if (ctx.getIOException() != null && ctx.getAsyncHandler() instanceof ResumableAsyncHandler) { Request request = ResumableAsyncHandler.class.cast(ctx.getAsyncHandler()).adjustRequestRange(ctx.getRequest()); diff --git a/api/src/main/java/org/asynchttpclient/websocket/WebSocketUpgradeHandler.java b/api/src/main/java/org/asynchttpclient/websocket/WebSocketUpgradeHandler.java index 870d74c545..c118e59714 100644 --- a/api/src/main/java/org/asynchttpclient/websocket/WebSocketUpgradeHandler.java +++ b/api/src/main/java/org/asynchttpclient/websocket/WebSocketUpgradeHandler.java @@ -130,7 +130,7 @@ public final void onClose(WebSocket webSocket, int status, String reasonPhrase) webSocket.addWebSocketListener(w); } w.onClose(webSocket); - if (WebSocketCloseCodeReasonListener.class.isAssignableFrom(w.getClass())) { + if (w instanceof WebSocketCloseCodeReasonListener) { WebSocketCloseCodeReasonListener.class.cast(w).onClose(webSocket, status, reasonPhrase); } } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index e1c3c9187a..c2564716f0 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -965,7 +965,7 @@ public void onThrowable(Throwable t) { future.get(10, TimeUnit.SECONDS); } catch (ExecutionException ex) { - if (ex.getCause() != null && TimeoutException.class.isAssignableFrom(ex.getCause().getClass())) { + if (ex.getCause() instanceof TimeoutException) { Assert.assertTrue(true); } } catch (TimeoutException te) { diff --git a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java index 13924201cc..aa5fdfbed5 100644 --- a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java @@ -132,7 +132,7 @@ public void testPutEmptyBody() throws Throwable { assertNotNull(response); assertEquals(response.getStatusCode(), 204); assertEquals(response.getResponseBody(), ""); - assertTrue(InputStream.class.isAssignableFrom(response.getResponseBodyAsStream().getClass())); + assertTrue(response.getResponseBodyAsStream() instanceof InputStream); assertEquals(response.getResponseBodyAsStream().read(), -1); } finally { ahc.close(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 46a6830ffd..3c3f7c5846 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -121,27 +121,19 @@ public void onHttpContentParsed(HttpContent content, public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) { final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); - if (handler != null) { - if (TransferCompletionHandler.class.isAssignableFrom(handler.getClass())) { - ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); - } - } + if (handler instanceof TransferCompletionHandler) { + ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); + } } public void onHttpContentEncoded(HttpContent content, FilterChainContext ctx) { final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); - if (handler != null) { - if (TransferCompletionHandler.class.isAssignableFrom(handler.getClass())) { - final int written = content.getContent().remaining(); - final long total = context.getTotalBodyWritten().addAndGet( - written); - ((TransferCompletionHandler) handler).onContentWriteProgress( - written, - total, - content.getHttpHeader().getContentLength()); - } - } + if (handler instanceof TransferCompletionHandler) { + final int written = content.getContent().remaining(); + final long total = context.getTotalBodyWritten().addAndGet(written); + ((TransferCompletionHandler) handler).onContentWriteProgress(written, total, content.getHttpHeader().getContentLength()); + } } public void onInitialLineParsed(HttpHeader httpHeader, diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java index 3085f7c147..cb26e1ab0f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java @@ -94,7 +94,7 @@ public boolean doHandle(final FilterChainContext ctx, public void updated(WriteResult result) { final AsyncHandler handler = context.getHandler(); if (handler != null) { - if (TransferCompletionHandler.class.isAssignableFrom(handler.getClass())) { + if (handler instanceof TransferCompletionHandler) { // WriteResult keeps a track of the total amount written, // so we need to calculate the delta ourselves. final long resultTotal = result.getWrittenSize(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index d48869b7a2..bc1b7a172e 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -285,15 +285,10 @@ private static FilterChainContext checkAndHandleFilterChainUpdate(final FilterCh private static void initTransferCompletionHandler(final Request request, final AsyncHandler h) throws IOException { - if (h != null) { - if (TransferCompletionHandler.class.isAssignableFrom(h.getClass())) { - final FluentCaseInsensitiveStringsMap map = - new FluentCaseInsensitiveStringsMap( - request.getHeaders()); - TransferCompletionHandler.class.cast(h) - .transferAdapter(new GrizzlyTransferAdapter(map)); - } - } + if (h instanceof TransferCompletionHandler) { + final FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(request.getHeaders()); + TransferCompletionHandler.class.cast(h).transferAdapter(new GrizzlyTransferAdapter(map)); + } } private static boolean checkHandshakeError(final FilterChainContext ctx, diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java index 1f245645ad..ebbc1d7d96 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java @@ -54,7 +54,7 @@ public AHCWebSocketListenerAdapter(final WebSocketListener ahcListener, @Override public void onClose(org.glassfish.grizzly.websockets.WebSocket gWebSocket, DataFrame dataFrame) { try { - if (WebSocketCloseCodeReasonListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketCloseCodeReasonListener) { ClosingFrame cf = ClosingFrame.class.cast(dataFrame); WebSocketCloseCodeReasonListener.class.cast(ahcListener).onClose(webSocket, cf.getCode(), cf.getReason()); } else { @@ -77,7 +77,7 @@ public void onConnect(org.glassfish.grizzly.websockets.WebSocket gWebSocket) { @Override public void onMessage(org.glassfish.grizzly.websockets.WebSocket webSocket, String s) { try { - if (WebSocketTextListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketTextListener) { WebSocketTextListener.class.cast(ahcListener).onMessage(s); } } catch (Throwable e) { @@ -88,7 +88,7 @@ public void onMessage(org.glassfish.grizzly.websockets.WebSocket webSocket, Stri @Override public void onMessage(org.glassfish.grizzly.websockets.WebSocket webSocket, byte[] bytes) { try { - if (WebSocketByteListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketByteListener) { WebSocketByteListener.class.cast(ahcListener).onMessage(bytes); } } catch (Throwable e) { @@ -99,7 +99,7 @@ public void onMessage(org.glassfish.grizzly.websockets.WebSocket webSocket, byte @Override public void onPing(org.glassfish.grizzly.websockets.WebSocket webSocket, byte[] bytes) { try { - if (WebSocketPingListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketPingListener) { WebSocketPingListener.class.cast(ahcListener).onPing(bytes); } } catch (Throwable e) { @@ -110,7 +110,7 @@ public void onPing(org.glassfish.grizzly.websockets.WebSocket webSocket, byte[] @Override public void onPong(org.glassfish.grizzly.websockets.WebSocket webSocket, byte[] bytes) { try { - if (WebSocketPongListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketPongListener) { WebSocketPongListener.class.cast(ahcListener).onPong(bytes); } } catch (Throwable e) { @@ -125,7 +125,7 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, Str synchronized (this.webSocket) { stringBuffer.append(s); if (last) { - if (WebSocketTextListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketTextListener) { final String message = stringBuffer.toString(); stringBuffer.setLength(0); WebSocketTextListener.class.cast(ahcListener).onMessage(message); @@ -133,7 +133,7 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, Str } } } else { - if (WebSocketTextListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketTextListener) { WebSocketTextListener.class.cast(ahcListener).onFragment(s, last); } } @@ -149,7 +149,7 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, byt synchronized (this.webSocket) { byteArrayOutputStream.write(bytes); if (last) { - if (WebSocketByteListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketByteListener) { final byte[] bytesLocal = byteArrayOutputStream.toByteArray(); byteArrayOutputStream.reset(); WebSocketByteListener.class.cast(ahcListener).onMessage(bytesLocal); @@ -157,7 +157,7 @@ public void onFragment(org.glassfish.grizzly.websockets.WebSocket webSocket, byt } } } else { - if (WebSocketByteListener.class.isAssignableFrom(ahcListener.getClass())) { + if (ahcListener instanceof WebSocketByteListener) { WebSocketByteListener.class.cast(ahcListener).onFragment(bytes, last); } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 078982c990..12b05f6dcc 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -78,6 +78,7 @@ import org.jboss.netty.channel.socket.ClientSocketChannelFactory; import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; +import org.jboss.netty.handler.codec.PrematureChannelClosureException; import org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer; import org.jboss.netty.handler.codec.http.DefaultHttpRequest; import org.jboss.netty.handler.codec.http.HttpChunk; @@ -187,7 +188,7 @@ private static boolean isNTLM(List auth) { public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { - if (config.getAsyncHttpProviderConfig() != null && NettyAsyncHttpProviderConfig.class.isAssignableFrom(config.getAsyncHttpProviderConfig().getClass())) { + if (config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig) { asyncHttpProviderConfig = NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()); } else { asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); @@ -412,7 +413,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie BodyGenerator bg = future.getRequest().getBodyGenerator(); if (bg != null) { // Netty issue with chunking. - if (InputStreamBodyGenerator.class.isAssignableFrom(bg.getClass())) { + if (bg instanceof InputStreamBodyGenerator) { InputStreamBodyGenerator.class.cast(bg).patchNettyChunkingIssue(true); } @@ -432,7 +433,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie } } - if (TransferCompletionHandler.class.isAssignableFrom(future.getAsyncHandler().getClass())) { + if (future.getAsyncHandler() instanceof TransferCompletionHandler) { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); for (String s : future.getNettyRequest().getHeaderNames()) { @@ -1368,7 +1369,7 @@ protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) connectionsPool.removeAll(channel); - if (future == null && channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment() != null && NettyResponseFuture.class.isAssignableFrom(channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment().getClass())) { + if (future == null && channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment() instanceof NettyResponseFuture) { future = (NettyResponseFuture) channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); } @@ -1447,10 +1448,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Throwable cause = e.getCause(); NettyResponseFuture future = null; - /** - * Issue 81 if (e.getCause() != null && e.getCause().getClass().isAssignableFrom(PrematureChannelClosureException.class)) { return; } - */ - if (e.getCause() != null && e.getCause().getClass().getSimpleName().equals("PrematureChannelClosureException")) { + if (e.getCause() instanceof PrematureChannelClosureException) { return; } @@ -1460,7 +1458,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws try { - if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) { + if (cause instanceof ClosedChannelException) { return; } @@ -1469,7 +1467,7 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws future.attachChannel(null, false); future.touch(); - if (IOException.class.isAssignableFrom(cause.getClass())) { + if (cause instanceof IOException) { if (!config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); @@ -1631,7 +1629,7 @@ public void operationComplete(ChannelFuture cf) { Throwable cause = cf.getCause(); if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) { - if (IllegalStateException.class.isAssignableFrom(cause.getClass())) { + if (cause instanceof IllegalStateException) { log.debug(cause.getMessage(), cause); try { cf.getChannel().close(); @@ -1641,7 +1639,7 @@ public void operationComplete(ChannelFuture cf) { return; } - if (ClosedChannelException.class.isAssignableFrom(cause.getClass()) || abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) { + if (cause instanceof ClosedChannelException || abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) { if (log.isDebugEnabled()) { log.debug(cf.getCause() == null ? "" : cf.getCause().getMessage(), cf.getCause()); @@ -1666,7 +1664,7 @@ public void operationComplete(ChannelFuture cf) { Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : NettyAsyncHttpProvider.this.getConfig().getRealm(); boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth() == true; - if (startPublishing && ProgressAsyncHandler.class.isAssignableFrom(asyncHandler.getClass())) { + if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) { if (notifyHeaders) { ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); } else { @@ -1677,7 +1675,7 @@ public void operationComplete(ChannelFuture cf) { public void operationProgressed(ChannelFuture cf, long amount, long current, long total) { future.touch(); - if (ProgressAsyncHandler.class.isAssignableFrom(asyncHandler.getClass())) { + if (asyncHandler instanceof ProgressAsyncHandler) { ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(amount, current, total); } } @@ -1915,7 +1913,7 @@ public void destroy() { } private static final boolean validateWebSocketRequest(Request request, AsyncHandler asyncHandler) { - if (request.getMethod() != "GET" || !WebSocketUpgradeHandler.class.isAssignableFrom(asyncHandler.getClass())) { + if (request.getMethod() != "GET" || !(asyncHandler instanceof WebSocketUpgradeHandler)) { return false; } return true; @@ -2178,7 +2176,7 @@ public Object call() throws Exception { } } } catch (Exception t) { - if (IOException.class.isAssignableFrom(t.getClass()) && !config.getIOExceptionFilters().isEmpty()) { + if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty()) { FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(IOException.class.cast(t)).build(); fc = handleIoException(fc, future); @@ -2337,7 +2335,7 @@ public void setContent(ChannelBuffer content) { webSocket.onTextFragment(frame.getBinaryData().toString(UTF8), frame.isFinalFragment()); } - if (CloseWebSocketFrame.class.isAssignableFrom(frame.getClass())) { + if (frame instanceof CloseWebSocketFrame) { try { ctx.setAttachment(DiscardEvent.class); webSocket.onClose(CloseWebSocketFrame.class.cast(frame).getStatusCode(), CloseWebSocketFrame.class.cast(frame).getReasonText()); @@ -2359,7 +2357,7 @@ public void setContent(ChannelBuffer content) { public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { try { log.warn("onError {}", e); - if (ctx.getAttachment() == null || !NettyResponseFuture.class.isAssignableFrom(ctx.getAttachment().getClass())) { + if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { return; } @@ -2379,7 +2377,7 @@ public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { // @Override public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { log.trace("onClose {}", e); - if (ctx.getAttachment() == null || !NettyResponseFuture.class.isAssignableFrom(ctx.getAttachment().getClass())) { + if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { return; } @@ -2388,7 +2386,7 @@ public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - if (ctx.getAttachment() == null || !DiscardEvent.class.isAssignableFrom(ctx.getAttachment().getClass())) + if (!(ctx.getAttachment() instanceof DiscardEvent)) webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent)."); } catch (Throwable t) { log.error("onError", t); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java index 5e3a7cfa62..0d090275fb 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java @@ -87,7 +87,7 @@ public final void operationComplete(ChannelFuture f) throws Exception { logger.debug("Trying to recover a dead cached channel {} with a retry value of {} ", f.getChannel(), future.canRetry()); if (future.canRetry() && cause != null && (NettyAsyncHttpProvider.abortOnDisconnectException(cause) - || ClosedChannelException.class.isAssignableFrom(cause.getClass()) + || cause instanceof ClosedChannelException || future.getState() != NettyResponseFuture.STATE.NEW)) { logger.debug("Retrying {} ", nettyRequest); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java index 5afd504df4..0ecc026780 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java @@ -118,7 +118,7 @@ public void run() { for (IdleChannel idleChannel : channelsInTimeout) { Object attachment = idleChannel.channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); if (attachment != null) { - if (NettyResponseFuture.class.isAssignableFrom(attachment.getClass())) { + if (attachment instanceof NettyResponseFuture) { NettyResponseFuture future = (NettyResponseFuture) attachment; if (!future.isDone() && !future.isCancelled()) { diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java index 8ae4f1ee03..860764a4c6 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java @@ -132,7 +132,7 @@ public void close(int statusCode, String reason) { protected void onBinaryFragment(byte[] message, boolean last) { for (WebSocketListener l : listeners) { - if (WebSocketByteListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketByteListener) { try { WebSocketByteListener.class.cast(l).onFragment(message,last); @@ -164,7 +164,7 @@ protected void onBinaryFragment(byte[] message, boolean last) { protected void onTextFragment(String message, boolean last) { for (WebSocketListener l : listeners) { - if (WebSocketTextListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketTextListener) { try { WebSocketTextListener.class.cast(l).onFragment(message,last); @@ -211,7 +211,7 @@ protected void onClose() { protected void onClose(int code, String reason) { for (WebSocketListener l : listeners) { try { - if (WebSocketCloseCodeReasonListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketCloseCodeReasonListener) { WebSocketCloseCodeReasonListener.class.cast(l).onClose(this, code, reason); } l.onClose(this); From 3e55e09dd3b29f021ba4f70a924e34438fb04a8e Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:47:33 +0200 Subject: [PATCH 0023/2389] Honor multipart boundary if specified in existing Content-Type header, close #345 --- .../multipart/MultipartRequestEntity.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java index 356bb59d07..69689f675c 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java @@ -63,7 +63,7 @@ private static byte[] generateMultipartBoundary() { */ protected Part[] parts; - private byte[] multipartBoundary; + private final byte[] multipartBoundary; private final String contentType; @@ -71,18 +71,35 @@ private static byte[] generateMultipartBoundary() { * Creates a new multipart entity containing the given parts. * * @param parts The parts to include. - * @param requestHeader */ public MultipartRequestEntity(Part[] parts, FluentCaseInsensitiveStringsMap requestHeaders) { if (parts == null) { throw new IllegalArgumentException("parts cannot be null"); } - String contentTypeHeader = requestHeaders.getFirstValue("Content-Type"); - if (isNonEmpty(contentTypeHeader)) - this.contentType = contentTypeHeader; - else - this.contentType = MULTIPART_FORM_CONTENT_TYPE; this.parts = parts; + String contentTypeHeader = requestHeaders.getFirstValue("Content-Type"); + if (isNonEmpty(contentTypeHeader)) { + int boundaryLocation = contentTypeHeader.indexOf("boundary="); + if (boundaryLocation != -1) { + // boundary defined in existing Content-Type + contentType = contentTypeHeader; + multipartBoundary = MultipartEncodingUtil.getAsciiBytes((contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim())); + } else { + // generate boundary and append it to existing Content-Type + multipartBoundary = generateMultipartBoundary(); + contentType = computeContentType(contentTypeHeader); + } + } else { + multipartBoundary = generateMultipartBoundary(); + contentType = computeContentType(MULTIPART_FORM_CONTENT_TYPE); + } + } + + private String computeContentType(String base) { + StringBuilder buffer = new StringBuilder(base); + if (!base.endsWith(";")) + buffer.append(";"); + return buffer.append(" boundary=").append(MultipartEncodingUtil.getAsciiString(multipartBoundary)).toString(); } /** @@ -92,9 +109,6 @@ public MultipartRequestEntity(Part[] parts, FluentCaseInsensitiveStringsMap requ * @return The boundary string of this entity in ASCII encoding. */ protected byte[] getMultipartBoundary() { - if (multipartBoundary == null) { - multipartBoundary = generateMultipartBoundary(); - } return multipartBoundary; } @@ -116,7 +130,7 @@ public boolean isRepeatable() { * @see org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream) */ public void writeRequest(OutputStream out) throws IOException { - Part.sendParts(out, parts, getMultipartBoundary()); + Part.sendParts(out, parts, multipartBoundary); } /* @@ -126,7 +140,7 @@ public void writeRequest(OutputStream out) throws IOException { */ public long getContentLength() { try { - return Part.getLengthOfParts(parts, getMultipartBoundary()); + return Part.getLengthOfParts(parts, multipartBoundary); } catch (Exception e) { log.error("An exception occurred while getting the length of the parts", e); return 0; @@ -139,16 +153,7 @@ public long getContentLength() { * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType() */ public String getContentType() { - if (contentType.contains("boundary=")) - return contentType; - else { - StringBuilder buffer = new StringBuilder(contentType); - if (!contentType.endsWith(";")) - buffer.append(";"); - buffer.append(" boundary="); - buffer.append(MultipartEncodingUtil.getAsciiString(getMultipartBoundary())); - return buffer.toString(); - } + return contentType; } - } + From a4b2b6312a22db34c01a9b754e3640534b2d2259 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:53:46 +0200 Subject: [PATCH 0024/2389] Remove ListenableFuture.done Callable argument, close #344 --- .../org/asynchttpclient/ListenableFuture.java | 5 ++--- .../listenable/AbstractListenableFuture.java | 4 ++-- .../providers/jdk/JDKAsyncHttpProvider.java | 4 ++-- .../providers/jdk/JDKDelegateFuture.java | 9 ++++----- .../asynchttpclient/providers/jdk/JDKFuture.java | 12 +++++------- .../providers/jdk/JDKResponse.java | 1 - .../providers/grizzly/EventHandler.java | 2 +- .../providers/grizzly/GrizzlyResponseFuture.java | 9 ++++----- .../grizzly/HttpTransactionContext.java | 7 +++---- .../providers/netty/NettyAsyncHttpProvider.java | 4 ++-- .../providers/netty/NettyResponseFuture.java | 16 ++++------------ 11 files changed, 29 insertions(+), 44 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/ListenableFuture.java b/api/src/main/java/org/asynchttpclient/ListenableFuture.java index f40012e76c..b7593b0e93 100755 --- a/api/src/main/java/org/asynchttpclient/ListenableFuture.java +++ b/api/src/main/java/org/asynchttpclient/ListenableFuture.java @@ -30,7 +30,6 @@ */ package org.asynchttpclient; -import java.util.concurrent.Callable; import java.util.concurrent.Executor; import java.util.concurrent.Future; @@ -42,11 +41,11 @@ public interface ListenableFuture extends Future { /** - * Execute a {@link Callable} and if there is no exception, mark this Future as done and release the internal lock. + * Terminate and if there is no exception, mark this Future as done and release the internal lock. * * @param callable */ - void done(Callable callable); + void done(); /** * Abort the current processing, and propagate the {@link Throwable} to the {@link AsyncHandler} or {@link Future} diff --git a/api/src/main/java/org/asynchttpclient/listenable/AbstractListenableFuture.java b/api/src/main/java/org/asynchttpclient/listenable/AbstractListenableFuture.java index 0317752849..be0d81842f 100644 --- a/api/src/main/java/org/asynchttpclient/listenable/AbstractListenableFuture.java +++ b/api/src/main/java/org/asynchttpclient/listenable/AbstractListenableFuture.java @@ -61,9 +61,9 @@ public ListenableFuture addListener(Runnable listener, Executor exec) { } /* - * Override the done method to execute the execution list. + * Execute the execution list. */ - protected void done() { + protected void runListeners() { executionList.run(); } } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index 64b2017093..b4821e1143 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -356,7 +356,7 @@ public T call() throws Exception { try { T t = asyncHandler.onCompleted(); future.content(t); - future.done(null); + future.done(); return t; } catch (Throwable t) { RuntimeException ex = new RuntimeException(); @@ -376,7 +376,7 @@ public T call() throws Exception { if (config.getMaxTotalConnections() != -1) { maxConnections.decrementAndGet(); } - future.done(null); + future.done(); } if (fc.replayRequest()) { diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java index 62dede5fd2..1b4dd34ea0 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java @@ -17,7 +17,6 @@ import org.asynchttpclient.ListenableFuture; import java.net.HttpURLConnection; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -32,9 +31,9 @@ public JDKDelegateFuture(AsyncHandler asyncHandler, int responseTimeoutInMs, this.delegateFuture = delegateFuture; } - public void done(Callable callable) { - delegateFuture.done(callable); - super.done(callable); + public void done() { + delegateFuture.done(); + runListeners(); } public void abort(Throwable t) { @@ -79,7 +78,7 @@ public V get(long timeout, TimeUnit unit) throws InterruptedException, Execution delegateFuture.abort(new ExecutionException(exception.get())); } delegateFuture.content(content); - delegateFuture.done(null); + delegateFuture.done(); return content; } } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java index 2810a33f2f..893312cfcb 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java @@ -15,12 +15,10 @@ import static org.asynchttpclient.util.DateUtil.millisTime; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.listenable.AbstractListenableFuture; -import org.asynchttpclient.listenable.AbstractListenableFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.net.HttpURLConnection; -import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -60,9 +58,9 @@ protected void setInnerFuture(Future innerFuture) { this.innerFuture = innerFuture; } - public void done(Callable callable) { + public void done() { isDone.set(true); - super.done(); + runListeners(); } public void abort(Throwable t) { @@ -77,7 +75,7 @@ public void abort(Throwable t) { logger.debug("asyncHandler.onThrowable", te); } } - super.done(); + runListeners(); } public void content(V v) { @@ -92,10 +90,10 @@ public boolean cancel(boolean mayInterruptIfRunning) { logger.debug("asyncHandler.onThrowable", te); } cancelled.set(true); - super.done(); + runListeners(); return innerFuture.cancel(mayInterruptIfRunning); } else { - super.done(); + runListeners(); return false; } } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java index 682db9fc4d..c3b536e971 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java @@ -18,7 +18,6 @@ import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.providers.ResponseBase; -import org.asynchttpclient.providers.ResponseBase; import org.asynchttpclient.util.AsyncHttpProviderUtils; import java.io.IOException; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 3c3f7c5846..5db786897f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -395,7 +395,7 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) context.abort(e); } } else { - context.done(null); + context.done(); } return result; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java index 92534f502f..b53c55fe61 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java @@ -21,7 +21,6 @@ import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.impl.FutureImpl; -import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -66,12 +65,12 @@ public GrizzlyResponseFuture(final GrizzlyAsyncHttpProvider provider, // ----------------------------------- Methods from AbstractListenableFuture - public void done(Callable callable) { + public void done() { if (!done.compareAndSet(false, true) || cancelled.get()) { return; } - done(); + runListeners(); } @@ -89,7 +88,7 @@ public void abort(Throwable t) { } } closeConnection(); - done(); + runListeners(); } @@ -140,7 +139,7 @@ public boolean cancel(boolean mayInterruptIfRunning) { } catch (Throwable ignore) { } } - done(); + runListeners(); return delegate.cancel(mayInterruptIfRunning); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java index 5e726acac7..c9718e0613 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java @@ -25,7 +25,6 @@ import org.glassfish.grizzly.websockets.HandShake; import org.glassfish.grizzly.websockets.ProtocolHandler; -import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -284,9 +283,9 @@ public HttpTransactionContext copy() { } - void done(final Callable c) { + void done() { if (future != null) { - future.done(c); + future.done(); } } @@ -294,7 +293,7 @@ void done(final Callable c) { void result(Object result) { if (future != null) { future.delegate.result(result); - future.done(null); + future.done(); } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 12b05f6dcc..95d59056b5 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -1397,7 +1397,7 @@ protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { // We need to make sure everything is OK before adding the connection back to the pool. try { - future.done(null); + future.done(); } catch (Throwable t) { // Never propagate exception once we know we are done. log.debug(t.getMessage(), t); @@ -2289,7 +2289,7 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { ctx.getPipeline().get(HttpResponseDecoder.class).replace("ws-decoder", new WebSocket08FrameDecoder(false, false)); invokeOnSucces(ctx, h); - future.done(null); + future.done(); } else if (e.getMessage() instanceof WebSocketFrame) { invokeOnSucces(ctx, h); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java index ca7773af7b..7e17358c4d 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java @@ -29,7 +29,6 @@ import java.net.MalformedURLException; import java.net.URI; -import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -178,7 +177,7 @@ public boolean cancel(boolean force) { } latch.countDown(); isCancelled.set(true); - super.done(); + runListeners(); return true; } @@ -291,7 +290,7 @@ V getContent() throws ExecutionException { return update; } - public final void done(Callable callable) { + public final void done() { Throwable exception = null; @@ -303,13 +302,6 @@ public final void done(Callable callable) { } getContent(); isDone.set(true); - if (callable != null) { - try { - callable.call(); - } catch (Exception ex) { - exception = ex; - } - } } catch (ExecutionException t) { return; } catch (RuntimeException t) { @@ -322,7 +314,7 @@ public final void done(Callable callable) { if (exception != null) exEx.compareAndSet(null, new ExecutionException(exception)); - super.done(); + runListeners(); } public final void abort(final Throwable t) { @@ -342,7 +334,7 @@ public final void abort(final Throwable t) { } } latch.countDown(); - super.done(); + runListeners(); } public void content(V v) { From 73fcd3c9f54562580e1be2def705708210e61491 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:54:59 +0200 Subject: [PATCH 0025/2389] Fix race condition in NettyResponseFuture.done exception handling, close #337 --- .../providers/netty/NettyResponseFuture.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java index 7e17358c4d..dab12365f2 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java @@ -292,8 +292,6 @@ V getContent() throws ExecutionException { public final void done() { - Throwable exception = null; - try { cancelReaper(); @@ -305,15 +303,13 @@ public final void done() { } catch (ExecutionException t) { return; } catch (RuntimeException t) { - exception = t.getCause() != null ? t.getCause() : t; + Throwable exception = t.getCause() != null ? t.getCause() : t; + exEx.compareAndSet(null, new ExecutionException(exception)); } finally { latch.countDown(); } - if (exception != null) - exEx.compareAndSet(null, new ExecutionException(exception)); - runListeners(); } From f859cec14112792f196786e73491b50e3a5806ec Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:56:59 +0200 Subject: [PATCH 0026/2389] Make NettyConnectionsPool's Timer externally configurable, close #346 --- .../providers/netty/NettyConnectionsPool.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java index 0ecc026780..665a45bdf7 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java @@ -37,7 +37,7 @@ public class NettyConnectionsPool implements ConnectionsPool { private final ConcurrentHashMap channel2IdleChannel = new ConcurrentHashMap(); private final ConcurrentHashMap channel2CreationDate = new ConcurrentHashMap(); private final AtomicBoolean isClosed = new AtomicBoolean(false); - private final Timer idleConnectionDetector = new Timer(true); + private final Timer idleConnectionDetector; private final boolean sslConnectionPoolEnabled; private final int maxTotalConnections; private final int maxConnectionPerHost; @@ -45,16 +45,17 @@ public class NettyConnectionsPool implements ConnectionsPool { private final long maxIdleTime; public NettyConnectionsPool(NettyAsyncHttpProvider provider) { - this(provider.getConfig().getMaxTotalConnections(), provider.getConfig().getMaxConnectionPerHost(), provider.getConfig().getIdleConnectionInPoolTimeoutInMs(), provider.getConfig().isSslConnectionPoolEnabled(), provider.getConfig().getMaxConnectionLifeTimeInMs()); + this(provider.getConfig().getMaxTotalConnections(), provider.getConfig().getMaxConnectionPerHost(), provider.getConfig().getIdleConnectionInPoolTimeoutInMs(), provider.getConfig().isSslConnectionPoolEnabled(), provider.getConfig().getMaxConnectionLifeTimeInMs(), new Timer(true)); } - public NettyConnectionsPool(int maxTotalConnections, int maxConnectionPerHost, long maxIdleTime, boolean sslConnectionPoolEnabled, int maxConnectionLifeTimeInMs) { + public NettyConnectionsPool(int maxTotalConnections, int maxConnectionPerHost, long maxIdleTime, boolean sslConnectionPoolEnabled, int maxConnectionLifeTimeInMs, Timer idleConnectionDetector) { this.maxTotalConnections = maxTotalConnections; this.maxConnectionPerHost = maxConnectionPerHost; this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; this.maxIdleTime = maxIdleTime; this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; this.idleConnectionDetector.schedule(new IdleChannelDetector(), maxIdleTime, maxIdleTime); + this.idleConnectionDetector = idleConnectionDetector; } private static class IdleChannel { From 0231cbf175d4a54046e51449279acb99f02aacdf Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 23 Jul 2013 14:57:49 +0200 Subject: [PATCH 0027/2389] Google redirect has changed --- .../test/java/org/asynchttpclient/async/Relative302Test.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java index 9d73308e7e..e2b65dbf29 100644 --- a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java @@ -97,10 +97,9 @@ public void redirected302Test() throws Throwable { assertNotNull(response); assertEquals(response.getStatusCode(), 200); - String anyGoogleSubdomain = "http://www//.google//.[a-z]+(//.[a-z]+)*:80"; String baseUrl = getBaseUrl(response.getUri()); - assertTrue(baseUrl.matches(anyGoogleSubdomain), "response does not show redirection to " + anyGoogleSubdomain); + assertTrue(baseUrl.startsWith("http://www.google./"), "response does not show redirection to a google subdomain, got " + baseUrl); } finally { c.close(); } From ee8e7d294cd1016e145ac39b473c32754f91bcc7 Mon Sep 17 00:00:00 2001 From: Pierre DAL-PRA Date: Tue, 23 Jul 2013 22:16:10 +0200 Subject: [PATCH 0028/2389] Fix NPE in NettyConnectionsPool --- .../asynchttpclient/providers/netty/NettyConnectionsPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java index 665a45bdf7..96b273f879 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java @@ -54,8 +54,8 @@ public NettyConnectionsPool(int maxTotalConnections, int maxConnectionPerHost, l this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; this.maxIdleTime = maxIdleTime; this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; - this.idleConnectionDetector.schedule(new IdleChannelDetector(), maxIdleTime, maxIdleTime); this.idleConnectionDetector = idleConnectionDetector; + this.idleConnectionDetector.schedule(new IdleChannelDetector(), maxIdleTime, maxIdleTime); } private static class IdleChannel { From e5f1aebd171712dd54277c85949fa04c241841ac Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 24 Jul 2013 00:17:40 +0200 Subject: [PATCH 0029/2389] Don't build request twice when using a proxy, close #235 --- .../providers/netty/NettyAsyncHttpProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 95d59056b5..d5f71864f6 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -912,9 +912,10 @@ private ListenableFuture doConnect(final Request request, final AsyncHand boolean useSSl = isSecure(uri) && !useProxy; if (channel != null && channel.isOpen() && channel.isConnected()) { - HttpRequest nettyRequest = buildRequest(config, request, uri, f == null ? false : f.isConnectAllowed(), bufferedBytes, proxyServer); + HttpRequest nettyRequest = null; if (f == null) { + nettyRequest = buildRequest(config, request, uri, false, bufferedBytes, proxyServer); f = newFuture(uri, request, asyncHandler, nettyRequest, config, this, proxyServer); } else { nettyRequest = buildRequest(config, request, uri, f.isConnectAllowed(), bufferedBytes, proxyServer); From c9331b0916e6a8764ae9b6e559a1ca11676965de Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 26 Jul 2013 11:56:52 -0700 Subject: [PATCH 0030/2389] - Improve exception handling when instantiating the different providers. If an InvocationTargetException is thrown, log the root cause. Not doing this hid a problem in the Netty provider (described below). - The 'config' instance variable needs to be set *before* calling configureNetty(). These two problems were causing the Netty tests to fail due to the fact that the Netty provider was being initialized to the point where worker threads were created, but then failed later in the constructor. The threads remained running and caused issues later with other tests (unable to create new threads). Someone more familiar with the Netty provider may wish to look into dealing with the above case better (i.e., if a problem occurs during construction, ensure the proper cleanup is performed). --- .../java/org/asynchttpclient/AsyncHttpClient.java | 12 ++++++++++-- .../providers/netty/NettyAsyncHttpProvider.java | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 4da9a16f98..7ed810960d 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; import java.util.Collection; import java.util.Map; import java.util.concurrent.Future; @@ -626,8 +627,15 @@ private static AsyncHttpProvider loadProvider(final String className, .getContextClassLoader().loadClass(className); return providerClass.getDeclaredConstructor( new Class[]{AsyncHttpClientConfig.class}).newInstance(config); - } catch (Throwable t) { - + } catch (Throwable t) { + if (t instanceof InvocationTargetException) { + final InvocationTargetException ite = (InvocationTargetException) t; + if (logger.isErrorEnabled()) { + logger.error("Unable to instantiate provider {}. Trying other providers.", + className); + logger.error(ite.getCause().toString(), ite.getCause()); + } + } // Let's try with another classloader try { Class providerClass = (Class) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index d5f71864f6..a1985f5312 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -220,10 +220,10 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { secureBootstrap = new ClientBootstrap(socketChannelFactory); webSocketBootstrap = new ClientBootstrap(socketChannelFactory); secureWebSocketBootstrap = new ClientBootstrap(socketChannelFactory); - configureNetty(); - this.config = config; + configureNetty(); + // This is dangerous as we can't catch a wrong typed ConnectionsPool ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); if (cp == null && config.getAllowPoolingConnection()) { From 23274cd5926b4798c7d9ff13b2c596297589a4e6 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 09:58:21 +0200 Subject: [PATCH 0031/2389] Typos --- .../test/java/org/asynchttpclient/async/BasicAuthTest.java | 2 +- .../asynchttpclient/async/SimpleAsyncHttpClientTest.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 361e57be51..2422bdc890 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -473,7 +473,7 @@ public AbstractHandler configureHandler() throws Exception { } @Test(groups = { "standalone", "default_provider" }, enabled = false) - public void StringBuilderBodyConsumerTest() throws Throwable { + public void stringBuilderBodyConsumerTest() throws Throwable { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setRealmPrincipal(user).setRealmPassword(admin).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index a8f09a3f95..7170170bb8 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -57,7 +57,7 @@ public void inpuStreamBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void StringBuilderBodyConsumerTest() throws Throwable { + public void stringBuilderBodyConsumerTest() throws Throwable { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { @@ -74,7 +74,7 @@ public void StringBuilderBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void ByteArrayOutputStreamBodyConsumerTest() throws Throwable { + public void byteArrayOutputStreamBodyConsumerTest() throws Throwable { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { @@ -91,7 +91,7 @@ public void ByteArrayOutputStreamBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void RequestByteArrayOutputStreamBodyConsumerTest() throws Throwable { + public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl()).build(); try { From 77f6d07771fd8a016602c8e65dd232e844f0a969 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 10:00:55 +0200 Subject: [PATCH 0032/2389] Add providerClass to SimpleAsyncHttpClient.Builder, close #349 --- .../asynchttpclient/SimpleAsyncHttpClient.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java index ccbb0f2aa9..e4cd81b893 100644 --- a/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java @@ -70,8 +70,9 @@ public class SimpleAsyncHttpClient implements Closeable { private final ErrorDocumentBehaviour errorDocumentBehaviour; private final SimpleAHCTransferListener listener; private final boolean derived; + private final String providerClass; - private SimpleAsyncHttpClient(AsyncHttpClientConfig config, RequestBuilder requestBuilder, ThrowableHandler defaultThrowableHandler, ErrorDocumentBehaviour errorDocumentBehaviour, boolean resumeEnabled, AsyncHttpClient ahc, SimpleAHCTransferListener listener) { + private SimpleAsyncHttpClient(AsyncHttpClientConfig config, RequestBuilder requestBuilder, ThrowableHandler defaultThrowableHandler, ErrorDocumentBehaviour errorDocumentBehaviour, boolean resumeEnabled, AsyncHttpClient ahc, SimpleAHCTransferListener listener, String providerClass) { this.config = config; this.requestBuilder = requestBuilder; this.defaultThrowableHandler = defaultThrowableHandler; @@ -79,6 +80,7 @@ private SimpleAsyncHttpClient(AsyncHttpClientConfig config, RequestBuilder reque this.errorDocumentBehaviour = errorDocumentBehaviour; this.asyncHttpClient = ahc; this.listener = listener; + this.providerClass = providerClass; this.derived = ahc != null; } @@ -289,7 +291,10 @@ private Future execute(RequestBuilder rb, BodyConsumer bodyConsumer, T private AsyncHttpClient asyncHttpClient() { synchronized (config) { if (asyncHttpClient == null) { - asyncHttpClient = new AsyncHttpClient(config); + if (providerClass == null) + asyncHttpClient = new AsyncHttpClient(config); + else + asyncHttpClient = new AsyncHttpClient(providerClass, config); } } return asyncHttpClient; @@ -402,6 +407,7 @@ public final static class Builder implements DerivedBuilder { private ErrorDocumentBehaviour errorDocumentBehaviour = ErrorDocumentBehaviour.WRITE; private AsyncHttpClient ahc = null; private SimpleAHCTransferListener listener = null; + private String providerClass = null; public Builder() { requestBuilder = new RequestBuilder("GET", false); @@ -661,6 +667,11 @@ public Builder setMaxRequestRetry(int maxRequestRetry) { return this; } + public Builder setProviderClass(String providerClass) { + this.providerClass = providerClass; + return this; + } + public SimpleAsyncHttpClient build() { if (realmBuilder != null) { @@ -673,7 +684,7 @@ public SimpleAsyncHttpClient build() { configBuilder.addIOExceptionFilter(new ResumableIOExceptionFilter()); - SimpleAsyncHttpClient sc = new SimpleAsyncHttpClient(configBuilder.build(), requestBuilder, defaultThrowableHandler, errorDocumentBehaviour, enableResumableDownload, ahc, listener); + SimpleAsyncHttpClient sc = new SimpleAsyncHttpClient(configBuilder.build(), requestBuilder, defaultThrowableHandler, errorDocumentBehaviour, enableResumableDownload, ahc, listener, providerClass); return sc; } From 7e28598eebb9374a9f809ee4d746f86d06ab5635 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 10:02:02 +0200 Subject: [PATCH 0033/2389] Refactor BodyChunkedInput --- .../providers/netty/BodyChunkedInput.java | 67 +++++++------------ 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java index 1c9e497765..8c260cb25b 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java @@ -16,78 +16,61 @@ import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.handler.stream.ChunkedInput; -import java.io.IOException; import java.nio.ByteBuffer; /** * Adapts a {@link Body} to Netty's {@link ChunkedInput}. */ -class BodyChunkedInput - implements ChunkedInput { +class BodyChunkedInput implements ChunkedInput { - private final Body body; - - private final int chunkSize = 1024 * 8; - - private ByteBuffer nextChunk; + private static final int DEFAULT_CHUNK_SIZE = 8 * 1024; - private static final ByteBuffer EOF = ByteBuffer.allocate(0); + private final Body body; + private final int contentLength; + private final int chunkSize; - private boolean endOfInput = false; + private boolean endOfInput; public BodyChunkedInput(Body body) { if (body == null) { throw new IllegalArgumentException("no body specified"); } this.body = body; + contentLength = (int) body.getContentLength(); + if (contentLength <= 0) + chunkSize = DEFAULT_CHUNK_SIZE; + else + chunkSize = Math.min(contentLength, DEFAULT_CHUNK_SIZE); } - private ByteBuffer peekNextChunk() - throws IOException { + public boolean hasNextChunk() throws Exception { + // unused + throw new UnsupportedOperationException(); + } - if (nextChunk == null) { + public Object nextChunk() throws Exception { + if (endOfInput) { + return null; + } else { ByteBuffer buffer = ByteBuffer.allocate(chunkSize); - long length = body.read(buffer); - if (length < 0) { - // Negative means this is finished - buffer.flip(); - nextChunk = buffer; + long r = body.read(buffer); + if (r < 0L) { endOfInput = true; - } else if (length == 0) { - // Zero means we didn't get anything this time, but may get next time - buffer.flip(); - nextChunk = null; + return null; } else { + endOfInput = r == contentLength || r < chunkSize && contentLength > 0; buffer.flip(); - nextChunk = buffer; + return ChannelBuffers.wrappedBuffer(buffer); } } - return nextChunk; - } - - /** - * Having no next chunk does not necessarily means end of input, other chunks may arrive later - */ - public boolean hasNextChunk() throws Exception { - return peekNextChunk() != null; - } - - public Object nextChunk() throws Exception { - ByteBuffer buffer = peekNextChunk(); - if (buffer == null || buffer == EOF) { - return null; - } - nextChunk = null; - - return ChannelBuffers.wrappedBuffer(buffer); } public boolean isEndOfInput() throws Exception { + // called by ChunkedWriteHandler AFTER nextChunk return endOfInput; } public void close() throws Exception { body.close(); } - } From cf2d89b46b1ad2f3f5500fba17b293e31d1f4adb Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 10:03:51 +0200 Subject: [PATCH 0034/2389] Properly set up providerClass on SimpleAsyncHttpClient based tests --- .../async/SimpleAsyncHttpClientTest.java | 28 ++++++++++--------- .../GrizzlySimpleAsyncHttpClientTest.java | 3 ++ .../netty/NettySimpleAsyncHttpClientTest.java | 3 ++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 7170170bb8..6dc2daec5a 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -40,10 +40,12 @@ public abstract class SimpleAsyncHttpClientTest extends AbstractBasicTest { private final static String MY_MESSAGE = "my message"; + public abstract String getProviderClass(); + @Test(groups = { "standalone", "default_provider" }) public void inpuStreamBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes()))); @@ -59,7 +61,7 @@ public void inpuStreamBodyConsumerTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void stringBuilderBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); @@ -76,7 +78,7 @@ public void stringBuilderBodyConsumerTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void byteArrayOutputStreamBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); @@ -93,7 +95,7 @@ public void byteArrayOutputStreamBodyConsumerTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl()).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); @@ -112,7 +114,7 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable { */ @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutZeroBytesFileTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain") + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain") .build(); try { File tmpfile = File.createTempFile("testPutZeroBytesFile", ".tmp"); @@ -133,7 +135,7 @@ public void testPutZeroBytesFileTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void testDerive() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build(); SimpleAsyncHttpClient derived = client.derive().build(); try { assertNotSame(derived, client); @@ -145,7 +147,7 @@ public void testDerive() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testDeriveOverrideURL() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl("http://invalid.url/").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl("http://invalid.url/").build(); ByteArrayOutputStream o = new ByteArrayOutputStream(10); InputStreamBodyGenerator generator = new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())); @@ -197,7 +199,7 @@ public void onBytesReceived(String url, long amount, long current, long total) { } }; - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl()).setHeader("Custom", "custom").setListener(listener).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).setHeader("Custom", "custom").setListener(listener).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); @@ -217,7 +219,7 @@ public void onBytesReceived(String url, long amount, long current, long total) { @Test(groups = { "standalone", "default_provider" }) public void testNullUrl() throws Exception { try { - new SimpleAsyncHttpClient.Builder().build().derive().build(); + new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build().derive().build(); assertTrue(true); } catch (NullPointerException ex) { fail(); @@ -226,7 +228,7 @@ public void testNullUrl() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testCloseDerivedValidMaster() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl()).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); SimpleAsyncHttpClient derived = client.derive().build(); try { derived.get().get(); @@ -243,7 +245,7 @@ public void testCloseDerivedValidMaster() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testCloseMasterInvalidDerived() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl()).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); SimpleAsyncHttpClient derived = client.derive().build(); client.close(); @@ -262,7 +264,7 @@ public void testCloseMasterInvalidDerived() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testMultiPartPut() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/multipart").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { Response response = client.put(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); @@ -286,7 +288,7 @@ public void testMultiPartPut() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testMultiPartPost() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/multipart").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { Response response = client.post(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java index 6a6d3041f3..dbd541b93b 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java @@ -24,4 +24,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } + public String getProviderClass() { + return GrizzlyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java index 27834862de..2f7c9b4e23 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java @@ -28,4 +28,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return null; } + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } } From ac3e57f878037dce4c3e91a29cfbdf5c183998c5 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 14:40:15 +0200 Subject: [PATCH 0035/2389] #326 actually only affects 1.7.x, reverting 7b75d540aa2e49d4a7907711ecd2cd6e2817c746 --- .../providers/netty/NettyAsyncHttpProvider.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index a1985f5312..9730f45cbb 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -623,11 +623,14 @@ else if (uri.getRawQuery() != null) } if (!m.equals(HttpMethod.CONNECT)) { - for (Entry> header : request.getHeaders()) { - String name = header.getKey(); - if (!HttpHeaders.Names.HOST.equalsIgnoreCase(name)) { - for (String value : header.getValue()) { - nettyRequest.addHeader(name, value); + FluentCaseInsensitiveStringsMap h = request.getHeaders(); + if (h != null) { + for (Entry> header : h) { + String name = header.getKey(); + if (!HttpHeaders.Names.HOST.equalsIgnoreCase(name)) { + for (String value : header.getValue()) { + nettyRequest.addHeader(name, value); + } } } } From be6a29dd25861c8c8e12dedaa62f63a33898d80e Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 28 Jul 2013 15:26:25 +0200 Subject: [PATCH 0036/2389] Fix bug introduced in d9a218ec9be1a4386af722d011df7dc7aa22c826 --- .../asynchttpclient/providers/netty/NettyAsyncHttpProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 9730f45cbb..4bab73cfd0 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -587,7 +587,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config, Request reque if (request.getVirtualHost() != null) { host = request.getVirtualHost(); } else { - AsyncHttpProviderUtils.getHost(uri); + host = AsyncHttpProviderUtils.getHost(uri); } HttpRequest nettyRequest; From 6c90e2597ff4b4679462e90e49bcc36b7edebe15 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 29 Jul 2013 10:11:41 +0200 Subject: [PATCH 0037/2389] Make Remotely Closed exception more generic --- .../asynchttpclient/providers/netty/NettyAsyncHttpProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 4bab73cfd0..da704e71fb 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -1357,7 +1357,7 @@ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws if (future != null && !future.isDone() && !future.isCancelled()) { if (!remotelyClosed(ctx.getChannel(), future)) { - abort(future, new IOException("Remotely Closed " + ctx.getChannel())); + abort(future, new IOException("Remotely Closed")); } } else { closeChannel(ctx); From 46e90de347f0dd41b0bc4a7ebbc0aadf3f6adfaa Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 29 Jul 2013 11:52:19 -0700 Subject: [PATCH 0038/2389] Port changes from 1.7.x. --- .../generators/InputStreamBodyGenerator.java | 6 +++++- .../test/java/org/asynchttpclient/async/BasicAuthTest.java | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java index 797b93af35..ba208b4864 100644 --- a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java +++ b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java @@ -43,7 +43,7 @@ public InputStreamBodyGenerator(InputStream inputStream) { if (inputStream.markSupported()) { inputStream.mark(0); } else { - logger.info("inputStream.markSupported() not supported. Some features will not works"); + logger.info("inputStream.markSupported() not supported. Some features will not work."); } } @@ -117,6 +117,10 @@ public long read(ByteBuffer buffer) throws IOException { } else { if (read > 0) { buffer.put(chunk, 0, read); + } else { + if (inputStream.markSupported()) { + inputStream.reset(); + } } } return read; diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 2422bdc890..2a277caa2b 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -472,7 +472,7 @@ public AbstractHandler configureHandler() throws Exception { return new SimpleHandler(); } - @Test(groups = { "standalone", "default_provider" }, enabled = false) + @Test(groups = { "standalone", "default_provider" }) public void stringBuilderBodyConsumerTest() throws Throwable { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setRealmPrincipal(user).setRealmPassword(admin).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); From 4f9ada478eab286ade453acff8ea50ff80f84ba7 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 30 Jul 2013 10:55:29 -0700 Subject: [PATCH 0039/2389] Fix test case and Grizzly impl. --- .../async/SimpleAsyncHttpClientTest.java | 4 ---- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 13 ++++++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 6dc2daec5a..2d7d8e84f4 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -253,10 +253,6 @@ public void testCloseMasterInvalidDerived() throws Exception { try { derived.get().get(); fail("Expected closed AHC"); - } catch (ExecutionException ee) { - if (!(ee.getCause() instanceof IOException)) { - fail("Unexpected failure: " + ee.getCause()); - } } catch (IOException e) { // expected } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index b334fb4266..6715dcca86 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -137,6 +137,9 @@ public GrizzlyAsyncHttpProvider(final AsyncHttpClientConfig clientConfig) { public ListenableFuture execute(final Request request, final AsyncHandler handler) throws IOException { + if (clientTransport.isStopped()) { + throw new IOException("AsyncHttpClient has been closed."); + } final ProxyServer proxy = ProxyUtils.getProxyServer(clientConfig, request); final GrizzlyResponseFuture future = new GrizzlyResponseFuture(this, request, handler, proxy); future.setDelegate(SafeFutureImpl.create()); @@ -231,11 +234,11 @@ public ListenableFuture execute(final Connection c, final Request request, final AsyncHandler handler, final GrizzlyResponseFuture future) { - Utils.addRequestInFlight(c); - if (HttpTransactionContext.get(c) == null) { - HttpTransactionContext.create(this, future, request, handler, c); - } - c.write(request, createWriteCompletionHandler(future)); + Utils.addRequestInFlight(c); + if (HttpTransactionContext.get(c) == null) { + HttpTransactionContext.create(this, future, request, handler, c); + } + c.write(request, createWriteCompletionHandler(future)); return future; } From aeb9bd7bed221463dd5c789eba0d1534241adf86 Mon Sep 17 00:00:00 2001 From: Jeanfrancois Arcand Date: Tue, 30 Jul 2013 18:18:22 -0400 Subject: [PATCH 0040/2389] Bump to the newest release --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 047711c227..f258f4b1ac 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Async Http Client library purpose is to allow Java applications to easily execut com.ning async-http-client - 1.7.16 + 1.7.19 ``` From e63a77d21e166ce1216a700419ad5e9322b7ff54 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 31 Jul 2013 13:05:40 -0700 Subject: [PATCH 0041/2389] Tabs->spaces --- .../providers/grizzly/EventHandler.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 5db786897f..e123e14ddd 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -119,21 +119,24 @@ public void onHttpContentParsed(HttpContent content, @SuppressWarnings("UnusedParameters") public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) { - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTransactionContext context = + HttpTransactionContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); - if (handler instanceof TransferCompletionHandler) { - ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); - } + if (handler instanceof TransferCompletionHandler) { + ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); + } } public void onHttpContentEncoded(HttpContent content, FilterChainContext ctx) { - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTransactionContext context = + HttpTransactionContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); - if (handler instanceof TransferCompletionHandler) { - final int written = content.getContent().remaining(); - final long total = context.getTotalBodyWritten().addAndGet(written); - ((TransferCompletionHandler) handler).onContentWriteProgress(written, total, content.getHttpHeader().getContentLength()); - } + if (handler instanceof TransferCompletionHandler) { + final int written = content.getContent().remaining(); + final long total = context.getTotalBodyWritten().addAndGet(written); + ((TransferCompletionHandler) handler).onContentWriteProgress( + written, total, content.getHttpHeader().getContentLength()); + } } public void onInitialLineParsed(HttpHeader httpHeader, From 7b857cfd0ec4d0312ddd38bc0844a1453e7abbbf Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 29 Jul 2013 12:45:17 +0200 Subject: [PATCH 0042/2389] Minor clean up, port 223641fb5e03c5deb3de768647c229b73f5a3bec to master --- .../netty/NettyAsyncHttpProvider.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index da704e71fb..4b9771c368 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -369,7 +369,7 @@ private Channel lookupInCache(URI uri, ConnectionPoolKeyStrategy connectionPoolK try { // Always make sure the channel who got cached support the proper protocol. It could - // only occurs when a HttpMethod.CONNECT is used agains a proxy that require upgrading from http to + // only occurs when a HttpMethod.CONNECT is used against a proxy that require upgrading from http to // https. return verifyChannelPipeline(channel, uri.getScheme()); } catch (Exception ex) { @@ -792,10 +792,10 @@ else if (uri.getRawQuery() != null) } } else if (request.getParts() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); + int length = computeAndSetContentLength(request, nettyRequest); - if (lenght == -1) { - lenght = MAX_BUFFERED_BYTES; + if (length == -1) { + length = MAX_BUFFERED_BYTES; } MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); @@ -808,18 +808,18 @@ else if (uri.getRawQuery() != null) */ if (isSecure(uri)) { - ChannelBuffer b = ChannelBuffers.dynamicBuffer(lenght); + ChannelBuffer b = ChannelBuffers.dynamicBuffer(length); mre.writeRequest(new ChannelBufferOutputStream(b)); nettyRequest.setContent(b); } } else if (request.getEntityWriter() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); + int length = computeAndSetContentLength(request, nettyRequest); - if (lenght == -1) { - lenght = MAX_BUFFERED_BYTES; + if (length == -1) { + length = MAX_BUFFERED_BYTES; } - ChannelBuffer b = ChannelBuffers.dynamicBuffer(lenght); + ChannelBuffer b = ChannelBuffers.dynamicBuffer(length); request.getEntityWriter().writeEntity(new ChannelBufferOutputStream(b)); nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); nettyRequest.setContent(b); @@ -1015,10 +1015,7 @@ private ListenableFuture doConnect(final Request request, final AsyncHand return c.future(); } - boolean directInvokation = true; - if (IN_IO_THREAD.get() && DefaultChannelFuture.isUseDeadLockChecker()) { - directInvokation = false; - } + boolean directInvokation = !(IN_IO_THREAD.get() && DefaultChannelFuture.isUseDeadLockChecker()); if (directInvokation && !asyncConnect && request.getFile() == null) { int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; From 0097294c72ccb6e36017f08dc56539723858f9dd Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 2 Aug 2013 13:56:06 +0200 Subject: [PATCH 0043/2389] Netty provider sends parts twice over https, port a29f682024b220438c55c4091010e1009e6936a3 to master --- .../multipart/MultipartRequestEntity.java | 15 ------- .../netty/NettyAsyncHttpProvider.java | 40 ++++--------------- 2 files changed, 8 insertions(+), 47 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java index 69689f675c..a3fcad60b6 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java @@ -124,20 +124,10 @@ public boolean isRepeatable() { return true; } - /* - * (non-Javadoc) - * - * @see org.apache.commons.httpclient.methods.RequestEntity#writeRequest(java.io.OutputStream) - */ public void writeRequest(OutputStream out) throws IOException { Part.sendParts(out, parts, multipartBoundary); } - /* - * (non-Javadoc) - * - * @see org.apache.commons.httpclient.methods.RequestEntity#getContentLength() - */ public long getContentLength() { try { return Part.getLengthOfParts(parts, multipartBoundary); @@ -147,11 +137,6 @@ public long getContentLength() { } } - /* - * (non-Javadoc) - * - * @see org.apache.commons.httpclient.methods.RequestEntity#getContentType() - */ public String getContentType() { return contentType; } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 4b9771c368..1d0657a11e 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -428,8 +428,10 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie } else { nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); } - } else { - body = null; + } else if (future.getRequest().getParts() != null) { + String contentType = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE); + String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH); + body = new MultipartBody(future.getRequest().getParts(), contentType, length); } } @@ -473,7 +475,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie ChannelFuture writeFuture; if (channel.getPipeline().get(SslHandler.class) != null) { - writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, 8192)); + writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, MAX_BUFFERED_BYTES)); } else { final FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); writeFuture = channel.write(region); @@ -497,15 +499,7 @@ public void operationComplete(ChannelFuture cf) { } throw ex; } - } else if (body != null || future.getRequest().getParts() != null) { - /** - * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements. - */ - if (future.getRequest().getParts() != null) { - String contentType = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_TYPE); - String length = future.getNettyRequest().getHeader(HttpHeaders.Names.CONTENT_LENGTH); - body = new MultipartBody(future.getRequest().getParts(), contentType, length); - } + } else if (body != null) { ChannelFuture writeFuture; if (channel.getPipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) { @@ -792,28 +786,13 @@ else if (uri.getRawQuery() != null) } } else if (request.getParts() != null) { - int length = computeAndSetContentLength(request, nettyRequest); - - if (length == -1) { - length = MAX_BUFFERED_BYTES; - } - MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength())); - /** - * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements. - */ - - if (isSecure(uri)) { - ChannelBuffer b = ChannelBuffers.dynamicBuffer(length); - mre.writeRequest(new ChannelBufferOutputStream(b)); - nettyRequest.setContent(b); - } } else if (request.getEntityWriter() != null) { - int length = computeAndSetContentLength(request, nettyRequest); + int length = getPredefinedContentLength(request, nettyRequest); if (length == -1) { length = MAX_BUFFERED_BYTES; @@ -1580,15 +1559,12 @@ protected static boolean abortOnWriteCloseException(Throwable cause) { return false; } - private final static int computeAndSetContentLength(Request request, HttpRequest r) { + private final static int getPredefinedContentLength(Request request, HttpRequest r) { int length = (int) request.getContentLength(); if (length == -1 && r.getHeader(HttpHeaders.Names.CONTENT_LENGTH) != null) { length = Integer.valueOf(r.getHeader(HttpHeaders.Names.CONTENT_LENGTH)); } - if (length >= 0) { - r.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length)); - } return length; } From db8bf694772912efe80afa95c50390103c76b63f Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 2 Aug 2013 13:58:59 +0200 Subject: [PATCH 0044/2389] Don't compute SSLContext over and over again, port e8d76624d3bf022e3601d0ed65c427afc338b0d8 to master --- .../org/asynchttpclient/util/SslUtils.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/util/SslUtils.java b/api/src/main/java/org/asynchttpclient/util/SslUtils.java index 2ac9769b18..c90c526309 100644 --- a/api/src/main/java/org/asynchttpclient/util/SslUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/SslUtils.java @@ -35,6 +35,8 @@ */ public class SslUtils { + private static SSLContext context = null; + public static SSLEngine getSSLEngine() throws GeneralSecurityException, IOException { SSLEngine engine = null; @@ -50,12 +52,16 @@ public static SSLEngine getSSLEngine() public static SSLContext getSSLContext() throws GeneralSecurityException, IOException { - SSLConfig config = new SSLConfig(); - if (config.keyStoreLocation == null || config.trustStoreLocation == null) { - return getLooseSSLContext(); - } else { - return getStrictSSLContext(config); - } + if (context == null) { + SSLConfig config = new SSLConfig(); + if (config.keyStoreLocation == null + || config.trustStoreLocation == null) { + context = getLooseSSLContext(); + } else { + context = getStrictSSLContext(config); + } + } + return context; } static SSLContext getStrictSSLContext(SSLConfig config) From b414b6df7467d1ecbfb96418d7b01e2221d658cb Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 2 Aug 2013 14:05:02 +0200 Subject: [PATCH 0045/2389] Minor clean up, port 1d965d7565ad8de0cd18ffb918243d0687cc21b3 to master --- .../providers/netty/NettyAsyncHttpProvider.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 1d0657a11e..e041258593 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -1332,7 +1332,7 @@ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws p.onClose(ctx, e); if (future != null && !future.isDone() && !future.isCancelled()) { - if (!remotelyClosed(ctx.getChannel(), future)) { + if (remotelyClosed(ctx.getChannel(), future)) { abort(future, new IOException("Remotely Closed")); } } else { @@ -1344,18 +1344,20 @@ public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) { if (isClose.get()) { - return false; + return true; } connectionsPool.removeAll(channel); - if (future == null && channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment() instanceof NettyResponseFuture) { - future = (NettyResponseFuture) channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); + if (future == null) { + Object attachment = channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); + if (attachment instanceof NettyResponseFuture) + future = (NettyResponseFuture) attachment; } if (future == null || future.cannotBeReplay()) { log.debug("Unable to recover future {}\n", future); - return false; + return true; } future.setState(NettyResponseFuture.STATE.RECONNECTED); @@ -1365,13 +1367,13 @@ protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) try { nextRequest(future.getRequest(), future); - return true; + return false; } catch (IOException iox) { future.setState(NettyResponseFuture.STATE.CLOSED); future.abort(iox); log.error("Remotely Closed, unable to recover", iox); } - return false; + return true; } private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { From 5179c5e4aff938447e7d325c7ef34499957734bb Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 09:15:07 -0700 Subject: [PATCH 0046/2389] Forward port PR #357. --- .../asynchttpclient/util/UTF8UrlEncoder.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/util/UTF8UrlEncoder.java b/api/src/main/java/org/asynchttpclient/util/UTF8UrlEncoder.java index 80b5ca4e8e..6e135ce29a 100644 --- a/api/src/main/java/org/asynchttpclient/util/UTF8UrlEncoder.java +++ b/api/src/main/java/org/asynchttpclient/util/UTF8UrlEncoder.java @@ -20,11 +20,12 @@ * (as per RFC-3986, see [http://www.ietf.org/rfc/rfc3986.txt]). */ public class UTF8UrlEncoder { - private static final boolean encodeSpaceUsingPlus = System.getProperty("com.UTF8UrlEncoder.encodeSpaceUsingPlus") == null ? false : true; + private static final boolean encodeSpaceUsingPlus = + System.getProperty("com.UTF8UrlEncoder.encodeSpaceUsingPlus") != null; /** * Encoding table used for figuring out ascii characters that must be escaped - * (all non-Ascii characers need to be encoded anyway) + * (all non-Ascii characters need to be encoded anyway) */ private final static int[] SAFE_ASCII = new int[128]; @@ -58,11 +59,11 @@ public static String encode(String input) { public static StringBuilder appendEncoded(StringBuilder sb, String input) { final int[] safe = SAFE_ASCII; - for (int i = 0, len = input.length(); i < len; ++i) { - char c = input.charAt(i); + for (int c, i = 0, len = input.length(); i < len; i+= Character.charCount(c)) { + c = input.codePointAt(i); if (c <= 127) { if (safe[c] != 0) { - sb.append(c); + sb.append((char) c); } else { appendSingleByteEncoded(sb, c); } @@ -73,7 +74,7 @@ public static StringBuilder appendEncoded(StringBuilder sb, String input) { return sb; } - private final static void appendSingleByteEncoded(StringBuilder sb, int value) { + private static void appendSingleByteEncoded(StringBuilder sb, int value) { if (encodeSpaceUsingPlus && value == 32) { sb.append('+'); @@ -85,15 +86,19 @@ private final static void appendSingleByteEncoded(StringBuilder sb, int value) { sb.append(HEX[value & 0xF]); } - private final static void appendMultiByteEncoded(StringBuilder sb, int value) { - // two or three bytes? (ignoring surrogate pairs for now, which would yield 4 bytes) + private static void appendMultiByteEncoded(StringBuilder sb, int value) { if (value < 0x800) { appendSingleByteEncoded(sb, (0xc0 | (value >> 6))); appendSingleByteEncoded(sb, (0x80 | (value & 0x3f))); - } else { + } else if (value < 0x10000) { appendSingleByteEncoded(sb, (0xe0 | (value >> 12))); appendSingleByteEncoded(sb, (0x80 | ((value >> 6) & 0x3f))); appendSingleByteEncoded(sb, (0x80 | (value & 0x3f))); + } else { + appendSingleByteEncoded(sb, (0xf0 | (value >> 18))); + appendSingleByteEncoded(sb, (0x80 | (value >> 12) & 0x3f)); + appendSingleByteEncoded(sb, (0x80 | (value >> 6) & 0x3f)); + appendSingleByteEncoded(sb, (0x80 | (value & 0x3f))); } } From 93b8b7b0dd1044cbe85ed9cb4d103aa0c84a481e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 12:11:28 -0700 Subject: [PATCH 0047/2389] Fix for #358. --- .../providers/grizzly/ConnectionManager.java | 59 +++++++++++++++++-- .../grizzly/GrizzlyHostnameVerifierTest.java | 27 +++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyHostnameVerifierTest.java diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 51fc80a169..89ee90d178 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -19,16 +19,21 @@ import org.asynchttpclient.Request; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.GrizzlyFuture; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.connectionpool.EndpointKey; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.ssl.SSLUtils; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.IdleTimeoutFilter; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; import java.io.IOException; +import java.net.ConnectException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; @@ -95,9 +100,10 @@ public void doTrackedConnection(final Request request, throws IOException { final EndpointKey key = getEndPointKey(request, requestFuture.getProxyServer()); - + CompletionHandler handler = + wrapHandler(request, getVerifier(), connectHandler); if (asyncConnect) { - connectionPool.take(key, connectHandler); + connectionPool.take(key, handler); } else { IOException ioe = null; GrizzlyFuture future = connectionPool.take(key); @@ -105,18 +111,18 @@ public void doTrackedConnection(final Request request, // No explicit timeout when calling get() here as the Grizzly // endpoint pool will time it out based on the connect timeout // setting. - connectHandler.completed(future.get()); + handler.completed(future.get()); } catch (CancellationException e) { - connectHandler.cancelled(); + handler.cancelled(); } catch (ExecutionException ee) { final Throwable cause = ee.getCause(); if (cause instanceof ConnectionPool.MaxCapacityException) { ioe = (IOException) cause; } else { - connectHandler.failed(ee.getCause()); + handler.failed(ee.getCause()); } } catch (Exception ie) { - connectHandler.failed(ie); + handler.failed(ie); } if (ioe != null) { throw ioe; @@ -136,6 +142,43 @@ public Connection obtainConnection(final Request request, // --------------------------------------------------Package Private Methods + static CompletionHandler wrapHandler(final Request request, + final HostnameVerifier verifier, + final CompletionHandler delegate) { + final URI uri = request.getURI(); + if (Utils.isSecure(uri) && verifier != null) { + return new EmptyCompletionHandler() { + @Override + public void completed(Connection result) { + final String host = uri.getHost(); + final SSLSession session = SSLUtils.getSSLEngine(result).getSession(); + if (!verifier.verify(host, session)) { + failed(new ConnectException("Host name verification failed for host " + host)); + } else { + delegate.completed(result); + } + + } + + @Override + public void cancelled() { + delegate.cancelled(); + } + + @Override + public void failed(Throwable throwable) { + delegate.failed(throwable); + } + + @Override + public void updated(Connection result) { + delegate.updated(result); + } + }; + } + return delegate; + } + static void markConnectionAsDoNotCache(final Connection c) { DO_NOT_CACHE.set(c, Boolean.TRUE); @@ -149,6 +192,10 @@ static boolean isConnectionCacheable(final Connection c) { // --------------------------------------------------------- Private Methods + private HostnameVerifier getVerifier() { + return provider.getClientConfig().getHostnameVerifier(); + } + private EndpointKey getEndPointKey(final Request request, final ProxyServer proxyServer) { final String stringKey = getPoolKey(request, proxyServer); diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyHostnameVerifierTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyHostnameVerifierTest.java new file mode 100644 index 0000000000..8bc8df9a7d --- /dev/null +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyHostnameVerifierTest.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2013 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.grizzly; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.async.HostnameVerifierTest; + +public class GrizzlyHostnameVerifierTest extends HostnameVerifierTest { + + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return GrizzlyProviderUtil.grizzlyProvider(config); + } + +} From 61451e09b42fba056c76fbb22a7c8289649b18bb Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 14:23:27 -0700 Subject: [PATCH 0048/2389] Fix for #192. --- .../asynchttpclient/AsyncHttpClientConfig.java | 15 +++++++++++++++ .../grizzly/GrizzlyAsyncHttpProvider.java | 10 +++++++--- .../providers/netty/NettyAsyncHttpProvider.java | 4 +++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 8e6cfa2d4c..2b8ca1c84d 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -106,6 +106,7 @@ public class AsyncHttpClientConfig { protected boolean allowSslConnectionPool; protected boolean useRawUrl; protected boolean removeQueryParamOnRedirect; + protected boolean managedApplicationThreadPool; protected HostnameVerifier hostnameVerifier; protected int ioThreadMultiplier; protected boolean strict302Handling; @@ -190,6 +191,7 @@ private AsyncHttpClientConfig(int maxTotalConnections, this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies; if (applicationThreadPool == null) { + managedApplicationThreadPool = true; this.applicationThreadPool = Executors.newCachedThreadPool(); } else { this.applicationThreadPool = applicationThreadPool; @@ -342,6 +344,19 @@ public ExecutorService executorService() { return applicationThreadPool; } + /** + * @return true if this AsyncHttpClientConfig instance created the + * {@link ExecutorService} returned by {@link #executorService()}, otherwise returns false. + * The return from this method is typically used by the various provider implementations to determine + * if it should shutdown the {@link ExecutorService} when the {@link AsyncHttpClient} is closed. Developers + * should take care and not share managed {@link ExecutorService} instances between client instances. + * + * @since 2.2.0 + */ + public boolean isManagedExecutorService() { + return managedApplicationThreadPool; + } + /** * An instance of {@link ProxyServer} used by an {@link AsyncHttpClient} * diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 6715dcca86..b44215b970 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -183,9 +183,13 @@ public void close() { try { connectionManager.destroy(); clientTransport.stop(); - final ExecutorService service = clientConfig.executorService(); - if (service != null) { - service.shutdown(); + if (clientConfig.isManagedExecutorService()) { + final ExecutorService service = clientConfig.executorService(); + // service may be null due to a custom configuration that + // leverages Grizzly's SameThreadIOStrategy. + if (service != null) { + service.shutdown(); + } } if (timeoutExecutor != null) { timeoutExecutor.stop(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index e041258593..61f89e3a73 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -828,7 +828,9 @@ public void close() { } } - config.executorService().shutdown(); + if (config.isManagedExecutorService()) { + config.executorService().shutdown(); + } config.reaper().shutdown(); if (this.allowReleaseSocketChannelFactory) { socketChannelFactory.releaseExternalResources(); From 8a67d4642029eafbbdd0f4053085871ad35c8069 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 16:01:57 -0700 Subject: [PATCH 0049/2389] - Return SPDY support to RUN status. + Still need to deal with connection pooling and SPDY connections. --- providers/grizzly/pom.xml | 2 +- .../providers/grizzly/EventHandler.java | 22 +++++++++---------- .../grizzly/GrizzlyAsyncHttpProvider.java | 2 +- .../providers/grizzly/Utils.java | 14 ++++++++---- .../filters/AsyncHttpClientFilter.java | 2 +- .../AHCWebSocketListenerAdapter.java | 2 +- .../GrizzlySimpleAsyncHttpClientTest.java | 20 +++++++++++++++++ 7 files changed, 44 insertions(+), 20 deletions(-) diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 796aa9ca6e..f7b481761c 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -14,7 +14,7 @@ - 2.3.4 + 2.3.6-SNAPSHOT 1.0 diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index e123e14ddd..ef1ed2688d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -45,7 +45,6 @@ import org.glassfish.grizzly.websockets.SimpleWebSocket; import org.glassfish.grizzly.websockets.WebSocketHolder; -import java.io.IOException; import java.net.URI; import java.util.HashMap; import java.util.List; @@ -358,8 +357,6 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, @SuppressWarnings("unchecked") public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) { - boolean result; - Utils.removeRequestInFlight(ctx.getConnection()); if (cleanup != null) { @@ -373,7 +370,6 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) return false; } - result = false; final HttpResponsePacket response = (HttpResponsePacket) httpHeader; final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); @@ -387,7 +383,6 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) context.getRequest(), context.getHandler(), context.getFuture()); - return result; } else { cleanup(ctx); final AsyncHandler handler = context.getHandler(); @@ -400,10 +395,10 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) } else { context.done(); } - return result; } + return false; } finally { - recycleRequestResponsePackets(response); + recycleRequestResponsePackets(ctx.getConnection(), response); } } @@ -411,11 +406,14 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) // ----------------------------------------------------- Private Methods - private static void recycleRequestResponsePackets(final HttpResponsePacket response) { - HttpRequestPacket request = response.getRequest(); - request.setExpectContent(false); - response.recycle(); - request.recycle(); + private static void recycleRequestResponsePackets(final Connection c, + final HttpResponsePacket response) { + if (!Utils.isSpdyConnection(c)) { + HttpRequestPacket request = response.getRequest(); + request.setExpectContent(false); + response.recycle(); + request.recycle(); + } } private static void processKeepAlive(final Connection c, diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index b44215b970..a74f593008 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -601,7 +601,7 @@ public String selectProtocol(SSLEngine engine, LinkedHashSet strings) { new SpdySession(connection, false, spdyHandlerFilter); spdySession.setLocalInitialWindowSize(spdyHandlerFilter.getInitialWindowSize()); spdySession.setLocalMaxConcurrentStreams(spdyHandlerFilter.getMaxConcurrentStreams()); - + Utils.setSpdyConnection(connection); SpdySession.bind(connection, spdySession); return SPDY; } else if (strings.contains(HTTP)) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java index 31b4dd48fa..b2a30ab7fa 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java @@ -27,6 +27,8 @@ public final class Utils { Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(Utils.class.getName() + "-IGNORE"); private static final Attribute REQUEST_IN_FLIGHT = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(Utils.class.getName() + "-IN-FLIGHT"); + private static final Attribute SPDY = + Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(Utils.class.getName() + "-SPDY-CONNECTION"); // ------------------------------------------------------------ Constructors @@ -38,10 +40,6 @@ private Utils() {} // ---------------------------------------------------------- Public Methods - public static boolean isSecure(final String uri) { - return (uri.startsWith("https:") || uri.startsWith("wss:")); - } - public static boolean isSecure(final URI uri) { final String scheme = uri.getScheme(); return ("https".equals(scheme) || "wss".equals(scheme)); @@ -81,4 +79,12 @@ public static int getRequestInFlightCount(final AttributeStorage storage) { AtomicInteger counter = REQUEST_IN_FLIGHT.get(storage); return ((counter != null) ? counter.get() : 0); } + + public static void setSpdyConnection(final Connection c) { + SPDY.set(c, Boolean.TRUE); + } + + public static boolean isSpdyConnection(final Connection c) { + return SPDY.get(c); + } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index bc1b7a172e..634e8a1a01 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -228,7 +228,7 @@ private boolean sendAsGrizzlyRequest(final Request request, if (httpCtx.isWSRequest() && !httpCtx.isEstablishingTunnel()) { try { final URI wsURI = new URI(httpCtx.getWsRequestURI()); - httpCtx.setProtocolHandler(Version.DRAFT17.createHandler(true)); + httpCtx.setProtocolHandler(Version.RFC6455.createHandler(true)); httpCtx.setHandshake( httpCtx.getProtocolHandler().createHandShake(wsURI)); requestPacket = (HttpRequestPacket) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java index ebbc1d7d96..931d53f2ed 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/websocket/AHCWebSocketListenerAdapter.java @@ -19,8 +19,8 @@ import org.asynchttpclient.websocket.WebSocketPingListener; import org.asynchttpclient.websocket.WebSocketPongListener; import org.asynchttpclient.websocket.WebSocketTextListener; +import org.glassfish.grizzly.websockets.ClosingFrame; import org.glassfish.grizzly.websockets.DataFrame; -import org.glassfish.grizzly.websockets.draft06.ClosingFrame; import java.io.ByteArrayOutputStream; diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java index dbd541b93b..45296b19d2 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java @@ -13,10 +13,18 @@ package org.asynchttpclient.providers.grizzly; +import org.asynchttpclient.AsyncCompletionHandler; +import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; import org.asynchttpclient.async.SimpleAsyncHttpClientTest; +import java.io.IOException; +import java.util.concurrent.Future; + public class GrizzlySimpleAsyncHttpClientTest extends SimpleAsyncHttpClientTest { @Override @@ -27,4 +35,16 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return GrizzlyAsyncHttpProvider.class.getName(); } + + public static void main(String[] args) { + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setSpdyEnabled(true).build(); + AsyncHttpClient client = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config); + Request request = new RequestBuilder("GET").setUrl("https://www.google.com/").build(); + try { + Future future = client.executeRequest(request); + System.out.println(future.get().toString()); + } catch (Exception e) { + e.printStackTrace(); + } + } } From d56735fe3d69a5ddfea00ba2e697fc51657d62ba Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 16:02:43 -0700 Subject: [PATCH 0050/2389] - remove unintended changes. --- .../grizzly/GrizzlySimpleAsyncHttpClientTest.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java index 45296b19d2..af99dd39fb 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java @@ -36,15 +36,4 @@ public String getProviderClass() { return GrizzlyAsyncHttpProvider.class.getName(); } - public static void main(String[] args) { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setSpdyEnabled(true).build(); - AsyncHttpClient client = new AsyncHttpClient(new GrizzlyAsyncHttpProvider(config), config); - Request request = new RequestBuilder("GET").setUrl("https://www.google.com/").build(); - try { - Future future = client.executeRequest(request); - System.out.println(future.get().toString()); - } catch (Exception e) { - e.printStackTrace(); - } - } } From c717f06a06f0a8c2af9bde89d17c32e9be62c23a Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 12 Aug 2013 16:18:41 -0700 Subject: [PATCH 0051/2389] - Fix test failure. --- .../main/java/org/asynchttpclient/providers/grizzly/Utils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java index b2a30ab7fa..3426376ee7 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java @@ -85,6 +85,7 @@ public static void setSpdyConnection(final Connection c) { } public static boolean isSpdyConnection(final Connection c) { - return SPDY.get(c); + Boolean result = SPDY.get(c); + return (result != null ? result : false); } } From 2326e09595ba62f76fff12a2ef2e4f798dbd8c93 Mon Sep 17 00:00:00 2001 From: James Roper Date: Mon, 19 Aug 2013 14:42:49 +1000 Subject: [PATCH 0052/2389] Provided ability to use JDK ProxySelector Fixes #360. * Adds a useProxySelector option that tells async-http-client to use the JDK default ProxySelector. * Adds a ProxyServerSelector interface that AsyncHttpClientConfig and ProxyUtils now use. --- .../AsyncHttpClientConfig.java | 63 +++++++++--- .../AsyncHttpClientConfigBean.java | 14 ++- .../asynchttpclient/ProxyServerSelector.java | 27 ++++++ .../org/asynchttpclient/util/ProxyUtils.java | 96 +++++++++++++++++-- .../org/asynchttpclient/async/ProxyTest.java | 80 +++++++++++++++- .../ProxyAuthorizationHandler.java | 3 +- site/src/site/apt/proxy.apt | 23 +++++ 7 files changed, 277 insertions(+), 29 deletions(-) create mode 100644 api/src/main/java/org/asynchttpclient/ProxyServerSelector.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 2b8ca1c84d..79143d1b00 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -92,7 +92,7 @@ public class AsyncHttpClientConfig { protected boolean allowPoolingConnection; protected ScheduledExecutorService reaper; protected ExecutorService applicationThreadPool; - protected ProxyServer proxyServer; + protected ProxyServerSelector proxyServerSelector; protected SSLContext sslContext; protected SSLEngineFactory sslEngineFactory; protected AsyncHttpProviderConfig providerConfig; @@ -136,7 +136,7 @@ private AsyncHttpClientConfig(int maxTotalConnections, boolean keepAlive, ScheduledExecutorService reaper, ExecutorService applicationThreadPool, - ProxyServer proxyServer, + ProxyServerSelector proxyServerSelector, SSLContext sslContext, SSLEngineFactory sslEngineFactory, AsyncHttpProviderConfig providerConfig, @@ -196,7 +196,7 @@ private AsyncHttpClientConfig(int maxTotalConnections, } else { this.applicationThreadPool = applicationThreadPool; } - this.proxyServer = proxyServer; + this.proxyServerSelector = proxyServerSelector; this.useRawUrl = useRawUrl; this.spdyEnabled = spdyEnabled; this.spdyInitialWindowSize = spdyInitialWindowSize; @@ -362,8 +362,8 @@ public boolean isManagedExecutorService() { * * @return instance of {@link ProxyServer} */ - public ProxyServer getProxyServer() { - return proxyServer; + public ProxyServerSelector getProxyServerSelector() { + return proxyServerSelector; } /** @@ -613,11 +613,12 @@ public static class Builder { private boolean compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled"); private String userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "AsyncHttpClient/" + AHC_VERSION); private boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties"); + private boolean useProxySelector = Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector"); private boolean allowPoolingConnection = true; private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies"); private ScheduledExecutorService reaper; private ExecutorService applicationThreadPool; - private ProxyServer proxyServer = null; + private ProxyServerSelector proxyServerSelector = null; private SSLContext sslContext; private SSLEngineFactory sslEngineFactory; private AsyncHttpProviderConfig providerConfig; @@ -816,6 +817,17 @@ public Builder setExecutorService(ExecutorService applicationThreadPool) { return this; } + /** + * Set an instance of {@link ProxyServerSelector} used by an {@link AsyncHttpClient} + * + * @param proxyServerSelector instance of {@link ProxyServerSelector} + * @return a {@link Builder} + */ + public Builder setProxyServerSelector(ProxyServerSelector proxyServerSelector) { + this.proxyServerSelector = proxyServerSelector; + return this; + } + /** * Set an instance of {@link ProxyServer} used by an {@link AsyncHttpClient} * @@ -823,7 +835,7 @@ public Builder setExecutorService(ExecutorService applicationThreadPool) { * @return a {@link Builder} */ public Builder setProxyServer(ProxyServer proxyServer) { - this.proxyServer = proxyServer; + this.proxyServerSelector = ProxyUtils.createProxyServerSelector(proxyServer); return this; } @@ -1024,12 +1036,27 @@ public Builder setRemoveQueryParamsOnRedirect(boolean removeQueryParamOnRedirect return this; } + /** + * Sets whether AHC should use the default JDK ProxySelector to select a proxy server. + *

+ * If useProxySelector is set to true but {@link #setProxyServer(ProxyServer)} + * was used to explicitly set a proxy server, the latter is preferred. + *

+ * See http://docs.oracle.com/javase/7/docs/api/java/net/ProxySelector.html + */ + public Builder setUseProxySelector(boolean useProxySelector) { + this.useProxySelector = useProxySelector; + return this; + } + /** * Sets whether AHC should use the default http.proxy* system properties - * to obtain proxy information. + * to obtain proxy information. This differs from {@link #setUseProxySelector(boolean)} + * in that AsyncHttpClient will use its own logic to handle the system properties, + * potentially supporting other protocols that the the JDK ProxySelector doesn't. *

- * If useProxyProperties is set to true but {@link #setProxyServer(ProxyServer)} was used - * to explicitly set a proxy server, the latter is preferred. + * If useProxyProperties is set to true but {@link #setUseProxySelector(boolean)} + * was also set to true, the latter is preferred. *

* See http://download.oracle.com/javase/1.4.2/docs/guide/net/properties.html */ @@ -1182,7 +1209,7 @@ public Builder(AsyncHttpClientConfig prototype) { defaultMaxConnectionLifeTimeInMs = prototype.getMaxConnectionLifeTimeInMs(); maxDefaultRedirects = prototype.getMaxRedirects(); defaultMaxTotalConnections = prototype.getMaxTotalConnections(); - proxyServer = prototype.getProxyServer(); + proxyServerSelector = prototype.getProxyServerSelector(); realm = prototype.getRealm(); defaultRequestTimeoutInMs = prototype.getRequestTimeoutInMs(); sslContext = prototype.getSSLContext(); @@ -1248,8 +1275,16 @@ public Thread newThread(Runnable r) { throw new IllegalStateException("ExecutorServices closed"); } - if (proxyServer == null && useProxyProperties) { - proxyServer = ProxyUtils.createProxy(System.getProperties()); + if (proxyServerSelector == null && useProxySelector) { + proxyServerSelector = ProxyUtils.getJdkDefaultProxyServerSelector(); + } + + if (proxyServerSelector == null && useProxyProperties) { + proxyServerSelector = ProxyUtils.createProxyServerSelector(System.getProperties()); + } + + if (proxyServerSelector == null) { + proxyServerSelector = ProxyServerSelector.NO_PROXY_SELECTOR; } return new AsyncHttpClientConfig(defaultMaxTotalConnections, @@ -1267,7 +1302,7 @@ public Thread newThread(Runnable r) { allowPoolingConnection, reaper, applicationThreadPool, - proxyServer, + proxyServerSelector, sslContext, sslEngineFactory, providerConfig, diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java index 4e48491b34..9a7d75bf47 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java @@ -55,9 +55,12 @@ void configureDefaults() { compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled"); userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "AsyncHttpClient/" + AHC_VERSION); + boolean useProxySelector = Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector"); boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties"); - if (useProxyProperties) { - proxyServer = ProxyUtils.createProxy(System.getProperties()); + if (useProxySelector) { + proxyServerSelector = ProxyUtils.getJdkDefaultProxyServerSelector(); + } else if (useProxyProperties) { + proxyServerSelector = ProxyUtils.createProxyServerSelector(System.getProperties()); } allowPoolingConnection = true; @@ -163,7 +166,12 @@ public AsyncHttpClientConfigBean setApplicationThreadPool(ExecutorService applic } public AsyncHttpClientConfigBean setProxyServer(ProxyServer proxyServer) { - this.proxyServer = proxyServer; + this.proxyServerSelector = ProxyUtils.createProxyServerSelector(proxyServer); + return this; + } + + public AsyncHttpClientConfigBean setProxyServerSelector(ProxyServerSelector proxyServerSelector) { + this.proxyServerSelector = proxyServerSelector; return this; } diff --git a/api/src/main/java/org/asynchttpclient/ProxyServerSelector.java b/api/src/main/java/org/asynchttpclient/ProxyServerSelector.java new file mode 100644 index 0000000000..b883b1fcf9 --- /dev/null +++ b/api/src/main/java/org/asynchttpclient/ProxyServerSelector.java @@ -0,0 +1,27 @@ +package org.asynchttpclient; + +import java.net.URI; + +/** + * Selector for a proxy server + */ +public interface ProxyServerSelector { + + /** + * Select a proxy server to use for the given URI. + * + * @param uri The URI to select a proxy server for. + * @return The proxy server to use, if any. May return null. + */ + ProxyServer select(URI uri); + + /** + * A selector that always selects no proxy. + */ + static final ProxyServerSelector NO_PROXY_SELECTOR = new ProxyServerSelector() { + @Override + public ProxyServer select(URI uri) { + return null; + } + }; +} diff --git a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java index 6e33588f6e..612642b524 100644 --- a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java @@ -14,13 +14,21 @@ import static org.asynchttpclient.util.MiscUtil.isNonEmpty; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.URI; import java.util.List; +import java.util.Locale; import java.util.Properties; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.ProxyServer.Protocol; +import org.asynchttpclient.ProxyServerSelector; import org.asynchttpclient.Request; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Utilities for Proxy handling. @@ -29,6 +37,8 @@ */ public class ProxyUtils { + private final static Logger log = LoggerFactory.getLogger(ProxyUtils.class); + private static final String PROPERTY_PREFIX = "org.asynchttpclient.AsyncHttpClientConfig.proxy."; /** @@ -69,7 +79,10 @@ public class ProxyUtils { public static ProxyServer getProxyServer(AsyncHttpClientConfig config, Request request) { ProxyServer proxyServer = request.getProxyServer(); if (proxyServer == null) { - proxyServer = config.getProxyServer(); + ProxyServerSelector selector = config.getProxyServerSelector(); + if (selector != null) { + proxyServer = selector.select(request.getOriginalURI()); + } } return ProxyUtils.avoidProxy(proxyServer, request) ? null : proxyServer; } @@ -107,7 +120,10 @@ public static boolean avoidProxy(final ProxyServer proxyServer, final String tar if (isNonEmpty(nonProxyHosts)) { for (String nonProxyHost : nonProxyHosts) { if (nonProxyHost.startsWith("*") && nonProxyHost.length() > 1 - && targetHost.endsWith(nonProxyHost.substring(1).toLowerCase())) { + && targetHost.endsWith(nonProxyHost.substring(1).toLowerCase(Locale.ENGLISH))) { + return true; + } else if (nonProxyHost.endsWith("*") && nonProxyHost.length() > 1 + && targetHost.startsWith(nonProxyHost.substring(0, nonProxyHost.length() - 1).toLowerCase(Locale.ENGLISH))) { return true; } else if (nonProxyHost.equalsIgnoreCase(targetHost)) { return true; @@ -134,31 +150,91 @@ public static boolean avoidProxy(final ProxyServer proxyServer, final String tar * @see #PROXY_PROTOCOL * @see #PROXY_NONPROXYHOSTS */ - public static ProxyServer createProxy(Properties properties) { - String host = System.getProperty(PROXY_HOST); + public static ProxyServerSelector createProxyServerSelector(Properties properties) { + String host = properties.getProperty(PROXY_HOST); if (host != null) { - int port = Integer.valueOf(System.getProperty(PROXY_PORT, "80")); + int port = Integer.valueOf(properties.getProperty(PROXY_PORT, "80")); Protocol protocol; try { - protocol = Protocol.valueOf(System.getProperty(PROXY_PROTOCOL, "HTTP")); + protocol = Protocol.valueOf(properties.getProperty(PROXY_PROTOCOL, "HTTP")); } catch (IllegalArgumentException e) { protocol = Protocol.HTTP; } - ProxyServer proxyServer = new ProxyServer(protocol, host, port, System.getProperty(PROXY_USER), System.getProperty(PROXY_PASSWORD)); + ProxyServer proxyServer = new ProxyServer(protocol, host, port, properties.getProperty(PROXY_USER), + properties.getProperty(PROXY_PASSWORD)); - String nonProxyHosts = System.getProperties().getProperty(PROXY_NONPROXYHOSTS); + String nonProxyHosts = properties.getProperty(PROXY_NONPROXYHOSTS); if (nonProxyHosts != null) { for (String spec : nonProxyHosts.split("\\|")) { proxyServer.addNonProxyHost(spec); } } - return proxyServer; + return createProxyServerSelector(proxyServer); } - return null; + return ProxyServerSelector.NO_PROXY_SELECTOR; + } + + /** + * Get a proxy server selector based on the JDK default proxy selector. + * + * @return The proxy server selector. + */ + public static ProxyServerSelector getJdkDefaultProxyServerSelector() { + return createProxyServerSelector(ProxySelector.getDefault()); + } + + /** + * Create a proxy server selector based on the passed in JDK proxy selector. + * + * @param proxySelector The proxy selector to use. Must not be null. + * @return The proxy server selector. + */ + public static ProxyServerSelector createProxyServerSelector(final ProxySelector proxySelector) { + return new ProxyServerSelector() { + @Override + public ProxyServer select(URI uri) { + List proxies = proxySelector.select(uri); + if (proxies != null) { + // Loop through them until we find one that we know how to use + for (Proxy proxy : proxies) { + switch (proxy.type()) { + case HTTP: + if (!(proxy.address() instanceof InetSocketAddress)) { + log.warn("Don't know how to connect to address " + proxy.address()); + } else { + InetSocketAddress address = (InetSocketAddress) proxy.address(); + return new ProxyServer(Protocol.HTTP, address.getHostString(), address.getPort()); + } + case DIRECT: + return null; + default: + log.warn("ProxySelector returned proxy type that we don't know how to use: " + proxy.type()); + break; + } + } + } + return null; + } + }; + } + + /** + * Create a proxy server selector that always selects a single proxy server. + * + * @param proxyServer The proxy server to select. + * @return The proxy server selector. + */ + public static ProxyServerSelector createProxyServerSelector(final ProxyServer proxyServer) { + return new ProxyServerSelector() { + @Override + public ProxyServer select(URI uri) { + return proxyServer; + } + }; } } diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java index 94ee870f84..1af6c073f1 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java @@ -16,6 +16,7 @@ package org.asynchttpclient.async; import static org.testng.Assert.*; +import static org.testng.Assert.assertEquals; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -23,7 +24,9 @@ import org.asynchttpclient.Response; import java.io.IOException; -import java.net.ConnectException; +import java.net.*; +import java.util.Arrays; +import java.util.List; import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -249,4 +252,79 @@ public void testProxyActivationProperty() throws IOException, ExecutionException } } + @Test(groups = { "standalone", "default_provider" }) + public void testWildcardNonProxyHosts() throws IOException, ExecutionException, TimeoutException, InterruptedException { + Properties originalProps = System.getProperties(); + try { + Properties props = new Properties(); + props.putAll(originalProps); + + System.setProperties(props); + + System.setProperty("http.proxyHost", "127.0.0.1"); + System.setProperty("http.proxyPort", String.valueOf(port1)); + System.setProperty("http.nonProxyHosts", "127.*"); + + AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setUseProxyProperties(true).build(); + AsyncHttpClient client = getAsyncHttpClient(cfg); + try { + String target = "http://127.0.0.1:1234/"; + Future f = client.prepareGet(target).execute(); + try { + f.get(3, TimeUnit.SECONDS); + fail("should not be able to connect"); + } catch (ExecutionException e) { + // ok, no proxy used + } + } finally { + client.close(); + } + } finally { + System.setProperties(originalProps); + } + } + + @Test(groups = { "standalone", "default_provider" }) + public void testUseProxySelector() throws IOException, ExecutionException, TimeoutException, InterruptedException { + ProxySelector originalProxySelector = ProxySelector.getDefault(); + try { + ProxySelector.setDefault(new ProxySelector() { + public List select(URI uri) { + if (uri.getHost().equals("127.0.0.1")) { + return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", port1))); + } else { + return Arrays.asList(Proxy.NO_PROXY); + } + } + + public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + } + }); + + AsyncHttpClientConfig cfg = new AsyncHttpClientConfig.Builder().setUseProxySelector(true).build(); + AsyncHttpClient client = getAsyncHttpClient(cfg); + try { + String target = "http://127.0.0.1:1234/"; + Future f = client.prepareGet(target).execute(); + Response resp = f.get(3, TimeUnit.SECONDS); + assertNotNull(resp); + assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); + assertEquals(resp.getHeader("target"), "/"); + + target = "http://localhost:1234/"; + f = client.prepareGet(target).execute(); + try { + f.get(3, TimeUnit.SECONDS); + fail("should not be able to connect"); + } catch (ExecutionException e) { + // ok, no proxy used + } + } finally { + client.close(); + } + } finally { + ProxySelector.setDefault(originalProxySelector); + } + } + } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index f2a156592e..d65a596ac6 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -65,7 +65,8 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, final Request req = httpTransactionContext.getRequest(); ProxyServer proxyServer = httpTransactionContext.getProvider() .getClientConfig() - .getProxyServer(); + .getProxyServerSelector() + .select(req.getOriginalURI()); String principal = proxyServer.getPrincipal(); String password = proxyServer.getPassword(); Realm realm = new Realm.RealmBuilder().setPrincipal(principal) diff --git a/site/src/site/apt/proxy.apt b/site/src/site/apt/proxy.apt index d62a0ebb48..a09932fc0e 100644 --- a/site/src/site/apt/proxy.apt +++ b/site/src/site/apt/proxy.apt @@ -61,3 +61,26 @@ Response r = responseFuture.get(); You can also set the <<>> at the <<>> level. In that case, all request will share the same proxy information. + +Using Java System Properties + + The AsyncHttpClient library supports the standard + {{{http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html#Proxies}Java Proxy System Properties}}. + You can configure this at a global level using the <<>> method on the + <<>>, or by setting the <<>> + system property to true. + +Using JDK ProxySelectors + + The AsyncHttpClient library also supports using the default + {{{http://docs.oracle.com/javase/7/docs/api/java/net/ProxySelector.html}JDK ProxySelector}}. This allows for more + fine grained control over which proxies to use, for example, it can be used in combination with + {{{https://code.google.com/p/proxy-vole/}Proxy Vole}} to use OS configured proxies or to use a proxy.pac file. + + You configure this at a global level using the <<>> method on the + <<>>, or by setting the + <<>> system property to true. + + If you don't change the default JDK <<>>, this setting is very similar to the <<>> + setting, though the <<>> setting does allow more flexibility, such as the ability to use an + HTTPS proxy. \ No newline at end of file From 4dd71c30fec339655413c17c9caa521596e991bd Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 21 Aug 2013 20:33:21 -0700 Subject: [PATCH 0053/2389] - Updates for 2.3.6. --- .../providers/grizzly/ProxyAwareConnectorHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index 7d9744ce1b..abf27dc5e0 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -109,7 +109,6 @@ public static final class Builder extends TCPNIOConnectorHandler.Builder { private Builder(final TCPNIOTransport transport) { - super(transport); connectorHandler = new ProxyAwareConnectorHandler(transport); } From 9c2fc939364d2c7ad21a5f6503e0cf4bdfc6559b Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 22 Aug 2013 09:56:02 -0700 Subject: [PATCH 0054/2389] - Delay when we do the conversion of byte[]->String. Offered a 6-7% speed increase. --- .../grizzly/GrizzlyResponseHeaders.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java index 4352a51a9b..588c33ca50 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java @@ -32,8 +32,9 @@ */ class GrizzlyResponseHeaders extends HttpResponseHeaders { - private final FluentCaseInsensitiveStringsMap headers = - new FluentCaseInsensitiveStringsMap(); + private FluentCaseInsensitiveStringsMap headers; + private MimeHeaders grizzlyHeaders; + // ------------------------------------------------------------ Constructors @@ -43,12 +44,8 @@ public GrizzlyResponseHeaders(final HttpResponsePacket response, final AsyncHttpProvider provider) { super(uri, provider); - final MimeHeaders headersLocal = response.getHeaders(); - for (String name : headersLocal.names()) { - for (String header : headersLocal.values(name)) { - headers.add(name, header); - } - } + grizzlyHeaders = new MimeHeaders(); + grizzlyHeaders.copyFrom(response.getHeaders()); } @@ -60,7 +57,15 @@ public GrizzlyResponseHeaders(final HttpResponsePacket response, * {@inheritDoc} */ @Override - public FluentCaseInsensitiveStringsMap getHeaders() { + public synchronized FluentCaseInsensitiveStringsMap getHeaders() { + if (headers == null) { + headers = new FluentCaseInsensitiveStringsMap(); + for (String name : grizzlyHeaders.names()) { + for (String header : grizzlyHeaders.values(name)) { + headers.add(name, header); + } + } + } return headers; } From b161d8e5119f1f1d5f15e8e830144fde979999b9 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 22 Aug 2013 09:58:08 -0700 Subject: [PATCH 0055/2389] - Refactor builder method names. --- .../providers/grizzly/ConnectionManager.java | 22 ++++++++++--------- .../grizzly/ProxyAwareConnectorHandler.java | 10 ++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index 89ee90d178..fbb65ee3e5 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -214,11 +214,13 @@ private EndpointKey getEndPointKey(final Request request, ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler .builder(provider.clientTransport) - .setNonSecureFilterChainTemplate(nonSecureBuilder) - .setSecureFilterChainTemplate(secureBuilder) - .setAsyncHttpClientConfig(provider.getClientConfig()) - .setURI(request.getURI()) - .setProxyServer(proxyServer) + .nonSecureFilterChainTemplate( + nonSecureBuilder) + .secureFilterChainTemplate(secureBuilder) + .asyncHttpClientConfig( + provider.getClientConfig()) + .uri(request.getURI()) + .proxyServer(proxyServer) .build(); EndpointKey localKey = new EndpointKey(stringKey, @@ -273,11 +275,11 @@ private Connection obtainConnection0(final Request request, final SocketAddress address = getRemoteAddress(request, proxyServer); ProxyAwareConnectorHandler handler = ProxyAwareConnectorHandler .builder(provider.clientTransport) - .setNonSecureFilterChainTemplate(nonSecureBuilder) - .setSecureFilterChainTemplate(secureBuilder) - .setAsyncHttpClientConfig(provider.getClientConfig()) - .setURI(request.getURI()) - .setProxyServer(proxyServer) + .nonSecureFilterChainTemplate(nonSecureBuilder) + .secureFilterChainTemplate(secureBuilder) + .asyncHttpClientConfig(provider.getClientConfig()) + .uri(request.getURI()) + .proxyServer(proxyServer) .build(); if (cTimeout > 0) { handler.connect(address, ch); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java index abf27dc5e0..f7accfa634 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ProxyAwareConnectorHandler.java @@ -116,27 +116,27 @@ private Builder(final TCPNIOTransport transport) { // ----------------------------------------------------- Builder Methods - public Builder setSecureFilterChainTemplate(final FilterChainBuilder secureTemplate) { + public Builder secureFilterChainTemplate(final FilterChainBuilder secureTemplate) { connectorHandler.secureTemplate = secureTemplate; return this; } - public Builder setNonSecureFilterChainTemplate(final FilterChainBuilder nonSecureTemplate) { + public Builder nonSecureFilterChainTemplate(final FilterChainBuilder nonSecureTemplate) { connectorHandler.nonSecureTemplate = nonSecureTemplate; return this; } - public Builder setAsyncHttpClientConfig(final AsyncHttpClientConfig clientConfig) { + public Builder asyncHttpClientConfig(final AsyncHttpClientConfig clientConfig) { connectorHandler.clientConfig = clientConfig; return this; } - public Builder setURI(final URI uri) { + public Builder uri(final URI uri) { connectorHandler.uri = uri; return this; } - public Builder setProxyServer(final ProxyServer proxyServer) { + public Builder proxyServer(final ProxyServer proxyServer) { connectorHandler.proxyServer = proxyServer; return this; } From adc88eee0c89bd198a81946760b9cbaaab2271d9 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 22 Aug 2013 12:37:35 -0700 Subject: [PATCH 0056/2389] Defer creation of composite buffer until the body is needed. --- .../providers/grizzly/GrizzlyResponse.java | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java index 25aed32698..fd2ca67a3a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java @@ -45,9 +45,13 @@ * @since 1.7.0 */ public class GrizzlyResponse extends ResponseBase { - private final Buffer responseBody; + private final Boolean rfc6265Enabled; + private Buffer responseBody; + private boolean initialized; + + // ------------------------------------------------------------ Constructors @@ -57,27 +61,11 @@ public GrizzlyResponse(final HttpResponseStatus status, final boolean rfc6265Enabled) { super(status, headers, bodyParts); this.rfc6265Enabled = rfc6265Enabled; - if (isNonEmpty(bodyParts)) { - if (bodyParts.size() == 1) { - responseBody = ((GrizzlyResponseBodyPart) bodyParts.get(0)).getBodyBuffer(); - } else { - final Buffer firstBuffer = ((GrizzlyResponseBodyPart) bodyParts.get(0)).getBodyBuffer(); - final MemoryManager mm = MemoryManager.DEFAULT_MEMORY_MANAGER; - Buffer constructedBodyBuffer = firstBuffer; - for (int i = 1, len = bodyParts.size(); i < len; i++) { - constructedBodyBuffer = - Buffers.appendBuffers(mm, - constructedBodyBuffer, - ((GrizzlyResponseBodyPart) bodyParts.get(i)).getBodyBuffer()); - } - responseBody = constructedBodyBuffer; - } - } else { - responseBody = Buffers.EMPTY_BUFFER; - } } + + // --------------------------------------------------- Methods from Response /** @@ -85,7 +73,7 @@ public GrizzlyResponse(final HttpResponseStatus status, */ public InputStream getResponseBodyAsStream() throws IOException { - return new BufferInputStream(responseBody); + return new BufferInputStream(getResponseBody0()); } @@ -95,6 +83,7 @@ public InputStream getResponseBodyAsStream() throws IOException { */ public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException { charset = calculateCharset(charset); + final Buffer responseBody = getResponseBody0(); final int len = Math.min(responseBody.remaining(), maxLength); final int pos = responseBody.position(); return responseBody.toStringContent(getCharset(charset), pos, len + pos); @@ -107,7 +96,7 @@ public String getResponseBodyExcerpt(int maxLength, String charset) throws IOExc */ public String getResponseBody(String charset) throws IOException { - return responseBody.toStringContent(getCharset(charset)); + return getResponseBody0().toStringContent(getCharset(charset)); } @@ -149,7 +138,7 @@ public String getResponseBody() throws IOException { */ @SuppressWarnings("UnusedDeclaration") public Buffer getResponseBodyAsBuffer() { - return responseBody; + return getResponseBody0(); } /** @@ -215,4 +204,34 @@ private Charset getCharset(final String charset) { return Charsets.lookupCharset(charsetLocal); } + + private synchronized Buffer getResponseBody0() { + if (!initialized) { + if (isNonEmpty(bodyParts)) { + if (bodyParts.size() == 1) { + responseBody = ((GrizzlyResponseBodyPart) bodyParts.get( + 0)).getBodyBuffer(); + } else { + final Buffer firstBuffer = + ((GrizzlyResponseBodyPart) bodyParts.get( + 0)).getBodyBuffer(); + final MemoryManager mm = + MemoryManager.DEFAULT_MEMORY_MANAGER; + Buffer constructedBodyBuffer = firstBuffer; + for (int i = 1, len = bodyParts.size(); i < len; i++) { + constructedBodyBuffer = + Buffers.appendBuffers(mm, + constructedBodyBuffer, + ((GrizzlyResponseBodyPart) bodyParts + .get(i)).getBodyBuffer()); + } + responseBody = constructedBodyBuffer; + } + } else { + responseBody = Buffers.EMPTY_BUFFER; + } + initialized = true; + } + return responseBody; + } } From bf575f6f040a1f2522a3a62aeaa5c4cbda8649e3 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 23 Aug 2013 11:04:12 -0700 Subject: [PATCH 0057/2389] - Add methods to ClientConfig to be able to determine if any {Request,Reponse}Filters have been registered. - Avoid unnecessary iterator creation. --- .../org/asynchttpclient/AsyncHttpClient.java | 23 +++++++++------- .../AsyncHttpClientConfig.java | 17 ++++++++++++ .../providers/grizzly/EventHandler.java | 17 +++++++----- .../providers/grizzly/GrizzlyResponse.java | 10 ++++--- .../bodyhandler/BodyHandlerFactory.java | 3 ++- .../bodyhandler/ParamsBodyHandler.java | 3 ++- .../filters/AsyncHttpClientFilter.java | 27 ++++++++++--------- 7 files changed, 66 insertions(+), 34 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 7ed810960d..4a8661a3b5 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.Collection; +import java.util.List; import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; @@ -592,16 +593,20 @@ public ListenableFuture executeRequest(Request request) throws IOExcep * @return {@link FilterContext} */ private FilterContext preProcessRequest(FilterContext fc) throws IOException { - for (RequestFilter asyncFilter : config.getRequestFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); + if (config.hasRequestFilters()) { + final List requestFilters = config.getRequestFilters(); + for (int i = 0, len = requestFilters.size(); i < len; i++) { + final RequestFilter asyncFilter = requestFilters.get(i); + try { + fc = asyncFilter.filter(fc); + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException e) { + IOException ex = new IOException(); + ex.initCause(e); + throw ex; } - } catch (FilterException e) { - IOException ex = new IOException(); - ex.initCause(e); - throw ex; } } diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 79143d1b00..d40e7c4f6d 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -424,6 +424,15 @@ public Realm getRealm() { return realm; } + /** + * @return true if {@link RequestFilter}s have been defined. + * + * @since 2.0.0 + */ + public boolean hasRequestFilters() { + return !requestFilters.isEmpty(); + } + /** * Return the list of {@link RequestFilter} * @@ -433,6 +442,14 @@ public List getRequestFilters() { return Collections.unmodifiableList(requestFilters); } + /** + * @return true if {@link ResponseFilter}s have been defined. + * @since 2.0.0 + */ + public boolean hasResponseFilters() { + return !requestFilters.isEmpty(); + } + /** * Return the list of {@link ResponseFilter} * diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index ef1ed2688d..f0add9b4b7 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -245,19 +245,20 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, } final AsyncHandler handler = context.getHandler(); - final List filters = context.getProvider() - .getClientConfig().getResponseFilters(); final GrizzlyResponseHeaders responseHeaders = new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader, context.getRequest().getURI(), provider); - if (!filters.isEmpty()) { + if (context.getProvider().getClientConfig().hasResponseFilters()) { + final List filters = context.getProvider() + .getClientConfig().getResponseFilters(); FilterContext fc = new FilterContext.FilterContextBuilder() .asyncHandler(handler).request(context.getRequest()) .responseHeaders(responseHeaders) .responseStatus(context.getResponseStatus()).build(); try { - for (final ResponseFilter f : filters) { + for (int i = 0, len = filters.size(); i < len; i++) { + final ResponseFilter f = filters.get(i); fc = f.filter(fc); } } catch (Exception e) { @@ -514,9 +515,11 @@ public static Request newRequest(final URI uri, if (ctx.getProvider().getClientConfig().isRemoveQueryParamOnRedirect()) { builder.setQueryParameters(null); } - for (String cookieStr : response.getHeaders().values(Header.Cookie)) { - for (Cookie c : CookieDecoder.decode(cookieStr)) { - builder.addOrReplaceCookie(c); + if (response.getHeader(Header.Cookie) != null) { + for (String cookieStr : response.getHeaders().values(Header.Cookie)) { + for (Cookie c : CookieDecoder.decode(cookieStr)) { + builder.addOrReplaceCookie(c); + } } } return builder.build(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java index fd2ca67a3a..303d5989f0 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java @@ -25,6 +25,7 @@ import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.http.Cookies; +import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; @@ -146,11 +147,11 @@ public Buffer getResponseBodyAsBuffer() { */ public List buildCookies() { - List values = headers.getHeaders().get("set-cookie"); + List values = headers.getHeaders().get(Header.SetCookie.toString()); if (isNonEmpty(values)) { ServerCookiesBuilder builder = new ServerCookiesBuilder(false, rfc6265Enabled); - for (String header : values) { - builder.parse(header); + for (int i = 0, len = values.size(); i < len; i++) { + builder.parse(values.get(i)); } return convertCookies(builder.build()); @@ -166,7 +167,8 @@ private List convertCookies(Cookies cookies) { final org.glassfish.grizzly.http.Cookie[] grizzlyCookies = cookies.get(); List convertedCookies = new ArrayList(grizzlyCookies.length); - for (org.glassfish.grizzly.http.Cookie gCookie : grizzlyCookies) { + for (int i = 0, len = grizzlyCookies.length; i < len; i++) { + org.glassfish.grizzly.http.Cookie gCookie = grizzlyCookies[i]; convertedCookies.add(new Cookie(gCookie.getDomain(), gCookie.getName(), gCookie.getValue(), diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java index 18ad3839e6..f5486f3d8b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java @@ -34,7 +34,8 @@ public BodyHandlerFactory(GrizzlyAsyncHttpProvider grizzlyAsyncHttpProvider) { } public BodyHandler getBodyHandler(final Request request) { - for (final BodyHandler h : handlers) { + for (int i = 0, len = handlers.length; i < len; i++) { + final BodyHandler h = handlers[i]; if (h.handlesBodyType(request)) { return h; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ParamsBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ParamsBodyHandler.java index dc5a9d8813..cf4f9f4307 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ParamsBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ParamsBodyHandler.java @@ -71,7 +71,8 @@ public boolean doHandle(final FilterChainContext ctx, if (sb == null) { sb = new StringBuilder(128); } - for (String value : values) { + for (int i = 0, len = values.size(); i < len; i++) { + final String value = values.get(i); if (sb.length() > 0) { sb.append('&'); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 634e8a1a01..9f9296a3e0 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -375,8 +375,8 @@ private void addGeneralHeaders(final Request request, final String headerName = entry.getKey(); final List headerValues = entry.getValue(); if (isNonEmpty(headerValues)) { - for (final String headerValue : headerValues) { - requestPacket.addHeader(headerName, headerValue); + for (int i = 0, len = headerValues.size(); i < len; i++) { + requestPacket.addHeader(headerName, headerValues.get(i)); } } } @@ -418,16 +418,19 @@ private void addCookies(final Request request, private static void convertCookies(final Collection cookies, final org.glassfish.grizzly.http.Cookie[] gCookies) { int idx = 0; - for (final Cookie cookie : cookies) { - final org.glassfish.grizzly.http.Cookie gCookie = - new org.glassfish.grizzly.http.Cookie(cookie.getName(), cookie.getValue()); - gCookie.setDomain(cookie.getDomain()); - gCookie.setPath(cookie.getPath()); - gCookie.setVersion(cookie.getVersion()); - gCookie.setMaxAge(cookie.getMaxAge()); - gCookie.setSecure(cookie.isSecure()); - gCookies[idx] = gCookie; - idx++; + if (!cookies.isEmpty()) { + for (final Cookie cookie : cookies) { + final org.glassfish.grizzly.http.Cookie gCookie = + new org.glassfish.grizzly.http.Cookie(cookie.getName(), + cookie.getValue()); + gCookie.setDomain(cookie.getDomain()); + gCookie.setPath(cookie.getPath()); + gCookie.setVersion(cookie.getVersion()); + gCookie.setMaxAge(cookie.getMaxAge()); + gCookie.setSecure(cookie.isSecure()); + gCookies[idx] = gCookie; + idx++; + } } } From 8f7752d9102bff5f841fec13cd995806d2e92257 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 23 Aug 2013 11:33:30 -0700 Subject: [PATCH 0058/2389] - Rework previous fix. - Switch from cached thread pool to fixed thread pool. --- .../AsyncHttpClientConfig.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index d40e7c4f6d..93ae5b87ff 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -157,7 +157,8 @@ private AsyncHttpClientConfig(int maxTotalConnections, int spdyInitialWindowSize, int spdyMaxConcurrentStreams, boolean rfc6265CookieEncoding, - boolean asyncConnectMode) { + boolean asyncConnectMode, + boolean managedApplicationThreadPool) { this.maxTotalConnections = maxTotalConnections; this.maxConnectionPerHost = maxConnectionPerHost; @@ -189,13 +190,8 @@ private AsyncHttpClientConfig(int maxTotalConnections, this.ioThreadMultiplier = ioThreadMultiplier; this.strict302Handling = strict302Handling; this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies; - - if (applicationThreadPool == null) { - managedApplicationThreadPool = true; - this.applicationThreadPool = Executors.newCachedThreadPool(); - } else { - this.applicationThreadPool = applicationThreadPool; - } + this.managedApplicationThreadPool = managedApplicationThreadPool; + this.applicationThreadPool = applicationThreadPool; this.proxyServerSelector = proxyServerSelector; this.useRawUrl = useRawUrl; this.spdyEnabled = spdyEnabled; @@ -635,6 +631,7 @@ public static class Builder { private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies"); private ScheduledExecutorService reaper; private ExecutorService applicationThreadPool; + private boolean managedApplicationThreadPool; private ProxyServerSelector proxyServerSelector = null; private SSLContext sslContext; private SSLEngineFactory sslEngineFactory; @@ -1276,8 +1273,10 @@ public Thread newThread(Runnable r) { } if (applicationThreadPool == null) { + managedApplicationThreadPool = true; + int count = Runtime.getRuntime().availableProcessors(); applicationThreadPool = - Executors.newCachedThreadPool(new ThreadFactory() { + Executors.newFixedThreadPool(count, new ThreadFactory() { final AtomicInteger counter = new AtomicInteger(); public Thread newThread(Runnable r) { Thread t = new Thread(r, @@ -1341,7 +1340,8 @@ public Thread newThread(Runnable r) { spdyInitialWindowSize, spdyMaxConcurrentStreams, rfc6265CookieEncoding, - asyncConnectMode); + asyncConnectMode, + managedApplicationThreadPool); } } } From 93c745c53b03deda947da3358b8948c5d539e05e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 23 Aug 2013 12:59:02 -0700 Subject: [PATCH 0059/2389] Fix typo. --- .../main/java/org/asynchttpclient/AsyncHttpClientConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 93ae5b87ff..55717a02e9 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -443,7 +443,7 @@ public List getRequestFilters() { * @since 2.0.0 */ public boolean hasResponseFilters() { - return !requestFilters.isEmpty(); + return !responseFilters.isEmpty(); } /** From 07476ab512b45d25e60f0002bed7c73b6467da4a Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 23 Aug 2013 13:17:21 -0700 Subject: [PATCH 0060/2389] Revert fixed thread pool change. Netty provider tests fail with it in place. --- .../main/java/org/asynchttpclient/AsyncHttpClientConfig.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 55717a02e9..32d01ebd99 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -1274,9 +1274,8 @@ public Thread newThread(Runnable r) { if (applicationThreadPool == null) { managedApplicationThreadPool = true; - int count = Runtime.getRuntime().availableProcessors(); applicationThreadPool = - Executors.newFixedThreadPool(count, new ThreadFactory() { + Executors.newCachedThreadPool(new ThreadFactory() { final AtomicInteger counter = new AtomicInteger(); public Thread newThread(Runnable r) { Thread t = new Thread(r, From cdfbea6f92edb02fd7d247585af678f8f74c7507 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 23 Aug 2013 13:27:49 -0700 Subject: [PATCH 0061/2389] Call getResponseBody0 before allocating the array. --- .../org/asynchttpclient/providers/grizzly/GrizzlyResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java index 303d5989f0..6a751bd376 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponse.java @@ -107,6 +107,7 @@ public String getResponseBody(String charset) throws IOException { */ @Override public byte[] getResponseBodyAsBytes() throws IOException { + final Buffer responseBody = getResponseBody0(); final byte[] responseBodyBytes = new byte[responseBody.remaining()]; final int origPos = responseBody.position(); responseBody.get(responseBodyBytes); From 322bca85c1026c34539c43a56a3b9b2642cff42f Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 25 Aug 2013 10:13:12 +0200 Subject: [PATCH 0062/2389] Force encoding when using String.toLower/UpperCase, close #361 --- .../FluentCaseInsensitiveStringsMap.java | 11 ++++++----- .../java/org/asynchttpclient/util/ProxyUtils.java | 2 +- .../async/AsyncStreamHandlerTest.java | 15 ++++++++------- .../providers/grizzly/ConnectionManager.java | 4 +++- .../providers/grizzly/EventHandler.java | 3 ++- .../statushandler/AuthorizationHandler.java | 6 ++++-- .../statushandler/ProxyAuthorizationHandler.java | 12 +++++++----- .../providers/netty/NettyAsyncHttpProvider.java | 6 ++++-- .../netty/NettyAsyncHttpProviderConfig.java | 4 ++-- 9 files changed, 37 insertions(+), 26 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java b/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java index 5f8c54232d..6e948c4d75 100644 --- a/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java +++ b/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java @@ -26,6 +26,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -105,7 +106,7 @@ public FluentCaseInsensitiveStringsMap add(String key, Collection values List nonNullValues = fetchValues(values); if (nonNullValues != null) { - String lcKey = key.toLowerCase(); + String lcKey = key.toLowerCase(Locale.ENGLISH); String realKey = keyLookup.get(lcKey); List curValues = null; @@ -177,7 +178,7 @@ public FluentCaseInsensitiveStringsMap replace(final String key, final String... public FluentCaseInsensitiveStringsMap replace(final String key, final Collection values) { if (key != null) { List nonNullValues = fetchValues(values); - String lcKkey = key.toLowerCase(); + String lcKkey = key.toLowerCase(Locale.ENGLISH); String realKey = keyLookup.get(lcKkey); if (nonNullValues == null) { @@ -259,7 +260,7 @@ public void putAll(Map> values) { */ public FluentCaseInsensitiveStringsMap delete(String key) { if (key != null) { - String lcKey = key.toLowerCase(); + String lcKey = key.toLowerCase(Locale.ENGLISH); String realKey = keyLookup.remove(lcKey); if (realKey != null) { @@ -368,7 +369,7 @@ public boolean isEmpty() { */ /* @Override */ public boolean containsKey(Object key) { - return key == null ? false : keyLookup.containsKey(key.toString().toLowerCase()); + return key == null ? false : keyLookup.containsKey(key.toString().toLowerCase(Locale.ENGLISH)); } /** @@ -433,7 +434,7 @@ public List get(Object key) { return null; } - String lcKey = key.toString().toLowerCase(); + String lcKey = key.toString().toLowerCase(Locale.ENGLISH); String realKey = keyLookup.get(lcKey); if (realKey == null) { diff --git a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java index 612642b524..5331dfa7d1 100644 --- a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java @@ -113,7 +113,7 @@ public static boolean avoidProxy(final ProxyServer proxyServer, final Request re */ public static boolean avoidProxy(final ProxyServer proxyServer, final String target) { if (proxyServer != null) { - final String targetHost = target.toLowerCase(); + final String targetHost = target.toLowerCase(Locale.ENGLISH); List nonProxyHosts = proxyServer.getNonProxyHosts(); diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index a2ab86cfc3..d25fa88ca6 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -52,7 +53,7 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { try { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.ABORT; } finally { l.countDown(); @@ -94,7 +95,7 @@ public void asyncStreamPOSTTest() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.CONTINUE; } @@ -142,7 +143,7 @@ public void asyncStreamInterruptTest() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.ABORT; } @@ -183,7 +184,7 @@ public void asyncStreamFutureTest() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.CONTINUE; } @@ -268,7 +269,7 @@ public void asyncStreamReusePOSTTest() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.CONTINUE; } @@ -303,7 +304,7 @@ public String onCompleted() throws Exception { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), UTF8); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); return STATE.CONTINUE; } @@ -345,7 +346,7 @@ public void asyncStream301WithBody() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(), "text/html; charset=utf-8"); + Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), "text/html; charset=utf-8"); return STATE.CONTINUE; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java index fbb65ee3e5..3f659146d0 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionManager.java @@ -32,6 +32,7 @@ import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLSession; + import java.io.IOException; import java.net.ConnectException; import java.net.InetAddress; @@ -39,6 +40,7 @@ import java.net.SocketAddress; import java.net.URI; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -250,7 +252,7 @@ private SocketAddress getRemoteAddress(final Request request, private static int getPort(final URI uri, final int p) { int port = p; if (port == -1) { - final String protocol = uri.getScheme().toLowerCase(); + final String protocol = uri.getScheme().toLowerCase(Locale.ENGLISH); if ("http".equals(protocol) || "ws".equals(protocol)) { port = 80; } else if ("https".equals(protocol) || "wss".equals(protocol)) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index f0add9b4b7..173c34e6c7 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -48,6 +48,7 @@ import java.net.URI; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.TimeUnit; @@ -424,7 +425,7 @@ private static void processKeepAlive(final Connection c, if (connectionHeader == null) { state.setKeepAlive(header.getProtocol() == Protocol.HTTP_1_1); } else { - if ("close".equals(connectionHeader.toLowerCase())) { + if ("close".equals(connectionHeader.toLowerCase(Locale.ENGLISH))) { ConnectionManager.markConnectionAsDoNotCache(c); state.setKeepAlive(false); } else { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java index 0660e27d18..04a2d72507 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java @@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; +import java.util.Locale; import static org.asynchttpclient.providers.grizzly.statushandler.StatusHandler.InvocationStatus.STOP; @@ -70,7 +71,8 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, .setUsePreemptiveAuth(true) .parseWWWAuthenticateHeader(auth) .build(); - if (auth.toLowerCase().startsWith("basic")) { + String lowerCaseAuth = auth.toLowerCase(Locale.ENGLISH); + if (lowerCaseAuth.startsWith("basic")) { req.getHeaders().remove(Header.Authorization.toString()); try { req.getHeaders().add(Header.Authorization.toString(), @@ -78,7 +80,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, realm)); } catch (UnsupportedEncodingException ignored) { } - } else if (auth.toLowerCase().startsWith("digest")) { + } else if (lowerCaseAuth.startsWith("digest")) { req.getHeaders().remove(Header.Authorization.toString()); try { req.getHeaders().add(Header.Authorization.toString(), diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index d65a596ac6..260a77acaf 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -35,6 +35,7 @@ import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; +import java.util.Locale; public final class ProxyAuthorizationHandler implements StatusHandler { @@ -76,7 +77,8 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, .setUsePreemptiveAuth(true) .parseProxyAuthenticateHeader(proxyAuth) .build(); - if (proxyAuth.toLowerCase().startsWith("basic")) { + String proxyAuthLowerCase = proxyAuth.toLowerCase(Locale.ENGLISH); + if (proxyAuthLowerCase.startsWith("basic")) { req.getHeaders().remove(Header.ProxyAuthenticate.toString()); req.getHeaders().remove(Header.ProxyAuthorization.toString()); try { @@ -85,7 +87,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, realm)); } catch (UnsupportedEncodingException ignored) { } - } else if (proxyAuth.toLowerCase().startsWith("digest")) { + } else if (proxyAuthLowerCase.startsWith("digest")) { req.getHeaders().remove(Header.ProxyAuthenticate.toString()); req.getHeaders().remove(Header.ProxyAuthorization.toString()); try { @@ -98,7 +100,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Unsupported encoding.", e); } - } else if (proxyAuth.toLowerCase().startsWith("ntlm")) { + } else if (proxyAuthLowerCase.startsWith("ntlm")) { req.getHeaders().remove(Header.ProxyAuthenticate.toString()); req.getHeaders().remove(Header.ProxyAuthorization.toString()); @@ -124,7 +126,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, } catch (Exception e1) { e1.printStackTrace(); } - } else if (proxyAuth.toLowerCase().startsWith("negotiate")) { + } else if (proxyAuthLowerCase.startsWith("negotiate")) { //this is for kerberos req.getHeaders().remove(Header.ProxyAuthenticate.toString()); req.getHeaders().remove(Header.ProxyAuthorization.toString()); @@ -208,7 +210,7 @@ private boolean executeRequest( } public static boolean isNTLMSecondHandShake(final String proxyAuth) { - return (proxyAuth != null && proxyAuth.toLowerCase() + return (proxyAuth != null && proxyAuth.toLowerCase(Locale.ENGLISH) .startsWith("ntlm") && !proxyAuth.equalsIgnoreCase("ntlm")); } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 61f89e3a73..084aac8a41 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -106,6 +106,7 @@ import org.slf4j.LoggerFactory; import javax.net.ssl.SSLEngine; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -122,6 +123,7 @@ import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; @@ -1995,7 +1997,7 @@ public void handle(final ChannelHandlerContext ctx, final MessageEvent e) throws int statusCode = response.getStatus().getCode(); String ka = response.getHeader(HttpHeaders.Names.CONNECTION); - future.setKeepAlive(ka == null || !ka.toLowerCase().equals("close")); + future.setKeepAlive(ka == null || !ka.toLowerCase(Locale.ENGLISH).equals("close")); List wwwAuth = getAuthorizationToken(response.getHeaders(), HttpHeaders.Names.WWW_AUTHENTICATE); Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); @@ -2246,7 +2248,7 @@ public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { final boolean validUpgrade = response.getHeader(HttpHeaders.Names.UPGRADE) != null; String c = response.getHeader(HttpHeaders.Names.CONNECTION); if (c == null) { - c = response.getHeader(HttpHeaders.Names.CONNECTION.toLowerCase()); + c = response.getHeader(HttpHeaders.Names.CONNECTION.toLowerCase(Locale.ENGLISH)); } final boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java index f338d570c8..d184b19aa7 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java @@ -17,6 +17,7 @@ package org.asynchttpclient.providers.netty; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -24,7 +25,6 @@ import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.asynchttpclient.AsyncHttpProviderConfig; /** @@ -96,7 +96,7 @@ public NettyAsyncHttpProviderConfig() { */ public NettyAsyncHttpProviderConfig addProperty(String name, Object value) { - if (name.equals(REUSE_ADDRESS) && value == Boolean.TRUE && System.getProperty("os.name").toLowerCase().contains("win")) { + if (name.equals(REUSE_ADDRESS) && value == Boolean.TRUE && System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win")) { LOGGER.warn("Can't enable {} on Windows", REUSE_ADDRESS); } else { properties.put(name, value); From ce85c81414cc46bdad5c89016d003fe10610399e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 26 Aug 2013 12:40:48 -0700 Subject: [PATCH 0063/2389] Do not create a thread pool in AsyncHttpClientConfig. Developers may still specify a service that they may wish to share with the AHC instance. By having this not be configured by default, it will allow providers to provide more optimized configurations out of the box. --- .../AsyncHttpClientConfig.java | 58 +++++++------------ .../providers/jdk/JDKAsyncHttpProvider.java | 15 ++++- .../util/AsyncHttpProviderUtils.java | 17 ++++++ .../grizzly/GrizzlyAsyncHttpProvider.java | 12 ++-- .../netty/NettyAsyncHttpProvider.java | 17 ++++-- 5 files changed, 69 insertions(+), 50 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 32d01ebd99..3e894f1b13 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -106,7 +106,6 @@ public class AsyncHttpClientConfig { protected boolean allowSslConnectionPool; protected boolean useRawUrl; protected boolean removeQueryParamOnRedirect; - protected boolean managedApplicationThreadPool; protected HostnameVerifier hostnameVerifier; protected int ioThreadMultiplier; protected boolean strict302Handling; @@ -157,8 +156,7 @@ private AsyncHttpClientConfig(int maxTotalConnections, int spdyInitialWindowSize, int spdyMaxConcurrentStreams, boolean rfc6265CookieEncoding, - boolean asyncConnectMode, - boolean managedApplicationThreadPool) { + boolean asyncConnectMode) { this.maxTotalConnections = maxTotalConnections; this.maxConnectionPerHost = maxConnectionPerHost; @@ -190,7 +188,6 @@ private AsyncHttpClientConfig(int maxTotalConnections, this.ioThreadMultiplier = ioThreadMultiplier; this.strict302Handling = strict302Handling; this.useRelativeURIsWithSSLProxies = useRelativeURIsWithSSLProxies; - this.managedApplicationThreadPool = managedApplicationThreadPool; this.applicationThreadPool = applicationThreadPool; this.proxyServerSelector = proxyServerSelector; this.useRawUrl = useRawUrl; @@ -334,25 +331,13 @@ public boolean isCompressionEnabled() { * asynchronous response. * * @return the {@link java.util.concurrent.ExecutorService} an {@link AsyncHttpClient} use for handling - * asynchronous response. + * asynchronous response. If no {@link ExecutorService} has been explicitly provided, + * this method will return null */ public ExecutorService executorService() { return applicationThreadPool; } - /** - * @return true if this AsyncHttpClientConfig instance created the - * {@link ExecutorService} returned by {@link #executorService()}, otherwise returns false. - * The return from this method is typically used by the various provider implementations to determine - * if it should shutdown the {@link ExecutorService} when the {@link AsyncHttpClient} is closed. Developers - * should take care and not share managed {@link ExecutorService} instances between client instances. - * - * @since 2.2.0 - */ - public boolean isManagedExecutorService() { - return managedApplicationThreadPool; - } - /** * An instance of {@link ProxyServer} used by an {@link AsyncHttpClient} * @@ -631,7 +616,6 @@ public static class Builder { private boolean useRelativeURIsWithSSLProxies = Boolean.getBoolean(ASYNC_CLIENT + "useRelativeURIsWithSSLProxies"); private ScheduledExecutorService reaper; private ExecutorService applicationThreadPool; - private boolean managedApplicationThreadPool; private ProxyServerSelector proxyServerSelector = null; private SSLContext sslContext; private SSLEngineFactory sslEngineFactory; @@ -1272,23 +1256,22 @@ public Thread newThread(Runnable r) { }); } - if (applicationThreadPool == null) { - managedApplicationThreadPool = true; - applicationThreadPool = - Executors.newCachedThreadPool(new ThreadFactory() { - final AtomicInteger counter = new AtomicInteger(); - public Thread newThread(Runnable r) { - Thread t = new Thread(r, - "AsyncHttpClient-Callback-" + counter.incrementAndGet()); - t.setDaemon(true); - return t; - } - }); - } - - if (applicationThreadPool.isShutdown()) { - throw new IllegalStateException("ExecutorServices closed"); - } +// if (applicationThreadPool == null) { +// applicationThreadPool = +// Executors.newCachedThreadPool(new ThreadFactory() { +// final AtomicInteger counter = new AtomicInteger(); +// public Thread newThread(Runnable r) { +// Thread t = new Thread(r, +// "AsyncHttpClient-Callback-" + counter.incrementAndGet()); +// t.setDaemon(true); +// return t; +// } +// }); +// } +// +// if (applicationThreadPool.isShutdown()) { +// throw new IllegalStateException("ExecutorServices closed"); +// } if (proxyServerSelector == null && useProxySelector) { proxyServerSelector = ProxyUtils.getJdkDefaultProxyServerSelector(); @@ -1339,8 +1322,7 @@ public Thread newThread(Runnable r) { spdyInitialWindowSize, spdyMaxConcurrentStreams, rfc6265CookieEncoding, - asyncConnectMode, - managedApplicationThreadPool); + asyncConnectMode); } } } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index b4821e1143..7f5ec241dc 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -72,6 +72,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -98,9 +99,18 @@ public class JDKAsyncHttpProvider implements AsyncHttpProvider { private boolean bufferResponseInMemory = false; + private ExecutorService service; + + private boolean managedExecutorService; + public JDKAsyncHttpProvider(AsyncHttpClientConfig config) { this.config = config; + service = config.executorService(); + managedExecutorService = (service == null); + if (service == null) { + service = AsyncHttpProviderUtils.createDefaultExecutorService(); + } AsyncHttpProviderConfig providerConfig = config.getAsyncHttpProviderConfig(); if (providerConfig instanceof JDKAsyncHttpProviderConfig) { configure(JDKAsyncHttpProviderConfig.class.cast(providerConfig)); @@ -152,7 +162,7 @@ public ListenableFuture execute(Request request, AsyncHandler handler, JDKFuture f = (delegate == null) ? new JDKFuture(handler, requestTimeout, urlConnection) : delegate; f.touch(); - f.setInnerFuture(config.executorService().submit(new AsyncHttpUrlConnection(urlConnection, request, handler, f))); + f.setInnerFuture(service.submit(new AsyncHttpUrlConnection(urlConnection, request, handler, f))); maxConnections.incrementAndGet(); return f; @@ -193,6 +203,9 @@ private HttpURLConnection createUrlConnection(Request request) throws IOExceptio public void close() { isClose.set(true); + if (managedExecutorService) { + service.shutdownNow(); + } } public Response prepareResponse(HttpResponseStatus status, HttpResponseHeaders headers, List bodyParts) { diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index 70ab5a60a2..06a29c0bce 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -28,6 +28,10 @@ import java.util.List; import java.util.Locale; import java.util.Vector; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProvider; @@ -582,4 +586,17 @@ public static String keepAliveHeaderValue(AsyncHttpClientConfig config) { public static int requestTimeout(AsyncHttpClientConfig config, Request request) { return request.getRequestTimeoutInMs() != 0 ? request.getRequestTimeoutInMs() : config.getRequestTimeoutInMs(); } + + public static ExecutorService createDefaultExecutorService() { + return Executors.newCachedThreadPool(new ThreadFactory() { + final AtomicInteger counter = new AtomicInteger(); + + public Thread newThread(Runnable r) { + Thread t = new Thread(r, + "AsyncHttpClient-Callback-" + counter.incrementAndGet()); + t.setDaemon(true); + return t; + } + }); + } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index a74f593008..d7a7d94d86 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -183,13 +183,11 @@ public void close() { try { connectionManager.destroy(); clientTransport.stop(); - if (clientConfig.isManagedExecutorService()) { - final ExecutorService service = clientConfig.executorService(); - // service may be null due to a custom configuration that - // leverages Grizzly's SameThreadIOStrategy. - if (service != null) { - service.shutdown(); - } + final ExecutorService service = clientConfig.executorService(); + // service may be null due to a custom configuration that + // leverages Grizzly's SameThreadIOStrategy. + if (service != null) { + service.shutdown(); } if (timeoutExecutor != null) { timeoutExecutor.stop(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 084aac8a41..4559250d3f 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -132,9 +132,11 @@ import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; +import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; import static org.asynchttpclient.util.DateUtil.millisTime; @@ -183,6 +185,8 @@ public boolean remove(Object o) { private static SpnegoEngine spnegoEngine = null; private final Protocol httpProtocol = new HttpProtocol(); private final Protocol webSocketProtocol = new WebSocketProtocol(); + private final boolean managedExecutorService; + private ExecutorService service; private static boolean isNTLM(List auth) { return isNonEmpty(auth) && auth.get(0).startsWith("NTLM"); @@ -195,9 +199,14 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { } else { asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); } + service = config.executorService(); + managedExecutorService = (service == null); + if (service == null) { + service = AsyncHttpProviderUtils.createDefaultExecutorService(); + } if (asyncHttpProviderConfig.isUseBlockingIO()) { - socketChannelFactory = new OioClientSocketChannelFactory(config.executorService()); + socketChannelFactory = new OioClientSocketChannelFactory(service); this.allowReleaseSocketChannelFactory = true; } else { // check if external NioClientSocketChannelFactory is defined @@ -214,7 +223,7 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { } int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); log.debug("Number of application's worker threads is {}", numWorkers); - socketChannelFactory = new NioClientSocketChannelFactory(e, config.executorService(), numWorkers); + socketChannelFactory = new NioClientSocketChannelFactory(e, service, numWorkers); this.allowReleaseSocketChannelFactory = true; } } @@ -830,8 +839,8 @@ public void close() { } } - if (config.isManagedExecutorService()) { - config.executorService().shutdown(); + if (managedExecutorService) { + service.shutdown(); } config.reaper().shutdown(); if (this.allowReleaseSocketChannelFactory) { From 2918d8f0c28615bf807b51dcbfa33efb2138757b Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 27 Aug 2013 11:24:40 -0700 Subject: [PATCH 0064/2389] tabs->spaces --- .../multipart/MultipartRequestEntity.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java index a3fcad60b6..4cf6834640 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartRequestEntity.java @@ -79,26 +79,26 @@ public MultipartRequestEntity(Part[] parts, FluentCaseInsensitiveStringsMap requ this.parts = parts; String contentTypeHeader = requestHeaders.getFirstValue("Content-Type"); if (isNonEmpty(contentTypeHeader)) { - int boundaryLocation = contentTypeHeader.indexOf("boundary="); - if (boundaryLocation != -1) { - // boundary defined in existing Content-Type - contentType = contentTypeHeader; - multipartBoundary = MultipartEncodingUtil.getAsciiBytes((contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim())); - } else { - // generate boundary and append it to existing Content-Type - multipartBoundary = generateMultipartBoundary(); + int boundaryLocation = contentTypeHeader.indexOf("boundary="); + if (boundaryLocation != -1) { + // boundary defined in existing Content-Type + contentType = contentTypeHeader; + multipartBoundary = MultipartEncodingUtil.getAsciiBytes((contentTypeHeader.substring(boundaryLocation + "boundary=".length()).trim())); + } else { + // generate boundary and append it to existing Content-Type + multipartBoundary = generateMultipartBoundary(); contentType = computeContentType(contentTypeHeader); - } + } } else { - multipartBoundary = generateMultipartBoundary(); + multipartBoundary = generateMultipartBoundary(); contentType = computeContentType(MULTIPART_FORM_CONTENT_TYPE); } } private String computeContentType(String base) { - StringBuilder buffer = new StringBuilder(base); - if (!base.endsWith(";")) - buffer.append(";"); + StringBuilder buffer = new StringBuilder(base); + if (!base.endsWith(";")) + buffer.append(";"); return buffer.append(" boundary=").append(MultipartEncodingUtil.getAsciiString(multipartBoundary)).toString(); } From d23b727c04e98615e03e8545add20d4abf3f81a0 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 27 Aug 2013 15:38:38 -0700 Subject: [PATCH 0065/2389] Instantiate header/cookie collections lazily. --- .../java/org/asynchttpclient/Request.java | 8 +++ .../asynchttpclient/RequestBuilderBase.java | 52 +++++++++++++++---- .../filters/AsyncHttpClientFilter.java | 17 +++--- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/Request.java b/api/src/main/java/org/asynchttpclient/Request.java index 056f93ee0d..34b41bcb27 100644 --- a/api/src/main/java/org/asynchttpclient/Request.java +++ b/api/src/main/java/org/asynchttpclient/Request.java @@ -86,6 +86,14 @@ public static interface EntityWriter { */ public FluentCaseInsensitiveStringsMap getHeaders(); + /** + * @return return true if request headers have been added, + * otherwise, returns false. + * + * @since 2.0 + */ + boolean hasHeaders(); + /** * Return Coookie. * diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index f22ff44918..e082ea8741 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -54,8 +54,8 @@ private static final class RequestImpl implements Request { private URI rawUri; private InetAddress address; private InetAddress localAddress; - private FluentCaseInsensitiveStringsMap headers = new FluentCaseInsensitiveStringsMap(); - private Collection cookies = new ArrayList(); + private FluentCaseInsensitiveStringsMap headers; + private Collection cookies; private byte[] byteData; private String stringData; private InputStream streamData; @@ -213,12 +213,23 @@ private URI toURI(boolean encode) { /* @Override */ public FluentCaseInsensitiveStringsMap getHeaders() { + if (headers == null) { + headers = new FluentCaseInsensitiveStringsMap(); + } return headers; } + @Override + public boolean hasHeaders() { + return headers != null && !headers.isEmpty(); + } + /* @Override */ public Collection getCookies() { - return Collections.unmodifiableCollection(cookies); + if (cookies == null) { + cookies = Collections.unmodifiableCollection(Collections.emptyList()); + } + return cookies; } /* @Override */ @@ -322,12 +333,13 @@ public String toString() { sb.append("\t"); sb.append(method); sb.append("\theaders:"); - if (headers != null) { - for (String name : headers.keySet()) { + final FluentCaseInsensitiveStringsMap headersLocal = getHeaders(); + if (headersLocal != null) { + for (String name : headersLocal.keySet()) { sb.append("\t"); sb.append(name); sb.append(":"); - sb.append(headers.getJoinedValue(name, ", ")); + sb.append(headersLocal.getJoinedValue(name, ", ")); } } sb.append("\tparams:"); @@ -436,7 +448,7 @@ public T setVirtualHost(String virtualHost) { } public T setHeader(String name, String value) { - request.headers.replace(name, value); + request.getHeaders().replace(name, value); return derived.cast(this); } @@ -446,17 +458,21 @@ public T addHeader(String name, String value) { value = ""; } - request.headers.add(name, value); + request.getHeaders().add(name, value); return derived.cast(this); } public T setHeaders(FluentCaseInsensitiveStringsMap headers) { - request.headers = (headers == null ? new FluentCaseInsensitiveStringsMap() : new FluentCaseInsensitiveStringsMap(headers)); + if (headers != null) { + request.headers = new FluentCaseInsensitiveStringsMap(headers); + } return derived.cast(this); } public T setHeaders(Map> headers) { - request.headers = (headers == null ? new FluentCaseInsensitiveStringsMap() : new FluentCaseInsensitiveStringsMap(headers)); + if (headers != null) { + request.headers = new FluentCaseInsensitiveStringsMap(headers); + } return derived.cast(this); } @@ -466,6 +482,9 @@ public T setContentLength(int length) { } public T addCookie(Cookie cookie) { + if (request.cookies == null) { + request.cookies = new ArrayList(); + } request.cookies.add(cookie); return derived.cast(this); } @@ -639,7 +658,10 @@ public T setConnectionPoolKeyStrategy(ConnectionPoolKeyStrategy connectionPoolKe public Request build() { if ((request.length < 0) && (request.streamData == null) && allowBody(request.getMethod())) { // can't concatenate content-length - String contentLength = request.headers.getFirstValue("Content-Length"); + String contentLength = null; + if (request.headers != null && request.headers.isEmpty()) { + contentLength = request.headers.getFirstValue("Content-Length"); + } if (contentLength != null) { try { @@ -649,6 +671,9 @@ public Request build() { } } } + if (request.cookies != null) { + request.cookies = Collections.unmodifiableCollection(request.cookies); + } return request; } @@ -660,6 +685,11 @@ public T addOrReplaceCookie(Cookie cookie) { String cookieKey = cookie.getName(); boolean replace = false; int index = 0; + if (request.cookies == null) { + request.cookies = new ArrayList(); + request.cookies.add(cookie); + return derived.cast(this); + } for (Cookie c : request.cookies) { if (c.getName().equals(cookieKey)) { replace = true; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 9f9296a3e0..fccf36361c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -285,10 +285,12 @@ private static FilterChainContext checkAndHandleFilterChainUpdate(final FilterCh private static void initTransferCompletionHandler(final Request request, final AsyncHandler h) throws IOException { - if (h instanceof TransferCompletionHandler) { - final FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(request.getHeaders()); - TransferCompletionHandler.class.cast(h).transferAdapter(new GrizzlyTransferAdapter(map)); - } + if (h instanceof TransferCompletionHandler) { + final FluentCaseInsensitiveStringsMap map = + new FluentCaseInsensitiveStringsMap(request.getHeaders()); + TransferCompletionHandler.class.cast(h) + .transferAdapter(new GrizzlyTransferAdapter(map)); + } } private static boolean checkHandshakeError(final FilterChainContext ctx, @@ -369,14 +371,15 @@ private static void convertToUpgradeRequest(final HttpTransactionContext ctx) { private void addGeneralHeaders(final Request request, final HttpRequestPacket requestPacket) { - final FluentCaseInsensitiveStringsMap map = request.getHeaders(); - if (isNonEmpty(map)) { + if (request.hasHeaders()) { + final FluentCaseInsensitiveStringsMap map = request.getHeaders(); for (final Map.Entry> entry : map.entrySet()) { final String headerName = entry.getKey(); final List headerValues = entry.getValue(); if (isNonEmpty(headerValues)) { for (int i = 0, len = headerValues.size(); i < len; i++) { - requestPacket.addHeader(headerName, headerValues.get(i)); + requestPacket.addHeader(headerName, + headerValues.get(i)); } } } From 57145c40a3d3b676da4a86183eb620b69f127a3e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 30 Aug 2013 12:40:27 -0700 Subject: [PATCH 0066/2389] Port changes from 1.7. --- .../async/NoNullResponseTest.java | 2 +- .../grizzly/FeedableBodyGenerator.java | 153 +++++++++++++++--- .../grizzly/GrizzlyAsyncHttpProvider.java | 7 +- 3 files changed, 137 insertions(+), 25 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java index 779373891b..2e85846920 100644 --- a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java @@ -39,7 +39,7 @@ public void multipleSslRequestsWithDelayAndKeepAlive() throws Throwable { try { final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); final Response response1 = builder.execute().get(); - Thread.sleep(5000); + Thread.sleep(4000); final Response response2 = builder.execute().get(); if (response2 != null) { System.out.println("Success (2nd response was not null)."); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index ad4febd666..778aa8b8c9 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -12,17 +12,27 @@ */ package org.asynchttpclient.providers.grizzly; -import org.asynchttpclient.Body; -import org.asynchttpclient.BodyGenerator; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; + +import org.asynchttpclient.Body; +import org.asynchttpclient.BodyGenerator; import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.utils.Futures; + +import static java.lang.Boolean.TRUE; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.glassfish.grizzly.utils.Exceptions.*; /** * {@link BodyGenerator} which may return just part of the payload at the time @@ -38,51 +48,145 @@ public class FeedableBodyGenerator implements BodyGenerator { private volatile HttpRequestPacket requestPacket; private volatile FilterChainContext context; - + private volatile HttpContent.Builder contentBuilder; + + private final EmptyBody EMPTY_BODY = new EmptyBody(); + + + + // ---------------------------------------------- Methods from BodyGenerator + + @Override public Body createBody() throws IOException { - return new EmptyBody(); + return EMPTY_BODY; } - + + + // ---------------------------------------------------------- Public Methods + + + /** + * Feeds the specified buffer. This buffer may be queued to be sent later + * or sent immediately. Note that this method may block if data is being + * fed faster than it is being consumed by the peer. + * + * The maximum duration that this method may block is dependent on + * the current value of {@link org.glassfish.grizzly.Transport#getWriteTimeout(java.util.concurrent.TimeUnit)}. + * This value can be customized by using a {@link TransportCustomizer} to + * fine-tune the transport used by the client instance. + * + * @param buffer the {@link Buffer} to feed. + * @param last flag indicating if this is the final buffer of the message. + * @throws IOException if an I/O error occurs. + * + * @see TransportCustomizer + * @see GrizzlyAsyncHttpProviderConfig#addProperty(GrizzlyAsyncHttpProviderConfig.Property, Object) + * @see GrizzlyAsyncHttpProviderConfig.Property#TRANSPORT_CUSTOMIZER + */ @SuppressWarnings("UnusedDeclaration") - public void feed(final Buffer buffer, final boolean isLast) - throws IOException { - queue.offer(new BodyPart(buffer, isLast)); + public void feed(final Buffer buffer, final boolean last) + throws IOException { + queue.offer(new BodyPart(buffer, last)); queueSize.incrementAndGet(); if (context != null) { - flushQueue(); + flushQueue(true); } } - + public void initializeAsynchronousTransfer(final FilterChainContext context, - final HttpRequestPacket requestPacket) { + final HttpRequestPacket requestPacket) + throws IOException { this.context = context; this.requestPacket = requestPacket; - flushQueue(); + this.contentBuilder = HttpContent.builder(requestPacket); + // don't block here. If queue is full at the time of the next feed() + // call, it will block. + flushQueue(false); } + + // --------------------------------------------------------- Private Methods + + @SuppressWarnings("unchecked") - private void flushQueue() { + private void flushQueue(final boolean allowBlocking) throws IOException { if (queueSize.get() > 0) { synchronized(this) { + final Connection c = context.getConnection(); while(queueSize.get() > 0) { + if (allowBlocking) { + blockUntilQueueFree(c); + } final BodyPart bodyPart = queue.poll(); queueSize.decrementAndGet(); final HttpContent content = - requestPacket.httpContentBuilder() - .content(bodyPart.buffer) - .last(bodyPart.isLast) + contentBuilder.content(bodyPart.buffer) + .last(bodyPart.isLast) .build(); - context.write(content, ((!requestPacket.isCommitted()) ? - context.getTransportContext().getCompletionHandler() : - null)); - + context.write(content, + ((!requestPacket.isCommitted()) + ? context.getTransportContext() + .getCompletionHandler() + : null)); } } } } - + + /** + * This method will block if the async write queue is currently larger + * than the configured maximum. The amount of time that this method + * will block is dependent on the write timeout of the transport + * associated with the specified connection. + */ + private void blockUntilQueueFree(final Connection c) { + if (!c.canWrite()) { + final FutureImpl future = + Futures.createSafeFuture(); + + // Connection may be obtained by calling FilterChainContext.getConnection(). + c.notifyCanWrite(new WriteHandler() { + + @Override + public void onWritePossible() throws Exception { + future.result(TRUE); + } + + @Override + public void onError(Throwable t) { + future.failure(makeIOException(t)); + } + }); + + block(c, future); + } + } + + private void block(final Connection c, + final FutureImpl future) { + try { + final long writeTimeout = + c.getTransport().getWriteTimeout(MILLISECONDS); + if (writeTimeout != -1) { + future.get(writeTimeout, MILLISECONDS); + } else { + future.get(); + } + } catch (ExecutionException e) { + HttpTransactionContext httpCtx = HttpTransactionContext.get(c); + httpCtx.abort(e.getCause()); + } catch (Exception e) { + HttpTransactionContext httpCtx = HttpTransactionContext.get(c); + httpCtx.abort(e); + } + } + + + // ----------------------------------------------------------- Inner Classes + + private final class EmptyBody implements Body { @Override @@ -100,9 +204,14 @@ public void close() throws IOException { context.completeAndRecycle(); context = null; requestPacket = null; + contentBuilder = null; } } - + + + // ---------------------------------------------------------- Nested Classes + + private final static class BodyPart { private final boolean isLast; private final Buffer buffer; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index d7a7d94d86..0f7e66ac94 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -86,6 +86,7 @@ import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.CONNECTION_POOL; import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.MAX_HTTP_PACKET_HEADER_SIZE; +import static org.glassfish.grizzly.asyncqueue.AsyncQueueWriter.AUTO_SIZE; /** * A Grizzly 2.0-based implementation of {@link AsyncHttpProvider}. @@ -182,7 +183,7 @@ public void close() { try { connectionManager.destroy(); - clientTransport.stop(); + clientTransport.shutdownNow(); final ExecutorService service = clientConfig.executorService(); // service may be null due to a custom configuration that // leverages Grizzly's SameThreadIOStrategy. @@ -254,6 +255,7 @@ void initializeTransport(final AsyncHttpClientConfig clientConfig) { final int timeout = clientConfig.getRequestTimeoutInMs(); if (timeout > 0) { int delay = 500; + //noinspection ConstantConditions if (timeout < delay) { delay = timeout - 10; if (delay <= 0) { @@ -382,7 +384,8 @@ public void onTimeout(Connection connection) { } // Don't limit the number of bytes the client can have queued to write. - clientTransport.getAsyncQueueIO().getWriter().setMaxPendingBytesPerConnection(-1); + clientTransport.getAsyncQueueIO().getWriter() + .setMaxPendingBytesPerConnection(AUTO_SIZE); // Install the HTTP filter chain. //clientTransport.setProcessor(fcb.build()); From 0253d3492b1812f9089f0a144473554ef568de88 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 30 Aug 2013 22:48:39 +0200 Subject: [PATCH 0067/2389] Introduce Netty 4 support (disabled) --- .../AsyncHttpClientConfig.java | 9 +- .../org/asynchttpclient/RequestBuilder.java | 1 + .../generators/InputStreamBodyGenerator.java | 4 + .../org/asynchttpclient/ntlm/NTLMEngine.java | 2 + .../providers/ResponseBase.java | 2 +- .../async/AsyncStreamHandlerTest.java | 28 +- .../async/AsyncStreamLifecycleTest.java | 4 - .../asynchttpclient/async/ChunkingTest.java | 15 +- .../async/FilePartLargeFileTest.java | 2 - .../async/InputStreamTest.java | 15 +- .../async/PutLargeFileTest.java | 3 - providers/netty-4/pom.xml | 24 - .../netty_4/NettyAsyncHttpProvider.java | 2504 ----------------- .../netty_4/NettyConnectListener.java | 153 - providers/netty4/pom.xml | 41 + .../netty4/AdditionalChannelInitializer.java | 8 + .../providers/netty4}/BodyChunkedInput.java | 70 +- .../providers/netty4}/BodyFileRegion.java | 33 +- .../providers/netty4/Callback.java | 16 + .../providers/netty4/Channels.java | 529 ++++ .../providers/netty4/Constants.java | 18 + .../providers/netty4/DiscardEvent.java | 6 + .../netty4}/FeedableBodyGenerator.java | 2 +- .../netty4/NettyAsyncHttpProvider.java | 94 + .../netty4}/NettyAsyncHttpProviderConfig.java | 51 +- .../providers/netty4/NettyChannelHandler.java | 887 ++++++ .../netty4/NettyConnectListener.java | 155 + .../netty4}/NettyConnectionsPool.java | 58 +- .../providers/netty4/NettyRequestSender.java | 462 +++ .../providers/netty4/NettyRequests.java | 321 +++ .../providers/netty4}/NettyResponse.java | 59 +- .../netty4}/NettyResponseFuture.java | 298 +- .../netty4/NettyResponseFutures.java | 98 + .../netty4/NettyTransferAdapter.java | 41 + .../providers/netty4}/NettyWebSocket.java | 33 +- .../providers/netty4/OptimizedFileRegion.java | 68 + .../providers/netty4/ProgressListener.java | 86 + .../providers/netty4}/Protocol.java | 6 +- .../providers/netty4/ReaperFuture.java | 104 + .../providers/netty4}/ResponseBodyPart.java | 69 +- .../providers/netty4}/ResponseHeaders.java | 43 +- .../providers/netty4}/ResponseStatus.java | 32 +- .../providers/netty4/ThreadLocalBoolean.java | 19 + .../providers/netty4}/WebSocketUtil.java | 2 +- .../netty4}/spnego/SpnegoEngine.java | 10 +- .../netty4}/spnego/SpnegoTokenGenerator.java | 2 +- .../providers/netty4/util/ByteBufUtil.java | 35 + .../netty4}/util/CleanupChannelGroup.java | 37 +- .../providers/netty4/util/HttpUtil.java | 33 + .../netty4}/NettyAsyncHttpProviderTest.java | 8 +- .../netty4}/NettyAsyncProviderBasicTest.java | 7 +- .../NettyAsyncProviderPipelineTest.java | 64 +- .../netty4}/NettyAsyncResponseTest.java | 13 +- .../netty4}/NettyAsyncStreamHandlerTest.java | 2 +- .../NettyAsyncStreamLifecycleTest.java | 2 +- .../netty4}/NettyAuthTimeoutTest.java | 2 +- .../providers/netty4}/NettyBasicAuthTest.java | 14 +- .../netty4}/NettyBasicHttpsTest.java | 2 +- .../providers/netty4}/NettyBodyChunkTest.java | 2 +- .../NettyBodyDeferringAsyncHandlerTest.java | 2 +- .../netty4}/NettyByteBufferCapacityTest.java | 2 +- .../providers/netty4}/NettyChunkingTest.java | 2 +- .../netty4}/NettyComplexClientTest.java | 2 +- .../netty4}/NettyConnectionPoolTest.java | 4 +- .../netty4}/NettyDigestAuthTest.java | 2 +- .../providers/netty4}/NettyEmptyBodyTest.java | 2 +- .../netty4}/NettyErrorResponseTest.java | 2 +- .../netty4}/NettyExpect100ContinueTest.java | 2 +- .../netty4}/NettyFilePartLargeFileTest.java | 2 +- .../providers/netty4}/NettyFilterTest.java | 2 +- .../netty4}/NettyFollowingThreadTest.java | 2 +- .../providers/netty4}/NettyHead302Test.java | 2 +- .../netty4}/NettyHostnameVerifierTest.java | 2 +- .../netty4}/NettyHttpToHttpsRedirectTest.java | 2 +- .../netty4}/NettyIdleStateHandlerTest.java | 2 +- .../netty4}/NettyInputStreamTest.java | 2 +- .../netty4}/NettyListenableFutureTest.java | 2 +- .../netty4}/NettyMaxConnectionsInThreads.java | 2 +- .../netty4}/NettyMaxTotalConnectionTest.java | 2 +- .../netty4}/NettyMultipartUploadTest.java | 2 +- .../netty4}/NettyMultipleHeaderTest.java | 2 +- .../netty4}/NettyNoNullResponseTest.java | 2 +- .../NettyNonAsciiContentLengthTest.java | 2 +- .../netty4}/NettyParamEncodingTest.java | 2 +- .../NettyPerRequestRelative302Test.java | 2 +- .../netty4}/NettyPerRequestTimeoutTest.java | 11 +- .../netty4}/NettyPostRedirectGetTest.java | 2 +- .../netty4}/NettyPostWithQSTest.java | 2 +- .../providers/netty4}/NettyProviderUtil.java | 17 +- .../providers/netty4}/NettyProxyTest.java | 2 +- .../netty4}/NettyProxyTunnellingTest.java | 2 +- .../netty4}/NettyPutLargeFileTest.java | 2 +- .../netty4}/NettyQueryParametersTest.java | 2 +- .../providers/netty4}/NettyRC10KTest.java | 2 +- .../NettyRedirectConnectionUsageTest.java | 4 +- .../netty4}/NettyRelative302Test.java | 2 +- .../netty4}/NettyRemoteSiteTest.java | 2 +- .../NettyRequestThrottleTimeoutTest.java | 2 +- .../netty4}/NettyRetryRequestTest.java | 2 +- .../NettySimpleAsyncHttpClientTest.java | 6 +- .../netty4}/NettyTransferListenerTest.java | 2 +- .../netty4}/NettyWebDavBasicTest.java | 2 +- .../netty4}/NettyZeroCopyFileTest.java | 2 +- .../netty4}/RetryNonBlockingIssue.java | 13 +- .../websocket/NettyByteMessageTest.java | 5 +- .../NettyCloseCodeReasonMsgTest.java | 5 +- .../netty4}/websocket/NettyRedirectTest.java | 5 +- .../websocket/NettyTextMessageTest.java | 5 +- .../src/test/resources/300k.png | Bin .../src/test/resources/SimpleTextFile.txt | 0 .../src/test/resources/client.keystore | Bin .../src/test/resources/gzip.txt.gz | Bin .../src/test/resources/logback-test.xml | 0 .../src/test/resources/realm.properties | 0 .../src/test/resources/ssltest-cacerts.jks | Bin .../src/test/resources/ssltest-keystore.jks | Bin .../src/test/resources/textfile.txt | 0 .../src/test/resources/textfile2.txt | 0 providers/pom.xml | 2 +- 119 files changed, 3587 insertions(+), 3276 deletions(-) delete mode 100644 providers/netty-4/pom.xml delete mode 100644 providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProvider.java delete mode 100644 providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectListener.java create mode 100644 providers/netty4/pom.xml create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/BodyChunkedInput.java (52%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/BodyFileRegion.java (72%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/FeedableBodyGenerator.java (98%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/NettyAsyncHttpProviderConfig.java (75%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/NettyConnectionsPool.java (83%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/NettyResponse.java (71%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/NettyResponseFuture.java (62%) mode change 100644 => 100755 create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/NettyWebSocket.java (88%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/Protocol.java (82%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/ResponseBodyPart.java (53%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/ResponseHeaders.java (58%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/ResponseStatus.java (59%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/WebSocketUtil.java (98%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/spnego/SpnegoEngine.java (96%) rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/spnego/SpnegoTokenGenerator.java (97%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java rename providers/{netty-4/src/main/java/org/asynchttpclient/providers/netty_4 => netty4/src/main/java/org/asynchttpclient/providers/netty4}/util/CleanupChannelGroup.java (75%) create mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncHttpProviderTest.java (87%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncProviderBasicTest.java (89%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncProviderPipelineTest.java (58%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncResponseTest.java (88%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncStreamHandlerTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAsyncStreamLifecycleTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyAuthTimeoutTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyBasicAuthTest.java (69%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyBasicHttpsTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyBodyChunkTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyBodyDeferringAsyncHandlerTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyByteBufferCapacityTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyChunkingTest.java (88%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyComplexClientTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyConnectionPoolTest.java (97%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyDigestAuthTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyEmptyBodyTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyErrorResponseTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyExpect100ContinueTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyFilePartLargeFileTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyFilterTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyFollowingThreadTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyHead302Test.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyHostnameVerifierTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyHttpToHttpsRedirectTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyIdleStateHandlerTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyInputStreamTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyListenableFutureTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyMaxConnectionsInThreads.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyMaxTotalConnectionTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyMultipartUploadTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyMultipleHeaderTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyNoNullResponseTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyNonAsciiContentLengthTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyParamEncodingTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyPerRequestRelative302Test.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyPerRequestTimeoutTest.java (79%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyPostRedirectGetTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyPostWithQSTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyProviderUtil.java (63%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyProxyTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyProxyTunnellingTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyPutLargeFileTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyQueryParametersTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRC10KTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRedirectConnectionUsageTest.java (92%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRelative302Test.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRemoteSiteTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRequestThrottleTimeoutTest.java (99%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyRetryRequestTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettySimpleAsyncHttpClientTest.java (84%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyTransferListenerTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyWebDavBasicTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/NettyZeroCopyFileTest.java (95%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/RetryNonBlockingIssue.java (97%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/websocket/NettyByteMessageTest.java (85%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/websocket/NettyCloseCodeReasonMsgTest.java (85%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/websocket/NettyRedirectTest.java (85%) rename providers/{netty-4/src/test/java/org/asynchttpclient/providers/netty => netty4/src/test/java/org/asynchttpclient/providers/netty4}/websocket/NettyTextMessageTest.java (85%) rename providers/{netty-4 => netty4}/src/test/resources/300k.png (100%) rename providers/{netty-4 => netty4}/src/test/resources/SimpleTextFile.txt (100%) rename providers/{netty-4 => netty4}/src/test/resources/client.keystore (100%) rename providers/{netty-4 => netty4}/src/test/resources/gzip.txt.gz (100%) rename providers/{netty-4 => netty4}/src/test/resources/logback-test.xml (100%) rename providers/{netty-4 => netty4}/src/test/resources/realm.properties (100%) rename providers/{netty-4 => netty4}/src/test/resources/ssltest-cacerts.jks (100%) rename providers/{netty-4 => netty4}/src/test/resources/ssltest-keystore.jks (100%) rename providers/{netty-4 => netty4}/src/test/resources/textfile.txt (100%) rename providers/{netty-4 => netty4}/src/test/resources/textfile2.txt (100%) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 3e894f1b13..35f7f1881d 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -855,13 +855,8 @@ public Builder setSSLEngineFactory(SSLEngineFactory sslEngineFactory) { * @return a {@link Builder} */ public Builder setSSLContext(final SSLContext sslContext) { - this.sslEngineFactory = new SSLEngineFactory() { - public SSLEngine newSSLEngine() throws GeneralSecurityException { - SSLEngine sslEngine = sslContext.createSSLEngine(); - sslEngine.setUseClientMode(true); - return sslEngine; - } - }; + // reset previously set value so it will be lazily recreated + this.sslEngineFactory = null; this.sslContext = sslContext; return this; } diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilder.java b/api/src/main/java/org/asynchttpclient/RequestBuilder.java index 4702419ac9..b1b608284b 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilder.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilder.java @@ -109,6 +109,7 @@ public RequestBuilder setBody(EntityWriter dataWriter) { * @deprecated {@link #setBody(BodyGenerator)} setBody(new InputStreamBodyGenerator(inputStream)) */ @Override + // FIXME I'd do the exact opposite: deprecate InputStreamBodyGenerator @Deprecated public RequestBuilder setBody(InputStream stream) throws IllegalArgumentException { return super.setBody(stream); diff --git a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java index ba208b4864..fcb2176854 100644 --- a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java +++ b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java @@ -47,6 +47,10 @@ public InputStreamBodyGenerator(InputStream inputStream) { } } + public InputStream getInputStream() { + return inputStream; + } + /** * {@inheritDoc} */ diff --git a/api/src/main/java/org/asynchttpclient/ntlm/NTLMEngine.java b/api/src/main/java/org/asynchttpclient/ntlm/NTLMEngine.java index 00da92497a..f09ac1fb81 100644 --- a/api/src/main/java/org/asynchttpclient/ntlm/NTLMEngine.java +++ b/api/src/main/java/org/asynchttpclient/ntlm/NTLMEngine.java @@ -108,6 +108,8 @@ public class NTLMEngine { SIGNATURE[bytesWithoutNull.length] = (byte) 0x00; } + public static final NTLMEngine INSTANCE = new NTLMEngine(); + /** * Returns the response for the given message. * diff --git a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java index d22a511eaa..9718c3302c 100644 --- a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java +++ b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java @@ -46,7 +46,7 @@ public final String getStatusText() { } /* @Override */ - public final URI getUri() /*throws MalformedURLException*/ { + public final URI getUri() { return status.getUrl(); } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index d25fa88ca6..2277d5a7a7 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -340,7 +340,11 @@ public void asyncStream301WithBody() throws Throwable { AsyncHttpClient c = getAsyncHttpClient(null); try { c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() { - private StringBuilder builder = new StringBuilder(); + + public STATE onStatusReceived(HttpResponseStatus status) throws Exception { + Assert.assertEquals(301, status.getStatusCode()); + return STATE.CONTINUE; + } @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { @@ -352,16 +356,13 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { @Override public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { - builder.append(new String(content.getBodyPartBytes())); return STATE.CONTINUE; } @Override public String onCompleted() throws Exception { - String r = builder.toString(); - Assert.assertTrue(r.contains("301 Moved")); l.countDown(); - return r; + return null; } }); @@ -379,7 +380,11 @@ public void asyncStream301RedirectWithBody() throws Throwable { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); try { c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() { - private StringBuilder builder = new StringBuilder(); + + public STATE onStatusReceived(HttpResponseStatus status) throws Exception { + Assert.assertTrue(status.getStatusCode() != 301); + return STATE.CONTINUE; + } @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { @@ -397,19 +402,10 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { return STATE.CONTINUE; } - @Override - public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { - builder.append(new String(content.getBodyPartBytes())); - return STATE.CONTINUE; - } - @Override public String onCompleted() throws Exception { - String r = builder.toString(); - Assert.assertTrue(!r.contains("301 Moved")); l.countDown(); - - return r; + return null; } }); diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java index 1c7f78c5e0..1666fc77d4 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java @@ -119,10 +119,6 @@ public void onThrowable(Throwable t) { public STATE onBodyPartReceived(HttpResponseBodyPart e) throws Exception { String s = new String(e.getBodyPartBytes()); log.info("got part: {}", s); - if (s.equals("")) { - // noinspection ThrowableInstanceNeverThrown - log.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body.")); - } queue.put(s); return STATE.CONTINUE; } diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index 9334cf38be..c4b008ec77 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -73,11 +73,6 @@ abstract public class ChunkingTest extends AbstractBasicTest { */ @Test() public void testCustomChunking() throws Throwable { - doTest(true); - } - - - private void doTest(boolean customChunkedInputStream) throws Exception { AsyncHttpClient c = null; try { AsyncHttpClientConfig.Builder bc = @@ -95,13 +90,9 @@ private void doTest(boolean customChunkedInputStream) throws Exception { RequestBuilder builder = new RequestBuilder("POST"); builder.setUrl(getTargetUrl()); - if (customChunkedInputStream) { - // made buff in stream big enough to mark. - builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000))); - } else { - // made buff in stream big enough to mark. - builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000))); - } + // made buff in stream big enough to mark. + builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000))); + Request r = builder.build(); Response res = null; diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index 2247181f77..adbe310ab3 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -111,8 +111,6 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle b = new byte[8192]; total += count; } - System.err.println("consumed " + total + " bytes."); - resp.setStatus(200); resp.addHeader("X-TRANFERED", String.valueOf(total)); resp.getOutputStream().flush(); diff --git a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java index 95d28480af..4cf034ada7 100644 --- a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java +++ b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java @@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; +import java.io.ByteArrayOutputStream; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -38,11 +39,18 @@ public abstract class InputStreamTest extends AbstractBasicTest { private class InputStreamHandler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("POST".equalsIgnoreCase(request.getMethod())) { - byte[] b = new byte[3]; - request.getInputStream().read(b, 0, 3); + byte[] bytes = new byte[3]; + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + int read = 0; + while (read > -1) { + read = request.getInputStream().read(bytes); + if (read > 0) { + bos.write(bytes, 0, read); + } + } response.setStatus(HttpServletResponse.SC_OK); - response.addHeader("X-Param", new String(b)); + response.addHeader("X-Param", new String(bos.toByteArray())); } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } @@ -80,7 +88,6 @@ public int read() throws IOException { } else { return -1; } - } }; diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index bf7d104897..c058c689a9 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -98,14 +98,11 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle total += count; } - System.err.println("consumed " + total + " bytes."); - resp.setStatus(200); resp.getOutputStream().flush(); resp.getOutputStream().close(); arg1.setHandled(true); - } }; } diff --git a/providers/netty-4/pom.xml b/providers/netty-4/pom.xml deleted file mode 100644 index 5aefababc7..0000000000 --- a/providers/netty-4/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - org.asynchttpclient - async-http-client-providers-parent - 2.0.0-SNAPSHOT - - 4.0.0 - async-http-client-netty-4-provider - Asynchronous Http Client Netty 4 Provider - - The Async Http Client Netty 4 Provider. - - - - - io.netty - netty-all - 4.0.0.Beta3 - - - - \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProvider.java b/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProvider.java deleted file mode 100644 index 9026fe3a3b..0000000000 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProvider.java +++ /dev/null @@ -1,2504 +0,0 @@ -/* - * Copyright 2010-2013 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty_4; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHandler.STATE; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.Body; -import org.asynchttpclient.BodyGenerator; -import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ConnectionsPool; -import org.asynchttpclient.Cookie; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.MaxRedirectException; -import org.asynchttpclient.ProgressAsyncHandler; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.RandomAccessBody; -import org.asynchttpclient.Realm; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.ResponseFilter; -import org.asynchttpclient.generators.InputStreamBodyGenerator; -import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.ntlm.NTLMEngine; -import org.asynchttpclient.ntlm.NTLMEngineException; -import org.asynchttpclient.providers.netty_4.FeedableBodyGenerator.FeedListener; -import org.asynchttpclient.providers.netty_4.spnego.SpnegoEngine; -import org.asynchttpclient.providers.netty_4.spnego.SpnegoEngine; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.asynchttpclient.multipart.MultipartBody; -import org.asynchttpclient.multipart.MultipartRequestEntity; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.util.AuthenticatorUtils; -import org.asynchttpclient.providers.netty_4.util.CleanupChannelGroup; -import org.asynchttpclient.util.ProxyUtils; -import org.asynchttpclient.util.SslUtils; -import org.asynchttpclient.util.UTF8UrlEncoder; -import io.netty.bootstrap.Bootstrap; -import io.netty.buffer.AbstractReferenceCounted; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufOutputStream; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundMessageHandlerAdapter; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.FileRegion; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.oio.OioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.oio.OioSocketChannel; -import io.netty.handler.codec.http.DefaultFullHttpRequest; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.HttpObject; -import io.netty.handler.codec.http.DefaultCookie; -import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpContentCompressor; -import io.netty.handler.codec.http.HttpContentDecompressor; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpRequestEncoder; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseDecoder; -import io.netty.handler.codec.http.HttpVersion; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder; -import io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.handler.ssl.SslHandler; -import io.netty.handler.stream.ChunkedFile; -import io.netty.handler.stream.ChunkedWriteHandler; -import io.netty.util.AttributeKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.SSLEngine; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.net.ConnectException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.lang.reflect.Field; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.FileChannel; -import java.nio.channels.WritableByteChannel; -import java.nio.charset.Charset; -import java.security.GeneralSecurityException; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.asynchttpclient.util.MiscUtil.isNonEmpty; -import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; - - -public class NettyAsyncHttpProvider extends ChannelInboundMessageHandlerAdapter implements AsyncHttpProvider { - private final static String WEBSOCKET_KEY = "Sec-WebSocket-Key"; - private final static String HTTP_HANDLER = "httpHandler"; - protected final static String SSL_HANDLER = "sslHandler"; - private final static String HTTPS = "https"; - private final static String HTTP = "http"; - private static final String WEBSOCKET = "ws"; - private static final String WEBSOCKET_SSL = "wss"; - - private final static Logger log = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); - private final static Charset UTF8 = Charset.forName("UTF-8"); - public final static AttributeKey DEFAULT_ATTRIBUTE = new AttributeKey("default"); - - private final Bootstrap plainBootstrap; - private final Bootstrap secureBootstrap; - private final Bootstrap webSocketBootstrap; - private final Bootstrap secureWebSocketBootstrap; - private /* final */ EventLoopGroup eventLoop; - private final static int MAX_BUFFERED_BYTES = 8192; - private final AsyncHttpClientConfig config; - private final AtomicBoolean isClose = new AtomicBoolean(false); - private final Class socketChannelFactory; - private final boolean allowReleaseSocketChannelFactory; - - private final ChannelGroup openChannels = new - CleanupChannelGroup("asyncHttpClient") { - @Override - public boolean remove(Object o) { - boolean removed = super.remove(o); - if (removed && trackConnections) { - freeConnections.release(); - } - return removed; - } - }; - private final ConnectionsPool connectionsPool; - private Semaphore freeConnections = null; - private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; - private boolean executeConnectAsync = true; - public static final ThreadLocal IN_IO_THREAD = new ThreadLocalBoolean(); - private final boolean trackConnections; - private final boolean useRawUrl; - private final static NTLMEngine ntlmEngine = new NTLMEngine(); - private static SpnegoEngine spnegoEngine = null; - private final Protocol httpProtocol = new HttpProtocol(); - private final Protocol webSocketProtocol = new WebSocketProtocol(); - - public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { - - if (config.getAsyncHttpProviderConfig() != null - && NettyAsyncHttpProviderConfig.class.isAssignableFrom(config.getAsyncHttpProviderConfig().getClass())) { - asyncHttpProviderConfig = NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()); - } else { - asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); - } - - if (asyncHttpProviderConfig.isUseBlockingIO()) { - socketChannelFactory = OioSocketChannel.class; - this.allowReleaseSocketChannelFactory = true; - } else { - // check if external NioClientSocketChannelFactory is defined - Class scf = asyncHttpProviderConfig.getSocketChannel(); - if (scf != null) { - this.socketChannelFactory = scf; - - // cannot allow releasing shared channel factory - this.allowReleaseSocketChannelFactory = false; - } else { - socketChannelFactory = NioSocketChannel.class; - eventLoop = asyncHttpProviderConfig.getEventLoopGroup(); - if (eventLoop == null) { - if (socketChannelFactory == OioSocketChannel.class) { - eventLoop = new OioEventLoopGroup(); - } else if (socketChannelFactory == NioSocketChannel.class) { - eventLoop = new NioEventLoopGroup(); - } else { - throw new IllegalArgumentException("No set event loop compatbile with socket channel " + scf); - } - } - int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); - log.debug("Number of application's worker threads is {}", numWorkers); - this.allowReleaseSocketChannelFactory = true; - } - } - plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); - secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);; - webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);; - secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);; - configureNetty(); - - this.config = config; - - // This is dangerous as we can't catch a wrong typed ConnectionsPool - ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); - if (cp == null && config.getAllowPoolingConnection()) { - cp = new NettyConnectionsPool(this); - } else if (cp == null) { - cp = new NonConnectionsPool(); - } - this.connectionsPool = cp; - - if (config.getMaxTotalConnections() != -1) { - trackConnections = true; - freeConnections = new Semaphore(config.getMaxTotalConnections()); - } else { - trackConnections = false; - } - - useRawUrl = config.isUseRawUrl(); - } - - @Override - public String toString() { - return String.format("NettyAsyncHttpProvider:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", - config.getMaxTotalConnections() - freeConnections.availablePermits(), - openChannels.toString(), - connectionsPool.toString()); - } - - void configureNetty() { - Map> optionMap = new HashMap>(); - for (Field field : ChannelOption.class.getDeclaredFields()) { - if (field.getType().isAssignableFrom(ChannelOption.class)) { - field.setAccessible(true); - try { - optionMap.put(field.getName(), (ChannelOption) field.get(null)); - } catch (IllegalAccessException ex) { - throw new Error(ex); - } - } - } - - if (asyncHttpProviderConfig != null) { - for (Entry entry : asyncHttpProviderConfig.propertiesSet()) { - ChannelOption key = optionMap.get(entry.getKey()); - Object value = entry.getValue(); - plainBootstrap.option(key, value); - webSocketBootstrap.option(key, value); - secureBootstrap.option(key, value); - secureWebSocketBootstrap.option(key, value); - } - } - - plainBootstrap.handler(createPlainPipelineFactory()); - // DefaultChannelFuture.setUseDeadLockChecker(false); - - if (asyncHttpProviderConfig != null) { - executeConnectAsync = asyncHttpProviderConfig.isAsyncConnect(); - if (!executeConnectAsync) { - // DefaultChannelFuture.setUseDeadLockChecker(true); - } - } - - webSocketBootstrap.handler(new ChannelInitializer() { - /* @Override */ - protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast("ws-decoder", new HttpResponseDecoder()); - pipeline.addLast("ws-encoder", new HttpRequestEncoder()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - } - }); - } - - protected HttpClientCodec newHttpClientCodec() { - if (asyncHttpProviderConfig != null) { - return new HttpClientCodec(asyncHttpProviderConfig.getMaxInitialLineLength(), asyncHttpProviderConfig.getMaxHeaderSize(), asyncHttpProviderConfig.getMaxChunkSize(), false); - - } else { - return new HttpClientCodec(); - } - } - - protected ChannelInitializer createPlainPipelineFactory() { - return new ChannelInitializer() { - - /* @Override */ - protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); - - if (config.getRequestCompressionLevel() > 0) { - pipeline.addLast("deflater", new HttpContentCompressor(config.getRequestCompressionLevel())); - } - - if (config.isCompressionEnabled()) { - pipeline.addLast("inflater", new HttpContentDecompressor()); - } - pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - } - }; - } - - void constructSSLPipeline(final NettyConnectListener cl) { - - secureBootstrap.handler(new ChannelInitializer() { - /* @Override */ - protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - abort(cl.future(), ex); - } - - pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); - - if (config.isCompressionEnabled()) { - pipeline.addLast("inflater", new HttpContentDecompressor()); - } - pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - } - }); - - secureWebSocketBootstrap.handler(new ChannelInitializer() { - - /* @Override */ - protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - abort(cl.future(), ex); - } - - pipeline.addLast("ws-decoder", new HttpResponseDecoder()); - pipeline.addLast("ws-encoder", new HttpRequestEncoder()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - } - }); - } - - private Channel lookupInCache(URI uri, ConnectionPoolKeyStrategy connectionPoolKeyStrategy) { - final Channel channel = connectionsPool.poll(connectionPoolKeyStrategy.getKey(uri)); - - if (channel != null) { - log.debug("Using cached Channel {}\n for uri {}\n", channel, uri); - - try { - // Always make sure the channel who got cached support the proper protocol. It could - // only occurs when a HttpMethod.CONNECT is used agains a proxy that require upgrading from http to - // https. - return verifyChannelPipeline(channel, uri.getScheme()); - } catch (Exception ex) { - log.debug(ex.getMessage(), ex); - } - } - return null; - } - - private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException { - SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine(); - if (sslEngine == null) { - sslEngine = SslUtils.getSSLEngine(); - } - return sslEngine; - } - - private Channel verifyChannelPipeline(Channel channel, String scheme) throws IOException, GeneralSecurityException { - - if (channel.pipeline().get(SSL_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { - channel.pipeline().remove(SSL_HANDLER); - } else if (channel.pipeline().get(HTTP_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { - return channel; - } else if (channel.pipeline().get(SSL_HANDLER) == null && isSecure(scheme)) { - channel.pipeline().addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); - } - return channel; - } - - protected final void writeRequest(final Channel channel, - final AsyncHttpClientConfig config, - final NettyResponseFuture future, - final HttpRequest nettyRequest) { - try { - /** - * If the channel is dead because it was pooled and the remote server decided to close it, - * we just let it go and the closeChannel do it's work. - */ - if (!channel.isOpen() || !channel.isActive()) { - return; - } - - Body body = null; - if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { - BodyGenerator bg = future.getRequest().getBodyGenerator(); - if (bg != null) { - // Netty issue with chunking. - if (InputStreamBodyGenerator.class.isAssignableFrom(bg.getClass())) { - InputStreamBodyGenerator.class.cast(bg).patchNettyChunkingIssue(true); - } - - try { - body = bg.createBody(); - } catch (IOException ex) { - throw new IllegalStateException(ex); - } - long length = body.getContentLength(); - if (length >= 0) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, length); - } else { - nettyRequest.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); - } - } else { - body = null; - } - } - - if (TransferCompletionHandler.class.isAssignableFrom(future.getAsyncHandler().getClass())) { - - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - for (String s : future.getNettyRequest().headers().names()) { - for (String header : future.getNettyRequest().headers().getAll(s)) { - h.add(s, header); - } - } - - TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter( - new NettyTransferAdapter(h, nettyRequest.getContent(), future.getRequest().getFile())); - } - - // Leave it to true. - if (future.getAndSetWriteHeaders(true)) { - try { - channel.write(nettyRequest).addListener(new ProgressListener(true, future.getAsyncHandler(), future)); - } catch (Throwable cause) { - log.debug(cause.getMessage(), cause); - try { - channel.close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } - } - - if (future.getAndSetWriteBody(true)) { - if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { - - if (future.getRequest().getFile() != null) { - final File file = future.getRequest().getFile(); - long fileLength = 0; - final RandomAccessFile raf = new RandomAccessFile(file, "r"); - - try { - fileLength = raf.length(); - - ChannelFuture writeFuture; - if (channel.pipeline().get(SslHandler.class) != null) { - writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, 8192)); - } else { - final FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); - writeFuture = channel.write(region); - } - writeFuture.addListener(new ProgressListener(false, future.getAsyncHandler(), future)); - } catch (IOException ex) { - if (raf != null) { - try { - raf.close(); - } catch (IOException e) { - } - } - throw ex; - } - } else if (body != null || future.getRequest().getParts() != null) { - /** - * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements. - */ - if (future.getRequest().getParts() != null) { - String boundary = future.getNettyRequest().headers().get("Content-Type"); - String length = future.getNettyRequest().headers().get("Content-Length"); - body = new MultipartBody(future.getRequest().getParts(), boundary, length); - } - - ChannelFuture writeFuture; - if (channel.pipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) { - BodyFileRegion bodyFileRegion = new BodyFileRegion((RandomAccessBody) body); - writeFuture = channel.write(bodyFileRegion); - } else { - BodyChunkedInput bodyChunkedInput = new BodyChunkedInput(body); - BodyGenerator bg = future.getRequest().getBodyGenerator(); - if (bg instanceof FeedableBodyGenerator) { - ((FeedableBodyGenerator)bg).setListener(new FeedListener() { - @Override public void onContentAdded() { - channel.pipeline().get(ChunkedWriteHandler.class).resumeTransfer(); - } - }); - } - writeFuture = channel.write(bodyChunkedInput); - } - - final Body b = body; - writeFuture.addListener(new ProgressListener(false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelFuture cf) { - try { - b.close(); - } catch (IOException e) { - log.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - } - } - } - } catch (Throwable ioe) { - try { - channel.close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - } - - try { - future.touch(); - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, future.getRequest()); - if (requestTimeout != -1 && !future.isDone() && !future.isCancelled()) { - ReaperFuture reaperFuture = new ReaperFuture(future); - Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, requestTimeout, TimeUnit.MILLISECONDS); - reaperFuture.setScheduledFuture(scheduledFuture); - future.setReaperFuture(reaperFuture); - } - } catch (RejectedExecutionException ex) { - abort(future, ex); - } - - } - - protected final static HttpRequest buildRequest(AsyncHttpClientConfig config, Request request, URI uri, - boolean allowConnect, ByteBuf buffer, ProxyServer proxyServer) throws IOException { - - String method = request.getMethod(); - if (allowConnect && proxyServer != null && isSecure(uri)) { - method = HttpMethod.CONNECT.toString(); - } - return construct(config, request, new HttpMethod(method), uri, buffer, proxyServer); - } - - private static SpnegoEngine getSpnegoEngine() { - if(spnegoEngine == null) - spnegoEngine = new SpnegoEngine(); - return spnegoEngine; - } - - private static HttpRequest construct(AsyncHttpClientConfig config, - Request request, - HttpMethod m, - URI uri, - ByteBuf buffer, - ProxyServer proxyServer) throws IOException { - - String host = AsyncHttpProviderUtils.getHost(uri); - boolean webSocket = isWebSocket(uri); - - if (request.getVirtualHost() != null) { - host = request.getVirtualHost(); - } - - FullHttpRequest nettyRequest; - if (m.equals(HttpMethod.CONNECT)) { - nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, m, AsyncHttpProviderUtils.getAuthority(uri)); - } else { - String path = null; - if (proxyServer != null && !(isSecure(uri) && config.isUseRelativeURIsWithSSLProxies())) - path = uri.toString(); - else if (uri.getRawQuery() != null) - path = uri.getRawPath() + "?" + uri.getRawQuery(); - else - path = uri.getRawPath(); - nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, m, path); - } - - if (webSocket) { - nettyRequest.headers().add(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET); - nettyRequest.headers().add(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); - nettyRequest.headers().add("Origin", "http://" + uri.getHost() + ":" - + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort())); - nettyRequest.headers().add(WEBSOCKET_KEY, WebSocketUtil.getKey()); - nettyRequest.headers().add("Sec-WebSocket-Version", "13"); - } - - if (host != null) { - if (uri.getPort() == -1) { - nettyRequest.headers().set(HttpHeaders.Names.HOST, host); - } else if (request.getVirtualHost() != null) { - nettyRequest.headers().set(HttpHeaders.Names.HOST, host); - } else { - nettyRequest.headers().set(HttpHeaders.Names.HOST, host + ":" + uri.getPort()); - } - } else { - host = "127.0.0.1"; - } - - if (!m.equals(HttpMethod.CONNECT)) { - FluentCaseInsensitiveStringsMap h = request.getHeaders(); - if (h != null) { - for (String name : h.keySet()) { - if (!"host".equalsIgnoreCase(name)) { - for (String value : h.get(name)) { - nettyRequest.headers().add(name, value); - } - } - } - } - - if (config.isCompressionEnabled()) { - nettyRequest.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); - } - } else { - List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (isNonEmpty(auth) && auth.get(0).startsWith("NTLM")) { - nettyRequest.headers().add(HttpHeaders.Names.PROXY_AUTHORIZATION, auth.get(0)); - } - } - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - if (realm != null && realm.getUsePreemptiveAuth()) { - - String domain = realm.getNtlmDomain(); - if (proxyServer != null && proxyServer.getNtlmDomain() != null) { - domain = proxyServer.getNtlmDomain(); - } - - String authHost = realm.getNtlmHost(); - if (proxyServer != null && proxyServer.getHost() != null) { - host = proxyServer.getHost(); - } - - switch (realm.getAuthScheme()) { - case BASIC: - nettyRequest.headers().set(HttpHeaders.Names.AUTHORIZATION, - AuthenticatorUtils.computeBasicAuthentication(realm)); - break; - case DIGEST: - if (isNonEmpty(realm.getNonce())) { - try { - nettyRequest.headers().set(HttpHeaders.Names.AUTHORIZATION, - AuthenticatorUtils.computeDigestAuthentication(realm)); - } catch (NoSuchAlgorithmException e) { - throw new SecurityException(e); - } - } - break; - case NTLM: - try { - String msg = ntlmEngine.generateType1Msg("NTLM " + domain, authHost); - nettyRequest.headers().set(HttpHeaders.Names.AUTHORIZATION, "NTLM " + msg); - } catch (NTLMEngineException e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - break; - case KERBEROS: - case SPNEGO: - String challengeHeader = null; - String server = proxyServer == null ? host : proxyServer.getHost(); - try { - challengeHeader = getSpnegoEngine().generateToken(server); - } catch (Throwable e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - nettyRequest.headers().set(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); - break; - case NONE: - break; - default: - throw new IllegalStateException("Invalid Authentication " + realm); - } - } - - if (!webSocket && !request.getHeaders().containsKey(HttpHeaders.Names.CONNECTION)) { - nettyRequest.headers().set(HttpHeaders.Names.CONNECTION, AsyncHttpProviderUtils.keepAliveHeaderValue(config)); - } - - if (proxyServer != null) { - if (!request.getHeaders().containsKey("Proxy-Connection")) { - nettyRequest.headers().set("Proxy-Connection", AsyncHttpProviderUtils.keepAliveHeaderValue(config)); - } - - if (proxyServer.getPrincipal() != null) { - if (isNonEmpty(proxyServer.getNtlmDomain())) { - - List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (!(isNonEmpty(auth) && auth.get(0).startsWith("NTLM"))) { - try { - String msg = ntlmEngine.generateType1Msg(proxyServer.getNtlmDomain(), - proxyServer.getHost()); - nettyRequest.headers().set(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + msg); - } catch (NTLMEngineException e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - } - } else { - nettyRequest.headers().set(HttpHeaders.Names.PROXY_AUTHORIZATION, - AuthenticatorUtils.computeBasicAuthentication(proxyServer)); - } - } - } - - // Add default accept headers. - if (request.getHeaders().getFirstValue("Accept") == null) { - nettyRequest.headers().set(HttpHeaders.Names.ACCEPT, "*/*"); - } - - if (request.getHeaders().getFirstValue("User-Agent") != null) { - nettyRequest.headers().set("User-Agent", request.getHeaders().getFirstValue("User-Agent")); - } else if (config.getUserAgent() != null) { - nettyRequest.headers().set("User-Agent", config.getUserAgent()); - } else { - nettyRequest.headers().set("User-Agent", - AsyncHttpProviderUtils.constructUserAgent(NettyAsyncHttpProvider.class, - config)); - } - - if (!m.equals(HttpMethod.CONNECT)) { - if (isNonEmpty(request.getCookies())) { - CookieEncoder httpCookieEncoder = new CookieEncoder(false); - Iterator ic = request.getCookies().iterator(); - Cookie c; - org.jboss.netty.handler.codec.http.Cookie cookie; - while (ic.hasNext()) { - c = ic.next(); - cookie = new DefaultCookie(c.getName(), c.getValue()); - cookie.setPath(c.getPath()); - cookie.setMaxAge(c.getMaxAge()); - cookie.setDomain(c.getDomain()); - httpCookieEncoder.addCookie(cookie); - } - nettyRequest.headers().set(HttpHeaders.Names.COOKIE, httpCookieEncoder.encode()); - } - - String reqType = request.getMethod(); - if (!"HEAD".equals(reqType) && !"OPTION".equals(reqType) && !"TRACE".equals(reqType)) { - - String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : request.getBodyEncoding(); - - // We already have processed the body. - if (buffer != null && buffer.writerIndex() != 0) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, buffer.writerIndex()); - nettyRequest.setContent(buffer); - } else if (request.getByteData() != null) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getByteData().length)); - nettyRequest.setContent(Unpooled.wrappedBuffer(request.getByteData())); - } else if (request.getStringData() != null) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getStringData().getBytes(bodyCharset).length)); - nettyRequest.setContent(Unpooled.wrappedBuffer(request.getStringData().getBytes(bodyCharset))); - } else if (request.getStreamData() != null) { - int[] lengthWrapper = new int[1]; - byte[] bytes = AsyncHttpProviderUtils.readFully(request.getStreamData(), lengthWrapper); - int length = lengthWrapper[0]; - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length)); - nettyRequest.setContent(Unpooled.wrappedBuffer(bytes, 0, length)); - } else if (isNonEmpty(request.getParams())) { - StringBuilder sb = new StringBuilder(); - for (final Entry> paramEntry : request.getParams()) { - final String key = paramEntry.getKey(); - for (final String value : paramEntry.getValue()) { - if (sb.length() > 0) { - sb.append("&"); - } - UTF8UrlEncoder.appendEncoded(sb, key); - sb.append("="); - UTF8UrlEncoder.appendEncoded(sb, value); - } - } - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(sb.length())); - nettyRequest.setContent(Unpooled.wrappedBuffer(sb.toString().getBytes(bodyCharset))); - - if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/x-www-form-urlencoded"); - } - - } else if (request.getParts() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); - - if (lenght == -1) { - lenght = MAX_BUFFERED_BYTES; - } - - MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getParams()); - - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength())); - - /** - * TODO: AHC-78: SSL + zero copy isn't supported by the MultiPart class and pretty complex to implements. - */ - - if (isSecure(uri)) { - ByteBuf b = Unpooled.buffer(lenght); - mre.writeRequest(new ByteBufOutputStream(b)); - nettyRequest.setContent(b); - } - } else if (request.getEntityWriter() != null) { - int lenght = computeAndSetContentLength(request, nettyRequest); - - if (lenght == -1) { - lenght = MAX_BUFFERED_BYTES; - } - - ByteBuf b = Unpooled.buffer(lenght); - request.getEntityWriter().writeEntity(new ByteBufOutputStream(b)); - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); - nettyRequest.setContent(b); - } else if (request.getFile() != null) { - File file = request.getFile(); - if (!file.isFile()) { - throw new IOException(String.format("File %s is not a file or doesn't exist", file.getAbsolutePath())); - } - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, file.length()); - } - } - } - return nettyRequest; - } - - public void close() { - isClose.set(true); - try { - connectionsPool.destroy(); - openChannels.close(); - - for (Channel channel : openChannels) { - ChannelHandlerContext ctx = channel.pipeline().context(NettyAsyncHttpProvider.class); - if (ctx.attr(DEFAULT_ATTRIBUTE).get() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.attr(DEFAULT_ATTRIBUTE).get(); - future.setReaperFuture(null); - } - } - - config.executorService().shutdown(); - config.reaper().shutdown(); - if (this.allowReleaseSocketChannelFactory) { - eventLoop.shutdown(); - } - } catch (Throwable t) { - log.warn("Unexpected error on close", t); - } - } - - /* @Override */ - - public Response prepareResponse(final HttpResponseStatus status, - final HttpResponseHeaders headers, - final List bodyParts) { - return new NettyResponse(status, headers, bodyParts); - } - - /* @Override */ - - public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { - return doConnect(request, asyncHandler, null, true, executeConnectAsync, false); - } - - private void execute(final Request request, final NettyResponseFuture f, boolean useCache, boolean asyncConnect, boolean reclaimCache) throws IOException { - doConnect(request, f.getAsyncHandler(), f, useCache, asyncConnect, reclaimCache); - } - - private ListenableFuture doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture f, - boolean useCache, boolean asyncConnect, boolean reclaimCache) throws IOException { - - if (isClose.get()) { - throw new IOException("Closed"); - } - - if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) { - throw new IOException("WebSocket method must be a GET"); - } - - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - boolean useProxy = proxyServer != null; - URI uri; - if (useRawUrl) { - uri = request.getRawURI(); - } else { - uri = request.getURI(); - } - Channel channel = null; - - if (useCache) { - if (f != null && f.reuseChannel() && f.channel() != null) { - channel = f.channel(); - } else { - URI connectionKeyUri = useProxy? proxyServer.getURI() : uri; - channel = lookupInCache(connectionKeyUri, request.getConnectionPoolKeyStrategy()); - } - } - - ByteBuf bufferedBytes = null; - if (f != null && f.getRequest().getFile() == null && - !f.getNettyRequest().getMethod().name().equals(HttpMethod.CONNECT.name())) { - bufferedBytes = f.getNettyRequest().data(); - } - - boolean useSSl = isSecure(uri) && !useProxy; - if (channel != null && channel.isOpen() && channel.isActive()) { - HttpRequest nettyRequest = buildRequest(config, request, uri, f == null ? false : f.isConnectAllowed(), bufferedBytes, proxyServer); - - if (f == null) { - f = newFuture(uri, request, asyncHandler, nettyRequest, config, this, proxyServer); - } else { - nettyRequest = buildRequest(config, request, uri, f.isConnectAllowed(), bufferedBytes, proxyServer); - f.setNettyRequest(nettyRequest); - } - f.setState(NettyResponseFuture.STATE.POOLED); - f.attachChannel(channel, false); - - log.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest); - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(DEFAULT_ATTRIBUTE).set(f); - - try { - writeRequest(channel, config, f, nettyRequest); - } catch (Exception ex) { - log.debug("writeRequest failure", ex); - if (useSSl && ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) { - log.debug("SSLEngine failure", ex); - f = null; - } else { - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("doConnect.writeRequest()", t); - } - IOException ioe = new IOException(ex.getMessage()); - ioe.initCause(ex); - throw ioe; - } - } - return f; - } - - // Do not throw an exception when we need an extra connection for a redirect. - if (!reclaimCache && !connectionsPool.canCacheConnection()) { - IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("!connectionsPool.canCacheConnection()", t); - } - throw ex; - } - - boolean acquiredConnection = false; - - if (trackConnections) { - if (!reclaimCache) { - if (!freeConnections.tryAcquire()) { - IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("!connectionsPool.canCacheConnection()", t); - } - throw ex; - } else { - acquiredConnection = true; - } - } - } - - NettyConnectListener c = new NettyConnectListener.Builder(config, request, asyncHandler, f, this, bufferedBytes).build(uri); - boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost()); - - if (useSSl) { - constructSSLPipeline(c); - } - - ChannelFuture channelFuture; - Bootstrap bootstrap = request.getUrl().startsWith(WEBSOCKET) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap : plainBootstrap); - bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); - - try { - InetSocketAddress remoteAddress; - if (request.getInetAddress() != null) { - remoteAddress = new InetSocketAddress(request.getInetAddress(), AsyncHttpProviderUtils.getPort(uri)); - } else if (proxyServer == null || avoidProxy) { - remoteAddress = new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)); - } else { - remoteAddress = new InetSocketAddress(proxyServer.getHost(), proxyServer.getPort()); - } - - if(request.getLocalAddress() != null){ - channelFuture = bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); - }else{ - channelFuture = bootstrap.connect(remoteAddress); - } - - } catch (Throwable t) { - if (acquiredConnection) { - freeConnections.release(); - } - abort(c.future(), t.getCause() == null ? t : t.getCause()); - return c.future(); - } - - boolean directInvokation = true; - if (IN_IO_THREAD.get() && DefaultChannelFuture.isUseDeadLockChecker()) { - directInvokation = false; - } - - if (directInvokation && !asyncConnect && request.getFile() == null) { - int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; - if (!channelFuture.awaitUninterruptibly(timeOut, TimeUnit.MILLISECONDS)) { - if (acquiredConnection) { - freeConnections.release(); - } - channelFuture.cancel(); - abort(c.future(), new ConnectException(String.format("Connect operation to %s timeout %s", uri, timeOut))); - } - - try { - c.operationComplete(channelFuture); - } catch (Exception e) { - if (acquiredConnection) { - freeConnections.release(); - } - IOException ioe = new IOException(e.getMessage()); - ioe.initCause(e); - try { - asyncHandler.onThrowable(ioe); - } catch (Throwable t) { - log.warn("c.operationComplete()", t); - } - throw ioe; - } - } else { - channelFuture.addListener(c); - } - - log.debug("\nNon cached request \n{}\n\nusing Channel \n{}\n", c.future().getNettyRequest(), channelFuture.getChannel()); - - if (!c.future().isCancelled() || !c.future().isDone()) { - openChannels.add(channelFuture.channel()); - c.future().attachChannel(channelFuture.channel(), false); - } - return c.future(); - } - - private void closeChannel(final ChannelHandlerContext ctx) { - connectionsPool.removeAll(ctx.channel()); - finishChannel(ctx); - } - - private void finishChannel(final ChannelHandlerContext ctx) { - ctx.attr(DEFAULT_ATTRIBUTE).set(new DiscardEvent()); - - // The channel may have already been removed if a timeout occurred, and this method may be called just after. - if (ctx.channel() == null) { - return; - } - - log.debug("Closing Channel {} ", ctx.channel()); - - - try { - ctx.channel().close(); - } catch (Throwable t) { - log.debug("Error closing a connection", t); - } - - if (ctx.channel() != null) { - openChannels.remove(ctx.channel()); - } - - } - - @Override - public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception { - //call super to reset the read timeout - super.messageReceived(ctx, e); - IN_IO_THREAD.set(Boolean.TRUE); - if (ctx.getAttachment() == null) { - log.debug("ChannelHandlerContext wasn't having any attachment"); - } - - if (ctx.getAttachment() instanceof DiscardEvent) { - return; - } else if (ctx.getAttachment() instanceof AsyncCallable) { - if (e.getMessage() instanceof HttpChunk) { - HttpChunk chunk = (HttpChunk) e.getMessage(); - if (chunk.isLast()) { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ac.call(); - } else { - return; - } - } else { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ac.call(); - } - ctx.setAttachment(new DiscardEvent()); - return; - } else if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { - try { - ctx.getChannel().close(); - } catch (Throwable t) { - log.trace("Closing an orphan channel {}", ctx.getChannel()); - } - return; - } - - Protocol p = (ctx.getPipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.handle(ctx, e); - } - - private Realm kerberosChallenge(List proxyAuth, - Request request, - ProxyServer proxyServer, - FluentCaseInsensitiveStringsMap headers, - Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - - URI uri = request.getURI(); - String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost(); - String server = proxyServer == null ? host : proxyServer.getHost(); - try { - String challengeHeader = getSpnegoEngine().generateToken(server); - headers.remove(HttpHeaders.Names.AUTHORIZATION); - headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); - - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - return realmBuilder.setUri(uri.getRawPath()) - .setMethodName(request.getMethod()) - .setScheme(Realm.AuthScheme.KERBEROS) - .build(); - } catch (Throwable throwable) { - if (proxyAuth.contains("NTLM")) { - return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); - } - abort(future, throwable); - return null; - } - } - - private Realm ntlmChallenge(List wwwAuth, - Request request, - ProxyServer proxyServer, - FluentCaseInsensitiveStringsMap headers, - Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - - boolean useRealm = (proxyServer == null && realm != null); - - String ntlmDomain = useRealm ? realm.getNtlmDomain() : proxyServer.getNtlmDomain(); - String ntlmHost = useRealm ? realm.getNtlmHost() : proxyServer.getHost(); - String principal = useRealm ? realm.getPrincipal() : proxyServer.getPrincipal(); - String password = useRealm ? realm.getPassword() : proxyServer.getPassword(); - - Realm newRealm; - if (realm != null && !realm.isNtlmMessageType2Received()) { - String challengeHeader = ntlmEngine.generateType1Msg(ntlmDomain, ntlmHost); - - URI uri = request.getURI(); - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()) - .setUri(uri.getRawPath()) - .setMethodName(request.getMethod()) - .setNtlmMessageType2Received(true) - .build(); - future.getAndSetAuth(false); - } else { - headers.remove(HttpHeaders.Names.AUTHORIZATION); - - if (wwwAuth.get(0).startsWith("NTLM ")) { - String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = ntlmEngine.generateType3Msg(principal, password, - ntlmDomain, ntlmHost, serverChallenge); - - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - } - - Realm.RealmBuilder realmBuilder; - Realm.AuthScheme authScheme; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - authScheme = realm.getAuthScheme(); - } else { - realmBuilder = new Realm.RealmBuilder(); - authScheme = Realm.AuthScheme.NTLM; - } - newRealm = realmBuilder.setScheme(authScheme) - .setUri(request.getURI().getPath()) - .setMethodName(request.getMethod()) - .build(); - } - - return newRealm; - } - - private Realm ntlmProxyChallenge(List wwwAuth, - Request request, - ProxyServer proxyServer, - FluentCaseInsensitiveStringsMap headers, - Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - future.getAndSetAuth(false); - headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); - - if (wwwAuth.get(0).startsWith("NTLM ")) { - String serverChallenge = wwwAuth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = ntlmEngine.generateType3Msg(proxyServer.getPrincipal(), - proxyServer.getPassword(), - proxyServer.getNtlmDomain(), - proxyServer.getHost(), - serverChallenge); - headers.add(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + challengeHeader); - } - Realm newRealm; - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - newRealm = realmBuilder//.setScheme(realm.getAuthScheme()) - .setUri(request.getURI().getPath()) - .setMethodName(request.getMethod()) - .build(); - - return newRealm; - } - - private String getPoolKey(NettyResponseFuture future) throws MalformedURLException { - URI uri = future.getProxyServer() != null ? future.getProxyServer().getURI() : future.getURI(); - return future.getConnectionPoolKeyStrategy().getKey(uri); - } - - private void drainChannel(final ChannelHandlerContext ctx, final NettyResponseFuture future) { - ctx.setAttachment(new AsyncCallable(future) { - public Object call() throws Exception { - if (future.isKeepAlive() && ctx.channel().isReadable() && connectionsPool.offer(getPoolKey(future), ctx.channel())) { - return null; - } - - finishChannel(ctx); - return null; - } - - @Override - public String toString() { - return "Draining task for channel " + ctx.channel(); - } - }); - } - - private FilterContext handleIoException(FilterContext fc, NettyResponseFuture future) { - for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - } - return fc; - } - - private void replayRequest(final NettyResponseFuture future, FilterContext fc, HttpResponse response, ChannelHandlerContext ctx) throws IOException { - final Request newRequest = fc.getRequest(); - future.setAsyncHandler(fc.getAsyncHandler()); - future.setState(NettyResponseFuture.STATE.NEW); - future.touch(); - - log.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); - drainChannel(ctx, future); - nextRequest(newRequest, future); - return; - } - - private List getAuthorizationToken(List> list, String headerAuth) { - ArrayList l = new ArrayList(); - for (Entry e : list) { - if (e.getKey().equalsIgnoreCase(headerAuth)) { - l.add(e.getValue().trim()); - } - } - return l; - } - - private void nextRequest(final Request request, final NettyResponseFuture future) throws IOException { - nextRequest(request, future, true); - } - - private void nextRequest(final Request request, final NettyResponseFuture future, final boolean useCache) throws IOException { - execute(request, future, useCache, true, true); - } - - private void abort(NettyResponseFuture future, Throwable t) { - Channel channel = future.channel(); - if (channel != null && openChannels.contains(channel)) { - closeChannel(channel.pipeline().context(NettyAsyncHttpProvider.class)); - openChannels.remove(channel); - } - - if (!future.isCancelled() && !future.isDone()) { - log.debug("Aborting Future {}\n", future); - log.debug(t.getMessage(), t); - } - - future.abort(t); - } - - private void upgradeProtocol(ChannelPipeline p, String scheme) throws IOException, GeneralSecurityException { - if (p.get(HTTP_HANDLER) != null) { - p.remove(HTTP_HANDLER); - } - - if (isSecure(scheme)) { - if (p.get(SSL_HANDLER) == null) { - p.addFirst(HTTP_HANDLER, newHttpClientCodec()); - p.addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); - } else { - p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); - } - - } else { - p.addFirst(HTTP_HANDLER, newHttpClientCodec()); - } - } - - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - - if (isClose.get()) { - return; - } - - connectionsPool.removeAll(ctx.getChannel()); - try { - super.channelClosed(ctx, e); - } catch (Exception ex) { - log.trace("super.channelClosed", ex); - } - - log.debug("Channel Closed: {} with attachment {}", e.getChannel(), ctx.getAttachment()); - - if (ctx.getAttachment() instanceof AsyncCallable) { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ctx.setAttachment(ac.future()); - ac.call(); - return; - } - - if (ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - future.touch(); - - if (config.getIOExceptionFilters().size() > 0) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()) - .request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest() && !future.cannotBeReplay()) { - replayRequest(future, fc, null, ctx); - return; - } - } - - Protocol p = (ctx.getPipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onClose(ctx, e); - - if (future != null && !future.isDone() && !future.isCancelled()) { - if (!remotelyClosed(ctx.getChannel(), future)) { - abort(future, new IOException("Remotely Closed " + ctx.getChannel())); - } - } else { - closeChannel(ctx); - } - } - } - - protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) { - - if (isClose.get()) { - return false; - } - - connectionsPool.removeAll(channel); - - if (future == null && channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment() != null - && NettyResponseFuture.class.isAssignableFrom( - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment().getClass())) { - future = (NettyResponseFuture) - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); - } - - if (future == null || future.cannotBeReplay()) { - log.debug("Unable to recover future {}\n", future); - return false; - } - - future.setState(NettyResponseFuture.STATE.RECONNECTED); - future.getAndSetStatusReceived(false); - - log.debug("Trying to recover request {}\n", future.getNettyRequest()); - - try { - nextRequest(future.getRequest(), future); - return true; - } catch (IOException iox) { - future.setState(NettyResponseFuture.STATE.CLOSED); - future.abort(iox); - log.error("Remotely Closed, unable to recover", iox); - } - return false; - } - - private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { - // We need to make sure everything is OK before adding the connection back to the pool. - try { - future.done(null); - } catch (Throwable t) { - // Never propagate exception once we know we are done. - log.debug(t.getMessage(), t); - } - - if (!future.isKeepAlive() || !ctx.channel().isReadable()) { - closeChannel(ctx); - } - } - - private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { - if (lastValidChunk && future.isKeepAlive()) { - drainChannel(ctx, future); - } else { - if (future.isKeepAlive() && ctx.channel().isReadable() && connectionsPool.offer(getPoolKey(future), ctx.close())) { - markAsDone(future, ctx); - return; - } - finishChannel(ctx); - } - markAsDone(future, ctx); - } - - private final boolean updateStatusAndInterrupt(AsyncHandler handler, HttpResponseStatus c) throws Exception { - return handler.onStatusReceived(c) != STATE.CONTINUE; - } - - private final boolean updateHeadersAndInterrupt(AsyncHandler handler, HttpResponseHeaders c) throws Exception { - return handler.onHeadersReceived(c) != STATE.CONTINUE; - } - - private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { - boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; - if (c.closeUnderlyingConnection()) { - future.setKeepAlive(false); - } - return state; - } - - //Simple marker for stopping publishing bytes. - - final static class DiscardEvent { - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) - throws Exception { - Channel channel = ctx.channel(); - Throwable cause = e.getCause(); - NettyResponseFuture future = null; - - /** Issue 81 - if (e.getCause() != null && e.getCause().getClass().isAssignableFrom(PrematureChannelClosureException.class)) { - return; - } - */ - if (e.getCause() != null && e.getCause().getClass().getSimpleName().equals("PrematureChannelClosureException")) { - return; - } - - if (log.isDebugEnabled()) { - log.debug("Unexpected I/O exception on channel {}", channel, cause); - } - - try { - - if (cause != null && ClosedChannelException.class.isAssignableFrom(cause.getClass())) { - return; - } - - if (ctx.attr(DEFAULT_ATTRIBUTE).get() instanceof NettyResponseFuture) { - future = (NettyResponseFuture) ctx.attr(DEFAULT_ATTRIBUTE).get(); - future.attachChannel(null, false); - future.touch(); - - if (IOException.class.isAssignableFrom(cause.getClass())) { - - if (config.getIOExceptionFilters().size() > 0) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()) - .request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest()) { - replayRequest(future, fc, null, ctx); - return; - } - } else { - // Close the channel so the recovering can occurs. - try { - ctx.channel().close(); - } catch (Throwable t) { - ; // Swallow. - } - return; - } - } - - if (abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) { - log.debug("Trying to recover from dead Channel: {}", channel); - return; - } - } else if (ctx.attr(DEFAULT_ATTRIBUTE).get() instanceof AsyncCallable) { - future = ((AsyncCallable) ctx.attr(DEFAULT_ATTRIBUTE).get()).future(); - } - } catch (Throwable t) { - cause = t; - } - - if (future != null) { - try { - log.debug("Was unable to recover Future: {}", future); - abort(future, cause); - } catch (Throwable t) { - log.error(t.getMessage(), t); - } - } - - Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onError(ctx, e); - - closeChannel(ctx); - ctx.sendUpstream(e); - } - - protected static boolean abortOnConnectCloseException(Throwable cause) { - try { - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketChannelImpl") - && element.getMethodName().equals("checkConnect")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnConnectCloseException(cause.getCause()); - } - - } catch (Throwable t) { - } - return false; - } - - protected static boolean abortOnDisconnectException(Throwable cause) { - try { - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("org.jboss.netty.handler.ssl.SslHandler") - && element.getMethodName().equals("channelDisconnected")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnConnectCloseException(cause.getCause()); - } - - } catch (Throwable t) { - } - return false; - } - - protected static boolean abortOnReadCloseException(Throwable cause) { - - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") - && element.getMethodName().equals("read")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnReadCloseException(cause.getCause()); - } - - return false; - } - - protected static boolean abortOnWriteCloseException(Throwable cause) { - - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") - && element.getMethodName().equals("write")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnReadCloseException(cause.getCause()); - } - - return false; - } - - private final static int computeAndSetContentLength(Request request, HttpRequest r) { - int length = (int) request.getContentLength(); - if (length == -1 && r.headers().get(HttpHeaders.Names.CONTENT_LENGTH) != null) { - length = Integer.valueOf(r.headers().get(HttpHeaders.Names.CONTENT_LENGTH)); - } - - if (length >= 0) { - r.headers().set(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length)); - } - return length; - } - - public static NettyResponseFuture newFuture(URI uri, - Request request, - AsyncHandler asyncHandler, - FullHttpRequest nettyRequest, - AsyncHttpClientConfig config, - NettyAsyncHttpProvider provider, - ProxyServer proxyServer) { - - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); - NettyResponseFuture f = new NettyResponseFuture(uri, request, asyncHandler, nettyRequest, requestTimeout, config.getIdleConnectionTimeoutInMs(), provider, request.getConnectionPoolKeyStrategy(), proxyServer); - - if (request.getHeaders().getFirstValue("Expect") != null - && request.getHeaders().getFirstValue("Expect").equalsIgnoreCase("100-Continue")) { - f.getAndSetWriteBody(false); - } - return f; - } - - private class ProgressListener implements ChannelFutureProgressListener { - - private final boolean notifyHeaders; - private final AsyncHandler asyncHandler; - private final NettyResponseFuture future; - - public ProgressListener(boolean notifyHeaders, AsyncHandler asyncHandler, NettyResponseFuture future) { - this.notifyHeaders = notifyHeaders; - this.asyncHandler = asyncHandler; - this.future = future; - } - - public void operationComplete(ChannelFuture cf) { - // The write operation failed. If the channel was cached, it means it got asynchronously closed. - // Let's retry a second time. - Throwable cause = cf.cause(); - if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) { - - if (IllegalStateException.class.isAssignableFrom(cause.getClass())) { - log.debug(cause.getMessage(), cause); - try { - cf.channel().close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } - - if (ClosedChannelException.class.isAssignableFrom(cause.getClass()) - || abortOnReadCloseException(cause) - || abortOnWriteCloseException(cause)) { - - if (log.isDebugEnabled()) { - log.debug(cf.cause() == null ? "" : cf.cause().getMessage(), cf.cause()); - } - - try { - cf.channel().close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } else { - future.abort(cause); - } - return; - } - future.touch(); - - /** - * We need to make sure we aren't in the middle of an authorization process before publishing events - * as we will re-publish again the same event after the authorization, causing unpredictable behavior. - */ - Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : NettyAsyncHttpProvider.this.getConfig().getRealm(); - boolean startPublishing = future.isInAuth() - || realm == null - || realm.getUsePreemptiveAuth() == true; - - if (startPublishing && ProgressAsyncHandler.class.isAssignableFrom(asyncHandler.getClass())) { - if (notifyHeaders) { - ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); - } else { - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteCompleted(); - } - } - } - - public void operationProgressed(ChannelFuture cf, long amount, long current, long total) { - future.touch(); - if (ProgressAsyncHandler.class.isAssignableFrom(asyncHandler.getClass())) { - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(amount, current, total); - } - } - } - - /** - * Because some implementation of the ThreadSchedulingService do not clean up cancel task until they try to run - * them, we wrap the task with the future so the when the NettyResponseFuture cancel the reaper future - * this wrapper will release the references to the channel and the nettyResponseFuture immediately. Otherwise, - * the memory referenced this way will only be released after the request timeout period which can be arbitrary long. - */ - private final class ReaperFuture implements Future, Runnable { - private Future scheduledFuture; - private NettyResponseFuture nettyResponseFuture; - - public ReaperFuture(NettyResponseFuture nettyResponseFuture) { - this.nettyResponseFuture = nettyResponseFuture; - } - - public void setScheduledFuture(Future scheduledFuture) { - this.scheduledFuture = scheduledFuture; - } - - /** - * @Override - */ - public boolean cancel(boolean mayInterruptIfRunning) { - nettyResponseFuture = null; - return scheduledFuture.cancel(mayInterruptIfRunning); - } - - /** - * @Override - */ - public Object get() throws InterruptedException, ExecutionException { - return scheduledFuture.get(); - } - - /** - * @Override - */ - public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - return scheduledFuture.get(timeout, unit); - } - - /** - * @Override - */ - public boolean isCancelled() { - return scheduledFuture.isCancelled(); - } - - /** - * @Override - */ - public boolean isDone() { - return scheduledFuture.isDone(); - } - - /** - * @Override - */ - public synchronized void run() { - if (isClose.get()) { - cancel(true); - return; - } - - if (nettyResponseFuture != null && nettyResponseFuture.hasExpired() - && !nettyResponseFuture.isDone() && !nettyResponseFuture.isCancelled()) { - log.debug("Request Timeout expired for {}\n", nettyResponseFuture); - - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, nettyResponseFuture.getRequest()); - - abort(nettyResponseFuture, new TimeoutException("No response received after " + requestTimeout)); - - nettyResponseFuture = null; - } - - if (nettyResponseFuture == null || nettyResponseFuture.isDone() || nettyResponseFuture.isCancelled()) { - cancel(true); - } - } - } - - private abstract class AsyncCallable implements Callable { - - private final NettyResponseFuture future; - - public AsyncCallable(NettyResponseFuture future) { - this.future = future; - } - - abstract public Object call() throws Exception; - - public NettyResponseFuture future() { - return future; - } - } - - public static class ThreadLocalBoolean extends ThreadLocal { - - private final boolean defaultValue; - - public ThreadLocalBoolean() { - this(false); - } - - public ThreadLocalBoolean(boolean defaultValue) { - this.defaultValue = defaultValue; - } - - @Override - protected Boolean initialValue() { - return defaultValue ? Boolean.TRUE : Boolean.FALSE; - } - } - - public static class OptimizedFileRegion extends AbstractReferenceCounted implements FileRegion { - - private final FileChannel file; - private final RandomAccessFile raf; - private final long position; - private final long count; - private long byteWritten; - - public OptimizedFileRegion(RandomAccessFile raf, long position, long count) { - this.raf = raf; - this.file = raf.getChannel(); - this.position = position; - this.count = count; - } - - public long position() { - return position; - } - - public long count() { - return count; - } - - public long transferTo(WritableByteChannel target, long position) throws IOException { - long count = this.count - position; - if (count < 0 || position < 0) { - throw new IllegalArgumentException( - "position out of range: " + position + - " (expected: 0 - " + (this.count - 1) + ")"); - } - if (count == 0) { - return 0L; - } - - long bw = file.transferTo(this.position + position, count, target); - byteWritten += bw; - if (byteWritten == raf.length()) { - deallocate(); - } - return bw; - } - - public void deallocate() { - try { - file.close(); - } catch (IOException e) { - log.warn("Failed to close a file.", e); - } - - try { - raf.close(); - } catch (IOException e) { - log.warn("Failed to close a file.", e); - } - } - } - - private static class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter { - - private final ByteBuf content; - private final FileInputStream file; - private int byteRead = 0; - - public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf content, File file) throws IOException { - super(headers); - this.content = content; - if (file != null) { - this.file = new FileInputStream(file); - } else { - this.file = null; - } - } - - @Override - public void getBytes(byte[] bytes) { - if (content.writableBytes() != 0) { - content.getBytes(byteRead, bytes); - byteRead += bytes.length; - } else if (file != null) { - try { - byteRead += file.read(bytes); - } catch (IOException e) { - log.error(e.getMessage(), e); - } - } - } - } - - protected AsyncHttpClientConfig getConfig() { - return config; - } - - private static class NonConnectionsPool implements ConnectionsPool { - - public boolean offer(String uri, Channel connection) { - return false; - } - - public Channel poll(String uri) { - return null; - } - - public boolean removeAll(Channel connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - } - } - - private static final boolean validateWebSocketRequest(Request request, AsyncHandler asyncHandler) { - if (request.getMethod() != "GET" || !WebSocketUpgradeHandler.class.isAssignableFrom(asyncHandler.getClass())) { - return false; - } - return true; - } - - private boolean redirect(Request request, - NettyResponseFuture future, - HttpResponse response, - final ChannelHandlerContext ctx) throws Exception { - - int statusCode = response.getStatus().code(); - boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); - if (redirectEnabled && (statusCode == 302 - || statusCode == 301 - || statusCode == 303 - || statusCode == 307)) { - - if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { - // We must allow 401 handling again. - future.getAndSetAuth(false); - - String location = response.headers().get(HttpHeaders.Names.LOCATION); - URI uri = AsyncHttpProviderUtils.getRedirectUri(future.getURI(), location); - boolean stripQueryString = config.isRemoveQueryParamOnRedirect(); - if (!uri.toString().equals(future.getURI().toString())) { - final RequestBuilder nBuilder = stripQueryString ? - new RequestBuilder(future.getRequest()).setQueryParameters(null) - : new RequestBuilder(future.getRequest()); - - if (!(statusCode < 302 || statusCode > 303) - && !(statusCode == 302 - && config.isStrict302Handling())) { - nBuilder.setMethod("GET"); - } - final boolean initialConnectionKeepAlive = future.isKeepAlive(); - final String initialPoolKey = getPoolKey(future); - future.setURI(uri); - String newUrl = uri.toString(); - if (request.getUrl().startsWith(WEBSOCKET)) { - newUrl = newUrl.replace(HTTP, WEBSOCKET); - } - - log.debug("Redirecting to {}", newUrl); - for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE)) { - Cookie c = AsyncHttpProviderUtils.parseCookie(cookieStr); - nBuilder.addOrReplaceCookie(c); - } - - for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE2)) { - Cookie c = AsyncHttpProviderUtils.parseCookie(cookieStr); - nBuilder.addOrReplaceCookie(c); - } - - AsyncCallable ac = new AsyncCallable(future) { - public Object call() throws Exception { - if (initialConnectionKeepAlive && ctx.channel().isReadable() && connectionsPool.offer(initialPoolKey, ctx.channel())) { - return null; - } - finishChannel(ctx); - return null; - } - }; - - if (response.isChunked()) { - // We must make sure there is no bytes left before executing the next request. - ctx.attr(DEFAULT_ATTRIBUTE).set(ac); - } else { - ac.call(); - } - nextRequest(nBuilder.setUrl(newUrl).build(), future); - return true; - } - } else { - throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); - } - } - return false; - } - - private final class HttpProtocol implements Protocol { - // @Override - public void handle(final ChannelHandlerContext ctx, final HttpObject e) throws Exception { - final NettyResponseFuture future = (NettyResponseFuture) ctx.attr(DEFAULT_ATTRIBUTE).get(); - future.touch(); - - // The connect timeout occured. - if (future.isCancelled() || future.isDone()) { - finishChannel(ctx); - return; - } - - HttpRequest nettyRequest = future.getNettyRequest(); - AsyncHandler handler = future.getAsyncHandler(); - Request request = future.getRequest(); - ProxyServer proxyServer = future.getProxyServer(); - HttpResponse response = null; - try { - if (e instanceof FullHttpResponse) { - response = (FullHttpResponse) e; - - log.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); - - // Required if there is some trailing headers. - future.setHttpResponse(response); - - int statusCode = response.getStatus().code(); - - String ka = response.headers().get(HttpHeaders.Names.CONNECTION); - future.setKeepAlive(ka == null || ! ka.toLowerCase().equals("close")); - - List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - HttpResponseStatus status = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response, NettyAsyncHttpProvider.this); - FilterContext fc = new FilterContext.FilterContextBuilder() - .asyncHandler(handler) - .request(request) - .responseStatus(status) - .responseHeaders(responseHeaders) - .build(); - - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - } - - // The handler may have been wrapped. - handler = fc.getAsyncHandler(); - future.setAsyncHandler(handler); - - // The request has changed - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - - Realm newRealm = null; - final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); - final RequestBuilder builder = new RequestBuilder(future.getRequest()); - - //if (realm != null && !future.getURI().getPath().equalsIgnoreCase(realm.getUri())) { - // builder.setUrl(future.getURI().toString()); - //} - - if (statusCode == 401 - && realm != null - && wwwAuth.size() > 0 - && !future.getAndSetAuth(true)) { - - future.setState(NettyResponseFuture.STATE.NEW); - // NTLM - if (!wwwAuth.contains("Kerberos") && (wwwAuth.contains("NTLM") || (wwwAuth.contains("Negotiate")))) { - newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (wwwAuth.contains("Negotiate")) { - newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) return; - } else { - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()) - .setUri(request.getURI().getPath()) - .setMethodName(request.getMethod()) - .setUsePreemptiveAuth(true) - .parseWWWAuthenticateHeader(wwwAuth.get(0)) - .build(); - } - - final Realm nr = new Realm.RealmBuilder().clone(newRealm) - .setUri(URI.create(request.getUrl()).getPath()).build(); - - log.debug("Sending authentication to {}", request.getUrl()); - AsyncCallable ac = new AsyncCallable(future) { - public Object call() throws Exception { - drainChannel(ctx, future); - nextRequest(builder.headers().sets(headers).setRealm(nr).build(), future); - return null; - } - }; - - if (future.isKeepAlive() && response.isChunked()) { - // We must make sure there is no bytes left before executing the next request. - ctx.attr(DEFAULT_ATTRIBUTE).set(ac); - } else { - ac.call(); - } - return; - } - - if (statusCode == 100) { - future.getAndSetWriteHeaders(false); - future.getAndSetWriteBody(true); - writeRequest(ctx.c, config, future, nettyRequest); - return; - } - - List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); - if (statusCode == 407 - && realm != null - && proxyAuth.size() > 0 - && !future.getAndSetAuth(true)) { - - log.debug("Sending proxy authentication to {}", request.getUrl()); - - future.setState(NettyResponseFuture.STATE.NEW); - - if (!proxyAuth.contains("Kerberos") && (proxyAuth.get(0).contains("NTLM") || (proxyAuth.contains("Negotiate")))) { - newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (proxyAuth.contains("Negotiate")) { - newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) return; - } else { - newRealm = future.getRequest().getRealm(); - } - - Request req = builder.headers().sets(headers).setRealm(newRealm).build(); - future.setReuseChannel(true); - future.setConnectAllowed(true); - nextRequest(req, future); - return; - } - - if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) - && statusCode == 200) { - - log.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); - - if (future.isKeepAlive()) { - future.attachChannel(ctx.channel(), true); - } - - try { - log.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); - upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); - } catch (Throwable ex) { - abort(future, ex); - } - Request req = builder.build(); - future.setReuseChannel(true); - future.setConnectAllowed(false); - nextRequest(req, future); - return; - } - - if (redirect(request, future, response, ctx)) return; - - if (!future.getAndSetStatusReceived(true) && updateStatusAndInterrupt(handler, status)) { - finishUpdate(future, ctx, response.isChunked()); - return; - } else if (updateHeadersAndInterrupt(handler, responseHeaders)) { - finishUpdate(future, ctx, response.isChunked()); - return; - } else if (!response.isChunked()) { - if (response.getContent().readableBytes() != 0) { - updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), response, NettyAsyncHttpProvider.this, true)); - } - finishUpdate(future, ctx, false); - return; - } - - if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) { - updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), response, NettyAsyncHttpProvider.this, true)); - markAsDone(future, ctx); - drainChannel(ctx, future); - } - - } else if (e.getMessage() instanceof HttpContent) { - HttpContent chunk = (HttpContent) e.getMessage(); - - if (handler != null) { - if (chunk.isLast() || updateBodyAndInterrupt(future, handler, - new ResponseBodyPart(future.getURI(), null, NettyAsyncHttpProvider.this, chunk, chunk.isLast()))) { - if (chunk instanceof DefaultHttpChunkTrailer) { - updateHeadersAndInterrupt(handler, new ResponseHeaders(future.getURI(), - future.getHttpResponse(), NettyAsyncHttpProvider.this, (HttpChunkTrailer) chunk)); - } - finishUpdate(future, ctx, !chunk.isLast()); - } - } - } - } catch (Exception t) { - if (IOException.class.isAssignableFrom(t.getClass()) && config.getIOExceptionFilters().size() > 0) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()) - .request(future.getRequest()).ioException(IOException.class.cast(t)).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - } - - try { - abort(future, t); - } finally { - finishUpdate(future, ctx, false); - throw t; - } - } - } - - // @Override - public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { - } - - // @Override - public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { - } - } - - private final class WebSocketProtocol implements Protocol { - private static final byte OPCODE_TEXT = 0x1; - private static final byte OPCODE_BINARY = 0x2; - private static final byte OPCODE_UNKNOWN = -1; - - protected byte pendingOpcode = OPCODE_UNKNOWN; - - // @Override - public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - NettyResponseFuture future = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler()); - Request request = future.getRequest(); - - if (e.getMessage() instanceof HttpResponse) { - HttpResponse response = (HttpResponse) e.getMessage(); - - HttpResponseStatus s = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response, NettyAsyncHttpProvider.this); - FilterContext fc = new FilterContext.FilterContextBuilder() - .asyncHandler(h) - .request(request) - .responseStatus(s) - .responseHeaders(responseHeaders) - .build(); - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - - } - - // The handler may have been wrapped. - future.setAsyncHandler(fc.getAsyncHandler()); - - // The request has changed - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - - future.setHttpResponse(response); - if (redirect(request, future, response, ctx)) return; - - final org.jboss.netty.handler.codec.http.HttpResponseStatus status = - new org.jboss.netty.handler.codec.http.HttpResponseStatus(101, "Web Socket Protocol Handshake"); - - final boolean validStatus = response.getStatus().equals(status); - final boolean validUpgrade = response.getHeader(HttpHeaders.Names.UPGRADE) != null; - String c = response.getHeader(HttpHeaders.Names.CONNECTION); - if (c == null) { - c = response.getHeader("connection"); - } - - final boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); - - s = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; - - if (!statusReceived) { - h.onClose(new NettyWebSocket(ctx.getChannel()), 1002, "Bad response status " + response.getStatus().getCode()); - future.done(null); - return; - } - - if (!validStatus || !validUpgrade || !validConnection) { - throw new IOException("Invalid handshake response"); - } - - String accept = response.getHeader("Sec-WebSocket-Accept"); - String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().getHeader(WEBSOCKET_KEY)); - if (accept == null || !accept.equals(key)) { - throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); - } - - ctx.getPipeline().replace("ws-decoder", "ws-decoder", new WebSocket08FrameDecoder(false, false)); - ctx.getPipeline().replace("ws-encoder", "ws-encoder", new WebSocket08FrameEncoder(true)); - if (h.onHeadersReceived(responseHeaders) == STATE.CONTINUE) { - h.onSuccess(new NettyWebSocket(ctx.getChannel())); - } - future.done(null); - } else if (e.getMessage() instanceof WebSocketFrame) { - final WebSocketFrame frame = (WebSocketFrame) e.getMessage(); - - if(frame instanceof TextWebSocketFrame) { - pendingOpcode = OPCODE_TEXT; - } - else if(frame instanceof BinaryWebSocketFrame) { - pendingOpcode = OPCODE_BINARY; - } - - HttpChunk webSocketChunk = new HttpChunk() { - private ChannelBuffer content; - - // @Override - public boolean isLast() { - return false; - } - - // @Override - public ChannelBuffer getContent() { - return content; - } - - // @Override - public void setContent(ChannelBuffer content) { - this.content = content; - } - }; - - if (frame.getBinaryData() != null) { - webSocketChunk.setContent(Unpooled.wrappedBuffer(frame.getBinaryData())); - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), null, NettyAsyncHttpProvider.this, webSocketChunk, true); - h.onBodyPartReceived(rp); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - if(pendingOpcode == OPCODE_BINARY) { - webSocket.onBinaryFragment(rp.getBodyPartBytes(),frame.isFinalFragment()); - } - else { - webSocket.onTextFragment(frame.getBinaryData().toString(UTF8),frame.isFinalFragment()); - } - - if (CloseWebSocketFrame.class.isAssignableFrom(frame.getClass())) { - try { - webSocket.onClose(CloseWebSocketFrame.class.cast(frame).getStatusCode(), CloseWebSocketFrame.class.cast(frame).getReasonText()); - } catch (Throwable t) { - // Swallow any exception that may comes from a Netty version released before 3.4.0 - log.trace("", t); - } - } - } - } else { - log.error("Invalid attachment {}", ctx.getAttachment()); - } - } - - //@Override - public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { - try { - log.warn("onError {}", e); - if (ctx.getAttachment() == null || !NettyResponseFuture.class.isAssignableFrom(ctx.getAttachment().getClass())) { - return; - } - - NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - webSocket.onError(e.getCause()); - webSocket.close(); - } catch (Throwable t) { - log.error("onError", t); - } - } - - //@Override - public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { - log.trace("onClose {}", e); - if (ctx.getAttachment() == null || !NettyResponseFuture.class.isAssignableFrom(ctx.getAttachment().getClass())) { - return; - } - - try { - NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - webSocket.close(); - } catch (Throwable t) { - log.error("onError", t); - } - } - } - - private static boolean isWebSocket(URI uri) { - return WEBSOCKET.equalsIgnoreCase(uri.getScheme()) || WEBSOCKET_SSL.equalsIgnoreCase(uri.getScheme()); - } - - private static boolean isSecure(String scheme) { - return HTTPS.equalsIgnoreCase(scheme) || WEBSOCKET_SSL.equalsIgnoreCase(scheme); - } - - private static boolean isSecure(URI uri) { - return isSecure(uri.getScheme()); - } -} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectListener.java b/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectListener.java deleted file mode 100644 index 6a634de9e9..0000000000 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectListener.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - * - */ -package org.asynchttpclient.providers.netty_4; - -import java.io.IOException; -import java.net.ConnectException; -import java.net.URI; -import java.nio.channels.ClosedChannelException; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.net.ssl.HostnameVerifier; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.ssl.SslHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Request; -import org.asynchttpclient.util.ProxyUtils; - - -/** - * Non Blocking connect. - */ -final class NettyConnectListener implements ChannelFutureListener { - private final static Logger logger = LoggerFactory.getLogger(NettyConnectListener.class); - private final AsyncHttpClientConfig config; - private final NettyResponseFuture future; - private final HttpRequest nettyRequest; - private final AtomicBoolean handshakeDone = new AtomicBoolean(false); - - private NettyConnectListener(AsyncHttpClientConfig config, - NettyResponseFuture future, - HttpRequest nettyRequest) { - this.config = config; - this.future = future; - this.nettyRequest = nettyRequest; - } - - public NettyResponseFuture future() { - return future; - } - - public final void operationComplete(ChannelFuture f) throws Exception { - if (f.isSuccess()) { - Channel channel = f.channel(); - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).set(future); - SslHandler sslHandler = (SslHandler) channel.pipeline().get(NettyAsyncHttpProvider.SSL_HANDLER); - if (!handshakeDone.getAndSet(true) && (sslHandler != null)) { - ((SslHandler) channel.pipeline().get(NettyAsyncHttpProvider.SSL_HANDLER)).handshake().addListener(this); - return; - } - - HostnameVerifier v = config.getHostnameVerifier(); - if (sslHandler != null) { - if (!v.verify(future.getURI().getHost(), sslHandler.engine().getSession())) { - ConnectException exception = new ConnectException("HostnameVerifier exception."); - future.abort(exception); - throw exception; - } - } - - future.provider().writeRequest(f.channel(), config, future, nettyRequest); - } else { - Throwable cause = f.cause(); - - logger.debug("Trying to recover a dead cached channel {} with a retry value of {} ", f.channel(), future.canRetry()); - if (future.canRetry() && cause != null && (NettyAsyncHttpProvider.abortOnDisconnectException(cause) - || ClosedChannelException.class.isAssignableFrom(cause.getClass()) - || future.getState() != NettyResponseFuture.STATE.NEW)) { - - logger.debug("Retrying {} ", nettyRequest); - if (future.provider().remotelyClosed(f.channel(), future)) { - return; - } - } - - logger.debug("Failed to recover from exception: {} with channel {}", cause, f.channel()); - - boolean printCause = f.cause() != null && cause.getMessage() != null; - ConnectException e = new ConnectException(printCause ? cause.getMessage() + " to " + future.getURI().toString() : future.getURI().toString()); - if (cause != null) { - e.initCause(cause); - } - future.abort(e); - } - } - - public static class Builder { - private final AsyncHttpClientConfig config; - - private final Request request; - private final AsyncHandler asyncHandler; - private NettyResponseFuture future; - private final NettyAsyncHttpProvider provider; - private final ByteBuf buffer; - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler, - NettyAsyncHttpProvider provider, ByteBuf buffer) { - - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = null; - this.provider = provider; - this.buffer = buffer; - } - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler, - NettyResponseFuture future, NettyAsyncHttpProvider provider, ByteBuf buffer) { - - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = future; - this.provider = provider; - this.buffer = buffer; - } - - public NettyConnectListener build(final URI uri) throws IOException { - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - HttpRequest nettyRequest = NettyAsyncHttpProvider.buildRequest(config, request, uri, true, buffer, proxyServer); - if (future == null) { - future = NettyAsyncHttpProvider.newFuture(uri, request, asyncHandler, nettyRequest, config, provider, proxyServer); - } else { - future.setNettyRequest(nettyRequest); - future.setRequest(request); - } - return new NettyConnectListener(config, future, nettyRequest); - } - } -} diff --git a/providers/netty4/pom.xml b/providers/netty4/pom.xml new file mode 100644 index 0000000000..551ae89a35 --- /dev/null +++ b/providers/netty4/pom.xml @@ -0,0 +1,41 @@ + + + org.asynchttpclient + async-http-client-providers-parent + 2.0.0-SNAPSHOT + + 4.0.0 + async-http-client-netty4-provider + Asynchronous Http Client Netty 4 Provider + + The Async Http Client Netty 4 Provider. + + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + + + + io.netty + netty-all + 4.0.9.Final-SNAPSHOT + + + org.javassist + javassist + 3.18.0-GA + + + + \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java new file mode 100644 index 0000000000..94fff93730 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java @@ -0,0 +1,8 @@ +package org.asynchttpclient.providers.netty4; + +import io.netty.channel.Channel; + +public interface AdditionalChannelInitializer { + + void initChannel(Channel ch) throws Exception; +} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyChunkedInput.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java similarity index 52% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyChunkedInput.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java index d9704ca7a9..22d6b15e92 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyChunkedInput.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java @@ -10,87 +10,67 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.Body; + import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; import io.netty.handler.stream.ChunkedInput; -import java.io.IOException; import java.nio.ByteBuffer; /** * Adapts a {@link Body} to Netty's {@link ChunkedInput}. */ -class BodyChunkedInput - implements ChunkedInput { - - private final Body body; +class BodyChunkedInput implements ChunkedInput { - private final int chunkSize = 1024 * 8; + private static final int DEFAULT_CHUNK_SIZE = 8 * 1024; - private ByteBuffer nextChunk; - - private static final ByteBuffer EOF = ByteBuffer.allocate(0); + private final Body body; + private final int contentLength; + private final int chunkSize; - private boolean endOfInput = false; + private boolean endOfInput; public BodyChunkedInput(Body body) { if (body == null) { throw new IllegalArgumentException("no body specified"); } this.body = body; + contentLength = (int) body.getContentLength(); + if (contentLength <= 0) + chunkSize = DEFAULT_CHUNK_SIZE; + else + chunkSize = Math.min(contentLength, DEFAULT_CHUNK_SIZE); } - private ByteBuffer peekNextChunk() - throws IOException { - - if (nextChunk == null) { + @Override + public ByteBuf readChunk(ChannelHandlerContext ctx) throws Exception { + if (endOfInput) { + return null; + } else { ByteBuffer buffer = ByteBuffer.allocate(chunkSize); - long length = body.read(buffer); - if (length < 0) { - // Negative means this is finished - buffer.flip(); - nextChunk = buffer; + long r = body.read(buffer); + if (r < 0L) { endOfInput = true; - } else if (length == 0) { - // Zero means we didn't get anything this time, but may get next time - buffer.flip(); - nextChunk = null; + return null; } else { + endOfInput = r == contentLength || r < chunkSize && contentLength > 0; buffer.flip(); - nextChunk = buffer; + return Unpooled.wrappedBuffer(buffer); } } - return nextChunk; - } - - /** - * Having no next chunk does not necessarily means end of input, other chunks may arrive later - */ - public boolean hasNextChunk() throws Exception { - return peekNextChunk() != null; } @Override - public boolean readChunk(ByteBuf b) throws Exception { - ByteBuffer buffer = peekNextChunk(); - if (buffer == null || buffer == EOF) { - return false; - } - nextChunk = null; - - b.writeBytes(buffer); - return true; - } - public boolean isEndOfInput() throws Exception { return endOfInput; } + @Override public void close() throws Exception { body.close(); } - } diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyFileRegion.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java similarity index 72% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyFileRegion.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java index f5da85db3b..7a2db0bd79 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/BodyFileRegion.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java @@ -10,24 +10,23 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.RandomAccessBody; -import io.netty.buffer.AbstractReferenceCounted; -import io.netty.buffer.ReferenceCounted; import io.netty.channel.FileRegion; +import io.netty.util.AbstractReferenceCounted; import java.io.IOException; import java.nio.channels.WritableByteChannel; +import org.asynchttpclient.RandomAccessBody; + /** * Adapts a {@link RandomAccessBody} to Netty's {@link FileRegion}. */ -class BodyFileRegion - extends AbstractReferenceCounted - implements FileRegion { +class BodyFileRegion extends AbstractReferenceCounted implements FileRegion { private final RandomAccessBody body; + private long transfered; public BodyFileRegion(RandomAccessBody body) { if (body == null) { @@ -36,20 +35,32 @@ public BodyFileRegion(RandomAccessBody body) { this.body = body; } + @Override public long position() { return 0; } + @Override public long count() { return body.getContentLength(); } - public long transferTo(WritableByteChannel target, long position) - throws IOException { - return body.transferTo(position, Long.MAX_VALUE, target); + @Override + public long transfered() { + return transfered; + } + + @Override + public long transferTo(WritableByteChannel target, long position) throws IOException { + long written = body.transferTo(position, Long.MAX_VALUE, target); + if (written > 0) { + transfered += written; + } + return written; } - public void deallocate() { + @Override + protected void deallocate() { try { body.close(); } catch (IOException e) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java new file mode 100644 index 0000000000..477f55feae --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java @@ -0,0 +1,16 @@ +package org.asynchttpclient.providers.netty4; + +public abstract class Callback { + + private final NettyResponseFuture future; + + public Callback(NettyResponseFuture future) { + this.future = future; + } + + abstract public void call() throws Exception; + + public NettyResponseFuture future() { + return future; + } +} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java new file mode 100644 index 0000000000..3fa4d6751c --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -0,0 +1,529 @@ +package org.asynchttpclient.providers.netty4; + +import static org.asynchttpclient.providers.netty4.util.HttpUtil.HTTP; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; +import io.netty.bootstrap.Bootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.group.ChannelGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.oio.OioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.channel.socket.oio.OioSocketChannel; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.HttpContentCompressor; +import io.netty.handler.codec.http.HttpContentDecompressor; +import io.netty.handler.codec.http.HttpRequestEncoder; +import io.netty.handler.codec.http.HttpResponseDecoder; +import io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder; +import io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder; +import io.netty.handler.ssl.SslHandler; +import io.netty.handler.stream.ChunkedWriteHandler; +import io.netty.util.AttributeKey; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.net.URI; +import java.security.GeneralSecurityException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.Semaphore; + +import javax.net.ssl.SSLEngine; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ConnectionPoolKeyStrategy; +import org.asynchttpclient.ConnectionsPool; +import org.asynchttpclient.providers.netty4.util.CleanupChannelGroup; +import org.asynchttpclient.util.SslUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Channels { + + private static final Logger LOGGER = LoggerFactory.getLogger(Channels.class); + public static final String HTTP_HANDLER = "httpHandler"; + public static final String SSL_HANDLER = "sslHandler"; + public static final String AHC_HANDLER = "httpProcessor"; + public static final String DEFLATER_HANDLER = "deflater"; + public static final String INFLATER_HANDLER = "inflater"; + public static final String CHUNKED_WRITER_HANDLER = "chunkedWriter"; + public static final String HTTP_DECODER_HANDLER = "http-decoder"; + public static final String HTTP_ENCODER_HANDLER = "http-encoder"; + public static final String WS_DECODER_HANDLER = "ws-decoder"; + public static final String WS_ENCODER_HANDLER = "ws-encoder"; + + private static final AttributeKey DEFAULT_ATTRIBUTE = new AttributeKey("default"); + + private final AsyncHttpClientConfig config; + private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; + + private EventLoopGroup eventLoop; + private final Class socketChannelFactory; + private final boolean allowReleaseSocketChannelFactory; + + private final Bootstrap plainBootstrap; + private final Bootstrap secureBootstrap; + private final Bootstrap webSocketBootstrap; + private final Bootstrap secureWebSocketBootstrap; + + public final ConnectionsPool connectionsPool; + public final Semaphore freeConnections; + public final boolean trackConnections; + public final ChannelGroup openChannels = new CleanupChannelGroup("asyncHttpClient") { + @Override + public boolean remove(Object o) { + boolean removed = super.remove(o); + if (removed && trackConnections) { + freeConnections.release(); + } + return removed; + } + }; + + private NettyChannelHandler httpProcessor; + + public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig asyncHttpProviderConfig) { + + this.config = config; + this.asyncHttpProviderConfig = asyncHttpProviderConfig; + + if (asyncHttpProviderConfig.isUseBlockingIO()) { + socketChannelFactory = OioSocketChannel.class; + this.allowReleaseSocketChannelFactory = true; + } else { + // check if external NioClientSocketChannelFactory is defined + Class scf = asyncHttpProviderConfig.getSocketChannel(); + if (scf != null) { + this.socketChannelFactory = scf; + + // cannot allow releasing shared channel factory + this.allowReleaseSocketChannelFactory = false; + } else { + socketChannelFactory = NioSocketChannel.class; + eventLoop = asyncHttpProviderConfig.getEventLoopGroup(); + if (eventLoop == null) { + if (socketChannelFactory == OioSocketChannel.class) { + eventLoop = new OioEventLoopGroup(); + } else if (socketChannelFactory == NioSocketChannel.class) { + eventLoop = new NioEventLoopGroup(); + } else { + throw new IllegalArgumentException("No set event loop compatbile with socket channel " + scf); + } + } + int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); + LOGGER.debug("Number of application's worker threads is {}", numWorkers); + this.allowReleaseSocketChannelFactory = true; + } + } + + plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); + secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); + webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); + secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); + + // This is dangerous as we can't catch a wrong typed ConnectionsPool + ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); + if (cp == null) { + if (config.getAllowPoolingConnection()) { + cp = new NettyConnectionsPool(config); + } else { + cp = new NonConnectionsPool(); + } + } + this.connectionsPool = cp; + if (config.getMaxTotalConnections() != -1) { + trackConnections = true; + freeConnections = new Semaphore(config.getMaxTotalConnections()); + } else { + trackConnections = false; + freeConnections = null; + } + + Map> optionMap = new HashMap>(); + for (Field field : ChannelOption.class.getDeclaredFields()) { + if (field.getType().isAssignableFrom(ChannelOption.class)) { + field.setAccessible(true); + try { + optionMap.put(field.getName(), (ChannelOption) field.get(null)); + } catch (IllegalAccessException ex) { + throw new Error(ex); + } + } + } + + if (asyncHttpProviderConfig != null) { + for (Entry entry : asyncHttpProviderConfig.propertiesSet()) { + ChannelOption key = optionMap.get(entry.getKey()); + if (key != null) { + Object value = entry.getValue(); + plainBootstrap.option(key, value); + webSocketBootstrap.option(key, value); + secureBootstrap.option(key, value); + secureWebSocketBootstrap.option(key, value); + } else { + throw new IllegalArgumentException("Unknown config property " + entry.getKey()); + } + } + } + + // FIXME clean up + plainBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); + webSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); + secureBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); + secureWebSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); + + // FIXME What was the meaning of this and what is it still a matter with + // Netty4 + // DefaultChannelFuture.setUseDeadLockChecker(false); + } + + public void configure(final NettyChannelHandler httpProcessor) { + this.httpProcessor = httpProcessor; + + ChannelInitializer httpChannelInitializer = new ChannelInitializer() { + + @Override + protected void initChannel(Channel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline()/**/ + .addLast(HTTP_HANDLER, newHttpClientCodec()); + + if (config.getRequestCompressionLevel() > 0) { + pipeline.addLast(DEFLATER_HANDLER, new HttpContentCompressor(config.getRequestCompressionLevel())); + } + + if (config.isCompressionEnabled()) { + pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); + } + pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())/**/ + .addLast(AHC_HANDLER, httpProcessor); + + if (asyncHttpProviderConfig.getHttpAdditionalChannelInitializer() != null) { + asyncHttpProviderConfig.getHttpAdditionalChannelInitializer().initChannel(ch); + } + } + }; + + ChannelInitializer webSocketChannelInitializer = new ChannelInitializer() { + @Override + protected void initChannel(Channel ch) throws Exception { + ch.pipeline()/**/ + .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())/**/ + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())/**/ + .addLast(AHC_HANDLER, httpProcessor); + + if (asyncHttpProviderConfig.getWsAdditionalChannelInitializer() != null) { + asyncHttpProviderConfig.getWsAdditionalChannelInitializer().initChannel(ch); + } + } + }; + + plainBootstrap.handler(httpChannelInitializer); + webSocketBootstrap.handler(webSocketChannelInitializer); + } + + public Bootstrap getBootstrap(String url, boolean useSSl) { + Bootstrap bootstrap = url.startsWith(WEBSOCKET) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap : plainBootstrap); + + return bootstrap; + } + + public void close() { + connectionsPool.destroy(); + openChannels.close(); + for (Channel channel : openChannels) { + Object attribute = getDefaultAttribute(channel); + if (attribute instanceof NettyResponseFuture) { + NettyResponseFuture future = (NettyResponseFuture) attribute; + future.setReaperFuture(null); + } + } + if (this.allowReleaseSocketChannelFactory) { + eventLoop.shutdownGracefully(); + } + } + + void constructSSLPipeline(final NettyResponseFuture future) { + + secureBootstrap.handler(new ChannelInitializer() { + + @Override + protected void initChannel(Channel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline(); + + try { + pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); + } catch (Throwable ex) { + abort(future, ex); + } + + pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); + + if (config.isCompressionEnabled()) { + pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); + } + pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())/**/ + .addLast(AHC_HANDLER, httpProcessor); + + if (asyncHttpProviderConfig.getHttpsAdditionalChannelInitializer() != null) { + asyncHttpProviderConfig.getHttpsAdditionalChannelInitializer().initChannel(ch); + } + } + }); + + secureWebSocketBootstrap.handler(new ChannelInitializer() { + + @Override + protected void initChannel(Channel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline(); + + try { + pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); + } catch (Throwable ex) { + abort(future, ex); + } + + pipeline.addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())/**/ + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())/**/ + .addLast(AHC_HANDLER, httpProcessor); + + if (asyncHttpProviderConfig.getWssAdditionalChannelInitializer() != null) { + asyncHttpProviderConfig.getWssAdditionalChannelInitializer().initChannel(ch); + } + } + }); + } + + private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException { + SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine(); + if (sslEngine == null) { + sslEngine = SslUtils.getSSLEngine(); + } + return sslEngine; + } + + public Channel verifyChannelPipeline(Channel channel, String scheme) throws IOException, GeneralSecurityException { + + if (channel.pipeline().get(SSL_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { + channel.pipeline().remove(SSL_HANDLER); + } else if (channel.pipeline().get(HTTP_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { + return channel; + } else if (channel.pipeline().get(SSL_HANDLER) == null && isSecure(scheme)) { + channel.pipeline().addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); + } + return channel; + } + + protected HttpClientCodec newHttpClientCodec() { + if (asyncHttpProviderConfig != null) { + return new HttpClientCodec(asyncHttpProviderConfig.getMaxInitialLineLength(), asyncHttpProviderConfig.getMaxHeaderSize(), asyncHttpProviderConfig.getMaxChunkSize(), + false); + + } else { + return new HttpClientCodec(); + } + } + + public void upgradeProtocol(ChannelPipeline p, String scheme) throws IOException, GeneralSecurityException { + if (p.get(HTTP_HANDLER) != null) { + p.remove(HTTP_HANDLER); + } + + if (isSecure(scheme)) { + if (p.get(SSL_HANDLER) == null) { + p.addFirst(HTTP_HANDLER, newHttpClientCodec()); + p.addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); + } else { + p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); + } + + } else { + p.addFirst(HTTP_HANDLER, newHttpClientCodec()); + } + } + + public static void upgradePipelineForWebSockets(ChannelHandlerContext ctx) { + ctx.pipeline().replace(Channels.HTTP_ENCODER_HANDLER, Channels.WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true)); + // ctx.pipeline().get(HttpResponseDecoder.class).replace("ws-decoder", + // new WebSocket08FrameDecoder(false, false)); + // FIXME Right way? Which maxFramePayloadLength? Configurable I + // guess + ctx.pipeline().replace(Channels.HTTP_DECODER_HANDLER, Channels.WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, 10 * 1024)); + } + + public Channel lookupInCache(URI uri, ConnectionPoolKeyStrategy connectionPoolKeyStrategy) { + final Channel channel = connectionsPool.poll(connectionPoolKeyStrategy.getKey(uri)); + + if (channel != null) { + LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri); + + try { + // Always make sure the channel who got cached support the + // proper protocol. It could + // only occurs when a HttpMethod.CONNECT is used against a proxy + // that require upgrading from http to + // https. + return verifyChannelPipeline(channel, uri.getScheme()); + } catch (Exception ex) { + LOGGER.debug(ex.getMessage(), ex); + } + } + return null; + } + + public boolean acquireConnection(AsyncHandler asyncHandler) throws IOException { + + if (!connectionsPool.canCacheConnection()) { + IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); + try { + asyncHandler.onThrowable(ex); + } catch (Throwable t) { + LOGGER.warn("!connectionsPool.canCacheConnection()", t); + } + throw ex; + } + + if (trackConnections) { + if (freeConnections.tryAcquire()) { + return true; + } else { + IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); + try { + asyncHandler.onThrowable(ex); + } catch (Throwable t) { + LOGGER.warn("!connectionsPool.canCacheConnection()", t); + } + throw ex; + } + } + + return false; + } + + public void registerChannel(Channel channel) { + openChannels.add(channel); + } + + public boolean offerToPool(String key, Channel channel) { + return connectionsPool.offer(key, channel); + } + + public void releaseFreeConnections() { + freeConnections.release(); + } + + public void removeFromPool(ChannelHandlerContext ctx) { + connectionsPool.removeAll(ctx.channel()); + } + + public void closeChannel(ChannelHandlerContext ctx) { + removeFromPool(ctx); + finishChannel(ctx); + } + + public void finishChannel(ChannelHandlerContext ctx) { + setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + + // The channel may have already been removed if a timeout occurred, and + // this method may be called just after. + if (ctx.channel() == null) { + return; + } + + LOGGER.debug("Closing Channel {} ", ctx.channel()); + + try { + ctx.channel().close(); + } catch (Throwable t) { + LOGGER.debug("Error closing a connection", t); + } + + if (ctx.channel() != null) { + openChannels.remove(ctx.channel()); + } + } + + public void drainChannel(final ChannelHandlerContext ctx, final NettyResponseFuture future) { + setDefaultAttribute(ctx, new Callback(future) { + public void call() throws Exception { + if (!(future.isKeepAlive() && ctx.channel().isActive() && connectionsPool.offer(getPoolKey(future), ctx.channel()))) { + finishChannel(ctx); + } + } + }); + } + + public String getPoolKey(NettyResponseFuture future) { + URI uri = future.getProxyServer() != null ? future.getProxyServer().getURI() : future.getURI(); + return future.getConnectionPoolKeyStrategy().getKey(uri); + } + + public void removeAll(Channel channel) { + connectionsPool.removeAll(channel); + } + + public void abort(NettyResponseFuture future, Throwable t) { + Channel channel = future.channel(); + if (channel != null && openChannels.contains(channel)) { + closeChannel(channel.pipeline().context(NettyChannelHandler.class)); + openChannels.remove(channel); + } + + if (!future.isCancelled() && !future.isDone()) { + LOGGER.debug("Aborting Future {}\n", future); + LOGGER.debug(t.getMessage(), t); + } + + future.abort(t); + } + + public static SslHandler getSslHandler(Channel channel) { + return (SslHandler) channel.pipeline().get(Channels.SSL_HANDLER); + } + + public static Object getDefaultAttribute(Channel channel) { + return getDefaultAttribute(channel.pipeline().context(NettyChannelHandler.class)); + } + + public static Object getDefaultAttribute(ChannelHandlerContext ctx) { + return ctx.attr(DEFAULT_ATTRIBUTE).get(); + } + + public static void setDefaultAttribute(Channel channel, Object o) { + setDefaultAttribute(channel.pipeline().context(NettyChannelHandler.class), o); + } + + public static void setDefaultAttribute(ChannelHandlerContext ctx, Object o) { + ctx.attr(DEFAULT_ATTRIBUTE).set(o); + } + + private static class NonConnectionsPool implements ConnectionsPool { + + public boolean offer(String uri, Channel connection) { + return false; + } + + public Channel poll(String uri) { + return null; + } + + public boolean removeAll(Channel connection) { + return false; + } + + public boolean canCacheConnection() { + return true; + } + + public void destroy() { + } + } +} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java new file mode 100644 index 0000000000..e8f408c095 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java @@ -0,0 +1,18 @@ +package org.asynchttpclient.providers.netty4; + +import java.nio.charset.Charset; + +public class Constants { + + // FIXME move into a state class along with isClose + public static final ThreadLocal IN_IO_THREAD = new ThreadLocalBoolean(); + + // FIXME what to do with this??? + public final static int MAX_BUFFERED_BYTES = 8192; + + // FIXME move to API module + public static final Charset UTF8 = Charset.forName("UTF-8"); + + private Constants() { + } +} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java new file mode 100644 index 0000000000..6796d5bbc7 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java @@ -0,0 +1,6 @@ +package org.asynchttpclient.providers.netty4; + +// Simple marker for stopping publishing bytes. +public enum DiscardEvent { + INSTANCE; +} \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/FeedableBodyGenerator.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java similarity index 98% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/FeedableBodyGenerator.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java index cd75684988..7bcd37442d 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/FeedableBodyGenerator.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java new file mode 100644 index 0000000000..b331f6a61d --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java @@ -0,0 +1,94 @@ +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty4; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.AsyncHttpProvider; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.Request; +import org.asynchttpclient.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NettyAsyncHttpProvider implements AsyncHttpProvider { + + static final Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); + + private final AsyncHttpClientConfig config; + private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; + private final AtomicBoolean isClose = new AtomicBoolean(false); + private final Channels channels; + private final NettyRequestSender requestSender; + private final NettyChannelHandler channelHandler; + private final boolean executeConnectAsync; + + public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { + + this.config = config; + if (config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig) { + asyncHttpProviderConfig = NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()); + } else { + asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); + } + + channels = new Channels(config, asyncHttpProviderConfig); + requestSender = new NettyRequestSender(isClose, config, channels); + channelHandler = new NettyChannelHandler(config, requestSender, channels, isClose); + channels.configure(channelHandler); + + executeConnectAsync = asyncHttpProviderConfig.isAsyncConnect(); + // FIXME + // if (!executeConnectAsync) { + // DefaultChannelFuture.setUseDeadLockChecker(true); + // } + } + + @Override + public String toString() { + return String.format("NettyAsyncHttpProvider4:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections() + - channels.freeConnections.availablePermits(), channels.openChannels.toString(), channels.connectionsPool.toString()); + } + + @Override + public void close() { + isClose.set(true); + try { + channels.close(); + config.executorService().shutdown(); + config.reaper().shutdown(); + } catch (Throwable t) { + LOGGER.warn("Unexpected error on close", t); + } + } + + @Override + public Response prepareResponse(final HttpResponseStatus status, final HttpResponseHeaders headers, final List bodyParts) { + throw new UnsupportedOperationException("Mocked, should be refactored"); + } + + @Override + public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { + return requestSender.doConnect(request, asyncHandler, null, true, executeConnectAsync, false); + } +} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProviderConfig.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java similarity index 75% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProviderConfig.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java index 86beea6864..d008d6b825 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyAsyncHttpProviderConfig.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java @@ -14,20 +14,22 @@ * under the License. * */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.socket.SocketChannel; import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.asynchttpclient.AsyncHttpProviderConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.asynchttpclient.AsyncHttpProviderConfig; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.socket.SocketChannel; - /** * This class can be used to pass Netty's internal configuration options. See Netty documentation for more information. */ @@ -49,6 +51,11 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig socketChannel; + + private AdditionalChannelInitializer httpAdditionalChannelInitializer; + private AdditionalChannelInitializer wsAdditionalChannelInitializer; + private AdditionalChannelInitializer httpsAdditionalChannelInitializer; + private AdditionalChannelInitializer wssAdditionalChannelInitializer; /** * Execute the connect operation asynchronously. @@ -195,4 +202,36 @@ public int getMaxChunkSize() { public void setMaxChunkSize(int maxChunkSize) { this.maxChunkSize = maxChunkSize; } + + public AdditionalChannelInitializer getHttpAdditionalChannelInitializer() { + return httpAdditionalChannelInitializer; + } + + public void setHttpAdditionalChannelInitializer(AdditionalChannelInitializer httpAdditionalChannelInitializer) { + this.httpAdditionalChannelInitializer = httpAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getWsAdditionalChannelInitializer() { + return wsAdditionalChannelInitializer; + } + + public void setWsAdditionalChannelInitializer(AdditionalChannelInitializer wsAdditionalChannelInitializer) { + this.wsAdditionalChannelInitializer = wsAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getHttpsAdditionalChannelInitializer() { + return httpsAdditionalChannelInitializer; + } + + public void setHttpsAdditionalChannelInitializer(AdditionalChannelInitializer httpsAdditionalChannelInitializer) { + this.httpsAdditionalChannelInitializer = httpsAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getWssAdditionalChannelInitializer() { + return wssAdditionalChannelInitializer; + } + + public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssAdditionalChannelInitializer) { + this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer; + } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java new file mode 100644 index 0000000000..c35e985be7 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -0,0 +1,887 @@ +package org.asynchttpclient.providers.netty4; + +import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE; +import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; +import static io.netty.handler.codec.http.HttpResponseStatus.MOVED_PERMANENTLY; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static io.netty.handler.codec.http.HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED; +import static io.netty.handler.codec.http.HttpResponseStatus.SEE_OTHER; +import static io.netty.handler.codec.http.HttpResponseStatus.TEMPORARY_REDIRECT; +import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.HTTP; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isNTLM; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.handler.codec.PrematureChannelClosureException; +import io.netty.handler.codec.http.DefaultHttpContent; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.channels.ClosedChannelException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHandler.STATE; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Cookie; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.MaxRedirectException; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.IOExceptionFilter; +import org.asynchttpclient.filter.ResponseFilter; +import org.asynchttpclient.ntlm.NTLMEngine; +import org.asynchttpclient.ntlm.NTLMEngineException; +import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; +import org.asynchttpclient.providers.netty4.spnego.SpnegoEngine; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.asynchttpclient.websocket.WebSocketUpgradeHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Sharable +public class NettyChannelHandler extends ChannelInboundHandlerAdapter { + + private static final Logger LOGGER = LoggerFactory.getLogger(NettyChannelHandler.class); + + private final AsyncHttpClientConfig config; + private final NettyRequestSender requestSender; + private final Channels channels; + private final AtomicBoolean isClose; + private final Protocol httpProtocol = new HttpProtocol(); + private final Protocol webSocketProtocol = new WebSocketProtocol(); + + public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requestSender, Channels channels, AtomicBoolean isClose) { + this.config = config; + this.requestSender = requestSender; + this.channels = channels; + this.isClose = isClose; + } + + @Override + public void channelRead(final ChannelHandlerContext ctx, Object e) throws Exception { + + Constants.IN_IO_THREAD.set(Boolean.TRUE); + + Object attribute = Channels.getDefaultAttribute(ctx); + + if (attribute instanceof Callback) { + Callback ac = (Callback) attribute; + if (e instanceof LastHttpContent || !(e instanceof HttpContent)) { + ac.call(); + Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + } + + } else if (attribute instanceof NettyResponseFuture) { + Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); + NettyResponseFuture future = (NettyResponseFuture) attribute; + + if (!(future.isIgnoreNextContents() && e instanceof HttpContent)) { + p.handle(ctx, future, e); + } + + } else if (attribute != DiscardEvent.INSTANCE) { + try { + LOGGER.trace("Closing an orphan channel {}", ctx.channel()); + ctx.channel().close(); + } catch (Throwable t) { + } + } + } + + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + + if (isClose.get()) { + return; + } + + try { + super.channelInactive(ctx); + } catch (Exception ex) { + LOGGER.trace("super.channelClosed", ex); + } + + channels.removeFromPool(ctx); + Object attachment = Channels.getDefaultAttribute(ctx); + LOGGER.debug("Channel Closed: {} with attachment {}", ctx.channel(), attachment); + + if (attachment instanceof Callback) { + Callback callback = (Callback) attachment; + Channels.setDefaultAttribute(ctx, callback.future()); + callback.call(); + + } else if (attachment instanceof NettyResponseFuture) { + NettyResponseFuture future = (NettyResponseFuture) attachment; + future.touch(); + + if (!config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { + return; + } + + Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); + p.onClose(ctx); + + if (future != null && !future.isDone() && !future.isCancelled()) { + if (!requestSender.retry(ctx.channel(), future)) { + channels.abort(future, new IOException("Remotely Closed")); + } + } else { + channels.closeChannel(ctx); + } + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { + Channel channel = ctx.channel(); + Throwable cause = e.getCause() != null ? e.getCause() : e; + NettyResponseFuture future = null; + + if (cause instanceof PrematureChannelClosureException) { + return; + } + + LOGGER.debug("Unexpected I/O exception on channel {}", channel, cause); + + try { + if (cause instanceof ClosedChannelException) { + return; + } + + Object attribute = Channels.getDefaultAttribute(ctx); + if (attribute instanceof NettyResponseFuture) { + future = (NettyResponseFuture) attribute; + future.attachChannel(null, false); + future.touch(); + + if (cause instanceof IOException) { + + // FIXME why drop the original exception and create a new + // one? + if (!config.getIOExceptionFilters().isEmpty()) { + if (applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { + return; + } + } else { + // Close the channel so the recovering can occurs. + try { + ctx.channel().close(); + } catch (Throwable t) { + // Swallow. + } + return; + } + } + + if (NettyResponseFutures.abortOnReadCloseException(cause) || NettyResponseFutures.abortOnWriteCloseException(cause)) { + LOGGER.debug("Trying to recover from dead Channel: {}", channel); + return; + } + } else if (attribute instanceof Callback) { + future = Callback.class.cast(attribute).future(); + } + } catch (Throwable t) { + cause = t; + } + + if (future != null) { + try { + LOGGER.debug("Was unable to recover Future: {}", future); + channels.abort(future, cause); + } catch (Throwable t) { + LOGGER.error(t.getMessage(), t); + } + } + + Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); + p.onError(ctx, e); + + channels.closeChannel(ctx); + // FIXME not really sure + // ctx.fireChannelRead(e); + ctx.close(); + } + + private boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, IOException e) throws IOException { + + boolean replayed = false; + + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(e).build(); + for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { + try { + fc = asyncFilter.filter(fc); + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + if (fc.replayRequest()) { + requestSender.replayRequest(future, fc, ctx); + replayed = true; + } + return replayed; + } + + private boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { + + int statusCode = response.getStatus().code(); + boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); + if (redirectEnabled && (statusCode == MOVED_PERMANENTLY.code() || statusCode == FOUND.code() || statusCode == SEE_OTHER.code() || statusCode == TEMPORARY_REDIRECT.code())) { + + if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { + // We must allow 401 handling again. + future.getAndSetAuth(false); + + String location = response.headers().get(HttpHeaders.Names.LOCATION); + URI uri = AsyncHttpProviderUtils.getRedirectUri(future.getURI(), location); + + if (!uri.toString().equals(future.getURI().toString())) { + final RequestBuilder nBuilder = new RequestBuilder(future.getRequest()); + if (config.isRemoveQueryParamOnRedirect()) { + nBuilder.setQueryParameters(null); + } + + // FIXME what about 307? + if (!(statusCode < FOUND.code() || statusCode > SEE_OTHER.code()) && !(statusCode == FOUND.code() && config.isStrict302Handling())) { + nBuilder.setMethod(HttpMethod.GET.name()); + } + + // in case of a redirect from HTTP to HTTPS, those values + // might be different + final boolean initialConnectionKeepAlive = future.isKeepAlive(); + final String initialPoolKey = channels.getPoolKey(future); + + future.setURI(uri); + String newUrl = uri.toString(); + if (request.getUrl().startsWith(WEBSOCKET)) { + newUrl = newUrl.replace(HTTP, WEBSOCKET); + } + + LOGGER.debug("Redirecting to {}", newUrl); + for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE)) { + for (Cookie c : CookieDecoder.decode(cookieStr)) { + nBuilder.addOrReplaceCookie(c); + } + } + + for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE2)) { + for (Cookie c : CookieDecoder.decode(cookieStr)) { + nBuilder.addOrReplaceCookie(c); + } + } + + Callback callback = new Callback(future) { + public void call() throws Exception { + if (!(initialConnectionKeepAlive && ctx.channel().isActive() && channels.offerToPool(initialPoolKey, ctx.channel()))) { + channels.finishChannel(ctx); + } + } + }; + + if (HttpHeaders.isTransferEncodingChunked(response)) { + // We must make sure there is no bytes left before + // executing the next request. + Channels.setDefaultAttribute(ctx, callback); + } else { + callback.call(); + } + + Request target = nBuilder.setUrl(newUrl).build(); + future.setRequest(target); + requestSender.execute(target, future); + return true; + } + } else { + throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); + } + } + return false; + } + + private final class HttpProtocol implements Protocol { + + private Realm kerberosChallenge(List proxyAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + + URI uri = request.getURI(); + String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost(); + String server = proxyServer == null ? host : proxyServer.getHost(); + try { + String challengeHeader = SpnegoEngine.instance().generateToken(server); + headers.remove(HttpHeaders.Names.AUTHORIZATION); + headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); + + Realm.RealmBuilder realmBuilder; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + } else { + realmBuilder = new Realm.RealmBuilder(); + } + return realmBuilder.setUri(uri.getRawPath()).setMethodName(request.getMethod()).setScheme(Realm.AuthScheme.KERBEROS).build(); + } catch (Throwable throwable) { + if (isNTLM(proxyAuth)) { + return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); + } + channels.abort(future, throwable); + return null; + } + } + + private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + + boolean useRealm = (proxyServer == null && realm != null); + + String ntlmDomain = useRealm ? realm.getNtlmDomain() : proxyServer.getNtlmDomain(); + String ntlmHost = useRealm ? realm.getNtlmHost() : proxyServer.getHost(); + String principal = useRealm ? realm.getPrincipal() : proxyServer.getPrincipal(); + String password = useRealm ? realm.getPassword() : proxyServer.getPassword(); + + Realm newRealm; + if (realm != null && !realm.isNtlmMessageType2Received()) { + String challengeHeader = NTLMEngine.INSTANCE.generateType1Msg(ntlmDomain, ntlmHost); + + URI uri = request.getURI(); + headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); + newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(uri.getRawPath()).setMethodName(request.getMethod()) + .setNtlmMessageType2Received(true).build(); + future.getAndSetAuth(false); + } else { + addType3NTLMAuthorizationHeader(wwwAuth, headers, principal, password, ntlmDomain, ntlmHost); + + Realm.RealmBuilder realmBuilder; + Realm.AuthScheme authScheme; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + authScheme = realm.getAuthScheme(); + } else { + realmBuilder = new Realm.RealmBuilder(); + authScheme = Realm.AuthScheme.NTLM; + } + newRealm = realmBuilder.setScheme(authScheme).setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); + } + + return newRealm; + } + + private Realm ntlmProxyChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + future.getAndSetAuth(false); + headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); + + addType3NTLMAuthorizationHeader(wwwAuth, headers, proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost()); + + Realm newRealm; + Realm.RealmBuilder realmBuilder; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + } else { + realmBuilder = new Realm.RealmBuilder(); + } + newRealm = realmBuilder// .setScheme(realm.getAuthScheme()) + .setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); + + return newRealm; + } + + private void addType3NTLMAuthorizationHeader(List auth, FluentCaseInsensitiveStringsMap headers, String username, String password, String domain, String workstation) + throws NTLMEngineException { + headers.remove(HttpHeaders.Names.AUTHORIZATION); + + if (isNTLM(auth)) { + String serverChallenge = auth.get(0).trim().substring("NTLM ".length()); + String challengeHeader = NTLMEngine.INSTANCE.generateType3Msg(username, password, domain, workstation, serverChallenge); + + headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); + } + } + + private List getAuthorizationToken(Iterable> list, String headerAuth) { + ArrayList l = new ArrayList(); + for (Entry e : list) { + if (e.getKey().equalsIgnoreCase(headerAuth)) { + l.add(e.getValue().trim()); + } + } + return l; + } + + private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { + if (lastValidChunk && future.isKeepAlive()) { + channels.drainChannel(ctx, future); + } else { + if (future.isKeepAlive() && ctx.channel().isActive() && channels.offerToPool(channels.getPoolKey(future), ctx.channel())) { + markAsDone(future, ctx); + return; + } + channels.finishChannel(ctx); + } + markAsDone(future, ctx); + } + + private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { + boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; + if (c.closeUnderlyingConnection()) { + future.setKeepAlive(false); + } + return state; + } + + private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { + // We need to make sure everything is OK before adding the + // connection back to the pool. + try { + future.done(); + } catch (Throwable t) { + // Never propagate exception once we know we are done. + LOGGER.debug(t.getMessage(), t); + } + + if (!future.isKeepAlive() || !ctx.channel().isActive()) { + channels.closeChannel(ctx); + } + } + + private boolean applyResponseFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, HttpResponseStatus status, HttpResponseHeaders responseHeaders) + throws IOException { + + boolean replayed = false; + + AsyncHandler handler = future.getAsyncHandler(); + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(future.getRequest()).responseStatus(status).responseHeaders(responseHeaders) + .build(); + + for (ResponseFilter asyncFilter : config.getResponseFilters()) { + try { + fc = asyncFilter.filter(fc); + // FIXME Is it work protecting against this? + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + // The handler may have been wrapped. + handler = fc.getAsyncHandler(); + future.setAsyncHandler(handler); + + // The request has changed + if (fc.replayRequest()) { + requestSender.replayRequest(future, fc, ctx); + future.setIgnoreNextContents(true); + replayed = true; + } + return replayed; + } + + @Override + public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture future, final Object e) throws Exception { + future.touch(); + + // The connect timeout occurred. + if (future.isCancelled() || future.isDone()) { + channels.finishChannel(ctx); + return; + } + + HttpRequest nettyRequest = future.getNettyRequest(); + AsyncHandler handler = future.getAsyncHandler(); + Request request = future.getRequest(); + ProxyServer proxyServer = future.getProxyServer(); + try { + if (e instanceof HttpResponse) { + HttpResponse response = (HttpResponse) e; + + LOGGER.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); + + int statusCode = response.getStatus().code(); + HttpResponseStatus status = new ResponseStatus(future.getURI(), response); + HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); + final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); + final RequestBuilder builder = new RequestBuilder(future.getRequest()); + Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); + + // store the original headers so we can re-send all them to + // the handler in case of trailing headers + future.setHttpResponse(response); + future.setIgnoreNextContents(false); + + future.setKeepAlive(!HttpHeaders.Values.CLOSE.equalsIgnoreCase(response.headers().get(HttpHeaders.Names.CONNECTION))); + + if (!config.getResponseFilters().isEmpty() && applyResponseFiltersAndReplayRequest(ctx, future, status, responseHeaders)) { + return; + } + + // FIXME handle without returns + if (statusCode == UNAUTHORIZED.code() && realm != null) { + List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); + if (!wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + // NTLM + boolean negociate = wwwAuth.contains("Negotiate"); + if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || negociate)) { + newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + future.setIgnoreNextContents(true); + return; + } + } else { + newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()) + .setMethodName(request.getMethod()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); + } + + final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); + + LOGGER.debug("Sending authentication to {}", request.getUrl()); + Callback callback = new Callback(future) { + public void call() throws Exception { + channels.drainChannel(ctx, future); + requestSender.execute(builder.setHeaders(headers).setRealm(nr).build(), future); + } + }; + + if (future.isKeepAlive() && HttpHeaders.isTransferEncodingChunked(response)) { + // We must make sure there is no bytes left + // before executing the next request. + Channels.setDefaultAttribute(ctx, callback); + } else { + callback.call(); + } + + future.setIgnoreNextContents(true); + return; + } + + } else if (statusCode == CONTINUE.code()) { + future.getAndSetWriteHeaders(false); + future.getAndSetWriteBody(true); + future.setIgnoreNextContents(true); + requestSender.writeRequest(ctx.channel(), config, future); + return; + + } else if (statusCode == PROXY_AUTHENTICATION_REQUIRED.code()) { + List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); + if (realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { + LOGGER.debug("Sending proxy authentication to {}", request.getUrl()); + + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + + boolean negociate = proxyAuth.contains("Negotiate"); + if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || negociate)) { + newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + future.setIgnoreNextContents(true); + return; + } + } else { + newRealm = future.getRequest().getRealm(); + } + + future.setReuseChannel(true); + future.setConnectAllowed(true); + future.setIgnoreNextContents(true); + requestSender.execute(builder.setHeaders(headers).setRealm(newRealm).build(), future); + return; + } + + } else if (statusCode == OK.code() && nettyRequest.getMethod().equals(HttpMethod.CONNECT)) { + + LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); + + if (future.isKeepAlive()) { + future.attachChannel(ctx.channel(), true); + } + + try { + LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); + channels.upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); + } catch (Throwable ex) { + channels.abort(future, ex); + } + future.setReuseChannel(true); + future.setConnectAllowed(false); + future.setIgnoreNextContents(true); + requestSender.execute(builder.build(), future); + return; + + } + + if (redirect(request, future, response, ctx)) { + future.setIgnoreNextContents(true); + return; + + } + + if (!future.getAndSetStatusReceived(true) + && (handler.onStatusReceived(status) != STATE.CONTINUE || handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE)) { + finishUpdate(future, ctx, HttpHeaders.isTransferEncodingChunked(response)); + return; + } + } + + if (handler != null && e instanceof HttpContent) { + HttpContent chunk = (HttpContent) e; + + boolean interrupt = false; + boolean last = chunk instanceof LastHttpContent; + + // FIXME + // Netty 3 provider is broken: in case of trailing headers, + // onHeadersReceived should be called before + // updateBodyAndInterrupt + if (last) { + LastHttpContent lastChunk = (LastHttpContent) chunk; + HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); + if (!trailingHeaders.isEmpty()) { + interrupt = handler.onHeadersReceived(new ResponseHeaders(future.getURI(), future.getHttpResponse().headers(), trailingHeaders)) != STATE.CONTINUE; + } + } + + if (!interrupt && chunk.content().readableBytes() > 0) { + // FIXME why + interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk)); + } + + if (interrupt || last) { + finishUpdate(future, ctx, !last); + } + } + } catch (Exception t) { + if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, IOException.class.cast(t))) { + return; + } + + try { + channels.abort(future, t); + } finally { + finishUpdate(future, ctx, false); + throw t; + } + } + } + + @Override + public void onError(ChannelHandlerContext ctx, Throwable error) { + } + + @Override + public void onClose(ChannelHandlerContext ctx) { + } + } + + private final class WebSocketProtocol implements Protocol { + + private static final byte OPCODE_TEXT = 0x1; + private static final byte OPCODE_BINARY = 0x2; + private static final byte OPCODE_UNKNOWN = -1; + protected byte pendingOpcode = OPCODE_UNKNOWN; + + // We don't need to synchronize as replacing the "ws-decoder" will + // process using the same thread. + private void invokeOnSucces(ChannelHandlerContext ctx, WebSocketUpgradeHandler h) { + if (!h.touchSuccess()) { + try { + h.onSuccess(new NettyWebSocket(ctx.channel())); + } catch (Exception ex) { + LOGGER.warn("onSuccess unexpected exception", ex); + } + } + } + + @Override + public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object e) throws Exception { + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler()); + Request request = future.getRequest(); + + if (e instanceof HttpResponse) { + HttpResponse response = (HttpResponse) e; + + HttpResponseStatus s = new ResponseStatus(future.getURI(), response); + HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); + + // FIXME there's a method for that IIRC + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(h).request(request).responseStatus(s).responseHeaders(responseHeaders).build(); + for (ResponseFilter asyncFilter : config.getResponseFilters()) { + try { + fc = asyncFilter.filter(fc); + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + // The handler may have been wrapped. + future.setAsyncHandler(fc.getAsyncHandler()); + + // The request has changed + if (fc.replayRequest()) { + requestSender.replayRequest(future, fc, ctx); + return; + } + + future.setHttpResponse(response); + if (redirect(request, future, response, ctx)) + return; + + io.netty.handler.codec.http.HttpResponseStatus status = io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; + + boolean validStatus = response.getStatus().equals(status); + boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null; + String c = response.headers().get(HttpHeaders.Names.CONNECTION); + if (c == null) { + c = response.headers().get(HttpHeaders.Names.CONNECTION.toLowerCase()); + } + + boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); + + s = new ResponseStatus(future.getURI(), response); + final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; + + final boolean headerOK = h.onHeadersReceived(responseHeaders) == STATE.CONTINUE; + if (!headerOK || !validStatus || !validUpgrade || !validConnection || !statusReceived) { + channels.abort(future, new IOException("Invalid handshake response")); + return; + } + + String accept = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT); + String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().headers().get(HttpHeaders.Names.SEC_WEBSOCKET_KEY)); + if (accept == null || !accept.equals(key)) { + throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); + } + + Channels.upgradePipelineForWebSockets(ctx); + + invokeOnSucces(ctx, h); + future.done(); + + } else if (e instanceof WebSocketFrame) { + + invokeOnSucces(ctx, h); + + final WebSocketFrame frame = (WebSocketFrame) e; + + if (frame instanceof TextWebSocketFrame) { + pendingOpcode = OPCODE_TEXT; + } else if (frame instanceof BinaryWebSocketFrame) { + pendingOpcode = OPCODE_BINARY; + } + + if (frame.content() != null && frame.content().readableBytes() > 0) { + HttpContent webSocketChunk = new DefaultHttpContent(Unpooled.wrappedBuffer(frame.content())); + ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), webSocketChunk); + h.onBodyPartReceived(rp); + + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + + if (webSocket != null) { + if (pendingOpcode == OPCODE_BINARY) { + webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); + } else { + webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); + } + + if (frame instanceof CloseWebSocketFrame) { + try { + Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + webSocket.onClose(CloseWebSocketFrame.class.cast(frame).statusCode(), CloseWebSocketFrame.class.cast(frame).reasonText()); + } catch (Throwable t) { + // Swallow any exception that may comes from a + // Netty version released before 3.4.0 + LOGGER.trace("", t); + } + } + } else { + LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); + } + } + } else { + LOGGER.error("Invalid message {}", e); + } + } + + @Override + public void onError(ChannelHandlerContext ctx, Throwable e) { + try { + Object attribute = Channels.getDefaultAttribute(ctx); + LOGGER.warn("onError {}", e); + if (!(attribute instanceof NettyResponseFuture)) { + return; + } + + NettyResponseFuture nettyResponse = (NettyResponseFuture) attribute; + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); + + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + if (webSocket != null) { + webSocket.onError(e.getCause()); + webSocket.close(); + } + } catch (Throwable t) { + LOGGER.error("onError", t); + } + } + + @Override + public void onClose(ChannelHandlerContext ctx) { + LOGGER.trace("onClose {}"); + Object attribute = Channels.getDefaultAttribute(ctx); + if (!(attribute instanceof NettyResponseFuture)) { + return; + } + + try { + NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(attribute); + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + + // FIXME How could this test not succeed, attachment is a + // NettyResponseFuture???? + if (attribute != DiscardEvent.INSTANCE) + webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent)."); + } catch (Throwable t) { + LOGGER.error("onError", t); + } + } + } +} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java new file mode 100644 index 0000000000..57c54cdeef --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java @@ -0,0 +1,155 @@ +/* + * Copyright 2010 Ning, Inc. + * + * Ning 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. + * + */ +package org.asynchttpclient.providers.netty4; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.URI; +import java.nio.channels.ClosedChannelException; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.net.ssl.HostnameVerifier; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.ssl.SslHandler; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Request; +import org.asynchttpclient.util.ProxyUtils; + +/** + * Non Blocking connect. + */ +// FIXME Netty 3: NettyConnectListener don't need to be passed the request as +// the future has it too +final class NettyConnectListener implements ChannelFutureListener { + private final static Logger logger = LoggerFactory.getLogger(NettyConnectListener.class); + private final AsyncHttpClientConfig config; + private final NettyRequestSender requestSender; + private final NettyResponseFuture future; + private final AtomicBoolean handshakeDone = new AtomicBoolean(false); + + private NettyConnectListener(AsyncHttpClientConfig config, NettyRequestSender requestSender, NettyResponseFuture future) { + this.requestSender = requestSender; + this.config = config; + this.future = future; + } + + public NettyResponseFuture future() { + return future; + } + + private void onFutureSuccess(final Channel channel) throws Exception { + Channels.setDefaultAttribute(channel, future); + SslHandler sslHandler = Channels.getSslHandler(channel); + + if (sslHandler != null) { + if (!handshakeDone.getAndSet(true)) { + sslHandler.handshakeFuture().addListener(new GenericFutureListener>() { + public void operationComplete(Future f) throws Exception { + if (f.isSuccess()) { + onFutureSuccess(channel); + } else { + onFutureFailure(channel, f.cause()); + } + } + }); + return; + } + + HostnameVerifier v = config.getHostnameVerifier(); + if (!v.verify(future.getURI().getHost(), sslHandler.engine().getSession())) { + ConnectException exception = new ConnectException("HostnameVerifier exception."); + future.abort(exception); + throw exception; + } + } + + requestSender.writeRequest(channel, config, future); + } + + private void onFutureFailure(Channel channel, Throwable cause) throws Exception { + + logger.debug("Trying to recover a dead cached channel {} with a retry value of {} ", channel, future.canRetry()); + if (future.canRetry() && cause != null + && (NettyResponseFutures.abortOnDisconnectException(cause) || cause instanceof ClosedChannelException || future.getState() != NettyResponseFuture.STATE.NEW)) { + + logger.debug("Retrying {} ", future.getNettyRequest()); + // FIXME Netty 3 use the wrong statement + if (requestSender.retry(channel, future)) { + return; + } + } + + logger.debug("Failed to recover from exception: {} with channel {}", cause, channel); + + boolean printCause = cause != null && cause.getMessage() != null; + ConnectException e = new ConnectException(printCause ? cause.getMessage() + " to " + future.getURI().toString() : future.getURI().toString()); + if (cause != null) { + e.initCause(cause); + } + future.abort(e); + } + + public final void operationComplete(ChannelFuture f) throws Exception { + if (f.isSuccess()) { + onFutureSuccess(f.channel()); + } else { + onFutureFailure(f.channel(), f.cause()); + } + } + + public static class Builder { + private final AsyncHttpClientConfig config; + + private final NettyRequestSender requestSender; + private final Request request; + private final AsyncHandler asyncHandler; + private NettyResponseFuture future; + + // FIXME Netty3 useless constructor + public Builder(AsyncHttpClientConfig config, NettyRequestSender requestSender, Request request, AsyncHandler asyncHandler, NettyResponseFuture future) { + + this.config = config; + this.requestSender = requestSender; + this.request = request; + this.asyncHandler = asyncHandler; + this.future = future; + } + + public NettyConnectListener build(final URI uri) throws IOException { + ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); + HttpRequest nettyRequest = NettyRequests.newNettyRequest(config, request, uri, true, proxyServer); + if (future == null) { + future = NettyResponseFutures.newNettyResponseFuture(uri, request, asyncHandler, nettyRequest, config, proxyServer); + } else { + future.setNettyRequest(nettyRequest); + future.setRequest(request); + } + return new NettyConnectListener(config, requestSender, future); + } + } +} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectionsPool.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java similarity index 83% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectionsPool.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java index 6b21e49119..16d9c43ecb 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyConnectionsPool.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java @@ -10,12 +10,10 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.ConnectionsPool; +import static org.asynchttpclient.util.DateUtil.millisTime; import io.netty.channel.Channel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -26,6 +24,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ConnectionsPool; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * A simple implementation of {@link org.asynchttpclient.ConnectionsPool} based on a {@link java.util.concurrent.ConcurrentHashMap} */ @@ -36,19 +39,24 @@ public class NettyConnectionsPool implements ConnectionsPool { private final ConcurrentHashMap channel2IdleChannel = new ConcurrentHashMap(); private final ConcurrentHashMap channel2CreationDate = new ConcurrentHashMap(); private final AtomicBoolean isClosed = new AtomicBoolean(false); - private final Timer idleConnectionDetector = new Timer(true); + private final Timer idleConnectionDetector; private final boolean sslConnectionPoolEnabled; private final int maxTotalConnections; private final int maxConnectionPerHost; private final int maxConnectionLifeTimeInMs; private final long maxIdleTime; - public NettyConnectionsPool(NettyAsyncHttpProvider provider) { - this.maxTotalConnections = provider.getConfig().getMaxTotalConnections(); - this.maxConnectionPerHost = provider.getConfig().getMaxConnectionPerHost(); - this.sslConnectionPoolEnabled = provider.getConfig().isSslConnectionPoolEnabled(); - this.maxIdleTime = provider.getConfig().getIdleConnectionInPoolTimeoutInMs(); - this.maxConnectionLifeTimeInMs = provider.getConfig().getMaxConnectionLifeTimeInMs(); + public NettyConnectionsPool(AsyncHttpClientConfig config) { + this(config.getMaxTotalConnections(), config.getMaxConnectionPerHost(), config.getIdleConnectionInPoolTimeoutInMs(), config.isSslConnectionPoolEnabled(), config.getMaxConnectionLifeTimeInMs(), new Timer(true)); + } + + public NettyConnectionsPool(int maxTotalConnections, int maxConnectionPerHost, long maxIdleTime, boolean sslConnectionPoolEnabled, int maxConnectionLifeTimeInMs, Timer idleConnectionDetector) { + this.maxTotalConnections = maxTotalConnections; + this.maxConnectionPerHost = maxConnectionPerHost; + this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; + this.maxIdleTime = maxIdleTime; + this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; + this.idleConnectionDetector = idleConnectionDetector; this.idleConnectionDetector.schedule(new IdleChannelDetector(), maxIdleTime, maxIdleTime); } @@ -60,7 +68,7 @@ private static class IdleChannel { IdleChannel(String uri, Channel channel) { this.uri = uri; this.channel = channel; - this.start = System.currentTimeMillis(); + this.start = millisTime(); } @Override @@ -96,7 +104,7 @@ public void run() { } List channelsInTimeout = new ArrayList(); - long currentTime = System.currentTimeMillis(); + long currentTime = millisTime(); for (IdleChannel idleChannel : channel2IdleChannel.values()) { long age = currentTime - idleChannel.start; @@ -108,20 +116,20 @@ public void run() { channelsInTimeout.add(idleChannel); } } - long endConcurrentLoop = System.currentTimeMillis(); + long endConcurrentLoop = millisTime(); for (IdleChannel idleChannel : channelsInTimeout) { - Object attachment = idleChannel.channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).get(); + Object attachment = Channels.getDefaultAttribute(idleChannel.channel); if (attachment != null) { - if (NettyResponseFuture.class.isAssignableFrom(attachment.getClass())) { + if (attachment instanceof NettyResponseFuture) { NettyResponseFuture future = (NettyResponseFuture) attachment; - if (!future.isDone() && !future.isCancelled()) { - log.debug("Future not in appropriate state %s\n", future); - continue; + if (!future.isDone() && !future.isCancelled()) { + log.debug("Future not in appropriate state %s\n", future); + continue; + } } } - } if (remove(idleChannel)) { log.debug("Closing Idle Channel {}", idleChannel.channel); @@ -135,7 +143,7 @@ public void run() { openChannels += hostChannels.size(); } log.trace(String.format("%d channel open, %d idle channels closed (times: 1st-loop=%d, 2nd-loop=%d).\n", - openChannels, channelsInTimeout.size(), endConcurrentLoop - currentTime, System.currentTimeMillis() - endConcurrentLoop)); + openChannels, channelsInTimeout.size(), endConcurrentLoop - currentTime, millisTime() - endConcurrentLoop)); } } catch (Throwable t) { log.error("uncaught exception!", t); @@ -155,15 +163,15 @@ public boolean offer(String uri, Channel channel) { Long createTime = channel2CreationDate.get(channel); if (createTime == null){ - channel2CreationDate.putIfAbsent(channel, System.currentTimeMillis()); + channel2CreationDate.putIfAbsent(channel, millisTime()); } - else if (maxConnectionLifeTimeInMs != -1 && (createTime + maxConnectionLifeTimeInMs) < System.currentTimeMillis() ) { + else if (maxConnectionLifeTimeInMs != -1 && (createTime + maxConnectionLifeTimeInMs) < millisTime() ) { log.debug("Channel {} expired", channel); return false; } log.debug("Adding uri: {} for channel {}", uri, channel); - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).set(new NettyAsyncHttpProvider.DiscardEvent()); + Channels.setDefaultAttribute(channel, DiscardEvent.INSTANCE); ConcurrentLinkedQueue idleConnectionForHost = connectionsPool.get(uri); if (idleConnectionForHost == null) { @@ -274,7 +282,7 @@ public void destroy() { private void close(Channel channel) { try { - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).set(new NettyAsyncHttpProvider.DiscardEvent()); + Channels.setDefaultAttribute(channel, DiscardEvent.INSTANCE); channel2CreationDate.remove(channel); channel.close(); } catch (Throwable t) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java new file mode 100644 index 0000000000..92572ccc74 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -0,0 +1,462 @@ +package org.asynchttpclient.providers.netty4; + +import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; +import io.netty.bootstrap.Bootstrap; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelProgressiveFuture; +import io.netty.channel.FileRegion; +import io.netty.handler.codec.http.FullHttpRequest; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.stream.ChunkedFile; +import io.netty.handler.stream.ChunkedStream; +import io.netty.handler.stream.ChunkedWriteHandler; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.RandomAccessFile; +import java.net.ConnectException; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.Map; +import java.util.concurrent.Future; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Body; +import org.asynchttpclient.BodyGenerator; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.RandomAccessBody; +import org.asynchttpclient.Request; +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.generators.InputStreamBodyGenerator; +import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.multipart.MultipartBody; +import org.asynchttpclient.providers.netty4.FeedableBodyGenerator.FeedListener; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.asynchttpclient.util.ProxyUtils; +import org.asynchttpclient.websocket.WebSocketUpgradeHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class NettyRequestSender { + + private static final Logger LOGGER = LoggerFactory.getLogger(NettyRequestSender.class); + + private final AtomicBoolean isClose; + private final AsyncHttpClientConfig config; + private final Channels channels; + + public NettyRequestSender(AtomicBoolean isClose, AsyncHttpClientConfig config, Channels channels) { + this.isClose = isClose; + this.config = config; + this.channels = channels; + } + + public boolean retry(Channel channel, NettyResponseFuture future) { + + boolean success = false; + + if (!isClose.get()) { + channels.removeAll(channel); + + if (future == null) { + Object attachment = Channels.getDefaultAttribute(channel); + if (attachment instanceof NettyResponseFuture) + future = (NettyResponseFuture) attachment; + } + + if (future != null && future.canBeReplayed()) { + future.setState(NettyResponseFuture.STATE.RECONNECTED); + future.getAndSetStatusReceived(false); + + LOGGER.debug("Trying to recover request {}\n", future.getNettyRequest()); + + try { + execute(future.getRequest(), future); + success = true; + + } catch (IOException iox) { + future.setState(NettyResponseFuture.STATE.CLOSED); + future.abort(iox); + LOGGER.error("Remotely Closed, unable to recover", iox); + } + } else { + LOGGER.debug("Unable to recover future {}\n", future); + } + } + return success; + } + + // FIXME Netty 3: only called from nextRequest, useCache, asyncConnect and + // reclaimCache always passed as true + public void execute(final Request request, final NettyResponseFuture f) throws IOException { + doConnect(request, f.getAsyncHandler(), f, true, true, true); + } + + private final boolean validateWebSocketRequest(Request request, AsyncHandler asyncHandler) { + return request.getMethod().equals(HttpMethod.GET.name()) && asyncHandler instanceof WebSocketUpgradeHandler; + } + + public ListenableFuture doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture future, boolean useCache, boolean asyncConnect, + boolean reclaimCache) throws IOException { + + if (isClose.get()) { + throw new IOException("Closed"); + } + + if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) { + throw new IOException("WebSocket method must be a GET"); + } + + ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); + boolean useProxy = proxyServer != null; + URI uri; + if (config.isUseRawUrl()) { + uri = request.getRawURI(); + } else { + uri = request.getURI(); + } + Channel channel = null; + + if (useCache) { + if (future != null && future.reuseChannel() && future.channel() != null) { + channel = future.channel(); + } else { + URI connectionKeyUri = useProxy ? proxyServer.getURI() : uri; + channel = channels.lookupInCache(connectionKeyUri, request.getConnectionPoolKeyStrategy()); + } + } + + boolean useSSl = isSecure(uri) && !useProxy; + if (channel != null && channel.isOpen() && channel.isActive()) { + HttpRequest nettyRequest = null; + + if (future == null) { + nettyRequest = NettyRequests.newNettyRequest(config, request, uri, false, proxyServer); + future = NettyResponseFutures.newNettyResponseFuture(uri, request, asyncHandler, nettyRequest, config, proxyServer); + } else { + nettyRequest = NettyRequests.newNettyRequest(config, request, uri, future.isConnectAllowed(), proxyServer); + future.setNettyRequest(nettyRequest); + } + future.setState(NettyResponseFuture.STATE.POOLED); + future.attachChannel(channel, false); + + LOGGER.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest); + Channels.setDefaultAttribute(channel, future); + + try { + writeRequest(channel, config, future); + } catch (Exception ex) { + LOGGER.debug("writeRequest failure", ex); + if (useSSl && ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) { + LOGGER.debug("SSLEngine failure", ex); + future = null; + } else { + try { + asyncHandler.onThrowable(ex); + } catch (Throwable t) { + LOGGER.warn("doConnect.writeRequest()", t); + } + IOException ioe = new IOException(ex.getMessage()); + ioe.initCause(ex); + throw ioe; + } + } + return future; + } + + // Do not throw an exception when we need an extra connection for a + // redirect. + boolean acquiredConnection = !reclaimCache && channels.acquireConnection(asyncHandler); + + NettyConnectListener cl = new NettyConnectListener.Builder(config, this, request, asyncHandler, future).build(uri); + + boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost()); + + if (useSSl) { + channels.constructSSLPipeline(cl.future()); + } + + Bootstrap bootstrap = channels.getBootstrap(request.getUrl(), useSSl); + + ChannelFuture channelFuture; + try { + InetSocketAddress remoteAddress; + if (request.getInetAddress() != null) { + remoteAddress = new InetSocketAddress(request.getInetAddress(), AsyncHttpProviderUtils.getPort(uri)); + } else if (proxyServer == null || avoidProxy) { + remoteAddress = new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)); + } else { + remoteAddress = new InetSocketAddress(proxyServer.getHost(), proxyServer.getPort()); + } + + if (request.getLocalAddress() != null) { + channelFuture = bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); + } else { + channelFuture = bootstrap.connect(remoteAddress); + } + + } catch (Throwable t) { + if (acquiredConnection) { + channels.releaseFreeConnections(); + } + channels.abort(cl.future(), t.getCause() == null ? t : t.getCause()); + return cl.future(); + } + + // FIXME when can we have a direct invokation??? + // boolean directInvokation = !(IN_IO_THREAD.get() && + // DefaultChannelFuture.isUseDeadLockChecker()); + boolean directInvokation = !Constants.IN_IO_THREAD.get(); + + // FIXME what does it have to do with the presence of a file? + if (directInvokation && !asyncConnect && request.getFile() == null) { + int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; + if (!channelFuture.awaitUninterruptibly(timeOut, TimeUnit.MILLISECONDS)) { + if (acquiredConnection) { + channels.releaseFreeConnections(); + } + // FIXME false or true? + channelFuture.cancel(false); + channels.abort(cl.future(), new ConnectException(String.format("Connect operation to %s timeout %s", uri, timeOut))); + } + + try { + cl.operationComplete(channelFuture); + } catch (Exception e) { + if (acquiredConnection) { + channels.releaseFreeConnections(); + } + IOException ioe = new IOException(e.getMessage()); + ioe.initCause(e); + try { + asyncHandler.onThrowable(ioe); + } catch (Throwable t) { + LOGGER.warn("c.operationComplete()", t); + } + throw ioe; + } + } else { + channelFuture.addListener(cl); + } + + // FIXME Why non cached??? + LOGGER.debug("\nNon cached request \n{}\n\nusing Channel \n{}\n", cl.future().getNettyRequest(), channelFuture.channel()); + + if (!cl.future().isCancelled() || !cl.future().isDone()) { + channels.registerChannel(channelFuture.channel()); + cl.future().attachChannel(channelFuture.channel(), false); + } + return cl.future(); + } + + protected final void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture future) { + try { + // If the channel is dead because it was pooled and the remote + // server decided to close it, we just let it go and the + // closeChannel do it's work. + if (!channel.isOpen() || !channel.isActive()) { + return; + } + + HttpRequest nettyRequest = future.getNettyRequest(); + Body body = null; + if (!nettyRequest.getMethod().equals(HttpMethod.CONNECT)) { + BodyGenerator bg = future.getRequest().getBodyGenerator(); + if (bg != null) { + try { + body = bg.createBody(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + long length = body.getContentLength(); + if (length >= 0) { + nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, length); + } else { + nettyRequest.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); + } + } else if (future.getRequest().getParts() != null) { + String contentType = nettyRequest.headers().get(HttpHeaders.Names.CONTENT_TYPE); + String length = nettyRequest.headers().get(HttpHeaders.Names.CONTENT_LENGTH); + body = new MultipartBody(future.getRequest().getParts(), contentType, length); + } + } + + if (future.getAsyncHandler() instanceof TransferCompletionHandler) { + + FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); + for (Map.Entry entries : future.getNettyRequest().headers()) { + h.add(entries.getKey(), entries.getValue()); + } + + ByteBuf content = nettyRequest instanceof FullHttpRequest ? FullHttpRequest.class.cast(nettyRequest).content() : Unpooled.buffer(0); + TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new NettyTransferAdapter(h, content, future.getRequest().getFile())); + } + + // Leave it to true. + // FIXME Yeah... explain why instead of saying the same thing as the + // code + if (future.getAndSetWriteHeaders(true)) { + try { + channel.writeAndFlush(nettyRequest, channel.newProgressivePromise()).addListener(new ProgressListener(config, true, future.getAsyncHandler(), future)); + } catch (Throwable cause) { + // FIXME why not notify? + LOGGER.debug(cause.getMessage(), cause); + try { + channel.close(); + } catch (RuntimeException ex) { + LOGGER.debug(ex.getMessage(), ex); + } + return; + } + } + + if (future.getAndSetWriteBody(true)) { + if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { + + if (future.getRequest().getFile() != null) { + final File file = future.getRequest().getFile(); + long fileLength = 0; + final RandomAccessFile raf = new RandomAccessFile(file, "r"); + + try { + fileLength = raf.length(); + + ChannelFuture writeFuture; + if (Channels.getSslHandler(channel) != null) { + writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise()); + } else { + FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); + writeFuture = channel.write(region, channel.newProgressivePromise()); + } + writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + raf.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } catch (IOException ex) { + if (raf != null) { + try { + raf.close(); + } catch (IOException e) { + } + } + throw ex; + } + } else if (future.getRequest().getStreamData() != null || future.getRequest().getBodyGenerator() instanceof InputStreamBodyGenerator) { + final InputStream is = future.getRequest().getStreamData() != null ? future.getRequest().getStreamData() : InputStreamBodyGenerator.class.cast( + future.getRequest().getBodyGenerator()).getInputStream(); + + if (future.getAndSetStreamWasAlreadyConsumed()) { + if (is.markSupported()) + is.reset(); + else { + LOGGER.warn("Stream has already been consumed and cannot be reset"); + return; + } + } + + channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + is.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + + } else if (body != null) { + + Object msg; + if (Channels.getSslHandler(channel) == null && body instanceof RandomAccessBody) { + msg = new BodyFileRegion((RandomAccessBody) body); + } else { + BodyGenerator bg = future.getRequest().getBodyGenerator(); + msg = new BodyChunkedInput(body); + if (bg instanceof FeedableBodyGenerator) { + FeedableBodyGenerator.class.cast(bg).setListener(new FeedListener() { + @Override + public void onContentAdded() { + channel.pipeline().get(ChunkedWriteHandler.class).resumeTransfer(); + } + }); + } + } + ChannelFuture writeFuture = channel.write(msg, channel.newProgressivePromise()); + + final Body b = body; + writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + b.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } + } + } + } catch (Throwable ioe) { + try { + channel.close(); + } catch (RuntimeException ex) { + LOGGER.debug(ex.getMessage(), ex); + } + } + + try { + future.touch(); + int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, future.getRequest()); + int schedulePeriod = requestTimeout != -1 ? (config.getIdleConnectionTimeoutInMs() != -1 ? Math.min(requestTimeout, config.getIdleConnectionTimeoutInMs()) + : requestTimeout) : config.getIdleConnectionTimeoutInMs(); + + if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { + ReaperFuture reaperFuture = new ReaperFuture(future, config, isClose, channels); + Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); + reaperFuture.setScheduledFuture(scheduledFuture); + future.setReaperFuture(reaperFuture); + } + } catch (RejectedExecutionException ex) { + channels.abort(future, ex); + } + } + + // FIXME Clean up Netty 3: replayRequest's response parameter is unused + + // WTF return??? + public void replayRequest(final NettyResponseFuture future, FilterContext fc, ChannelHandlerContext ctx) throws IOException { + Request newRequest = fc.getRequest(); + future.setAsyncHandler(fc.getAsyncHandler()); + future.setState(NettyResponseFuture.STATE.NEW); + future.touch(); + + LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); + channels.drainChannel(ctx, future); + execute(newRequest, future); + } +} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java new file mode 100644 index 0000000000..960bd2009a --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java @@ -0,0 +1,321 @@ +package org.asynchttpclient.providers.netty4; + +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isNTLM; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.isWebSocket; +import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; +import static org.asynchttpclient.util.MiscUtil.isNonEmpty; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufOutputStream; +import io.netty.buffer.Unpooled; +import io.netty.handler.codec.http.DefaultFullHttpRequest; +import io.netty.handler.codec.http.DefaultHttpRequest; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpVersion; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Request; +import org.asynchttpclient.multipart.MultipartRequestEntity; +import org.asynchttpclient.ntlm.NTLMEngine; +import org.asynchttpclient.ntlm.NTLMEngineException; +import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieEncoder; +import org.asynchttpclient.providers.netty4.spnego.SpnegoEngine; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.asynchttpclient.util.AuthenticatorUtils; +import org.asynchttpclient.util.UTF8UrlEncoder; + +public class NettyRequests { + + public static HttpRequest newNettyRequest(AsyncHttpClientConfig config, Request request, URI uri, boolean allowConnect, ProxyServer proxyServer) throws IOException { + + String method = request.getMethod(); + if (allowConnect && proxyServer != null && isSecure(uri)) { + method = HttpMethod.CONNECT.toString(); + } + return construct(config, request, new HttpMethod(method), uri, proxyServer); + } + + private static int getPredefinedContentLength(Request request, Map headers) { + int length = (int) request.getContentLength(); + Object contentLength = headers.get(HttpHeaders.Names.CONTENT_LENGTH); + if (length == -1 && contentLength != null) { + length = Integer.valueOf(contentLength.toString()); + } + + return length; + } + + private static HttpRequest construct(AsyncHttpClientConfig config, Request request, HttpMethod m, URI uri, ProxyServer proxyServer) throws IOException { + + String host = null; + HttpVersion httpVersion; + String requestUri; + Map headers = new HashMap(); + ByteBuf content = null; + boolean webSocket = isWebSocket(uri); + + if (request.getVirtualHost() != null) { + host = request.getVirtualHost(); + } else { + host = AsyncHttpProviderUtils.getHost(uri); + } + + if (m.equals(HttpMethod.CONNECT)) { + httpVersion = HttpVersion.HTTP_1_0; + requestUri = AsyncHttpProviderUtils.getAuthority(uri); + } else { + httpVersion = HttpVersion.HTTP_1_1; + if (proxyServer != null && !(isSecure(uri) && config.isUseRelativeURIsWithSSLProxies())) + requestUri = uri.toString(); + else if (uri.getRawQuery() != null) + requestUri = uri.getRawPath() + "?" + uri.getRawQuery(); + else + requestUri = uri.getRawPath(); + } + + if (webSocket) { + headers.put(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET); + headers.put(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); + headers.put(HttpHeaders.Names.ORIGIN, "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort())); + headers.put(HttpHeaders.Names.SEC_WEBSOCKET_KEY, WebSocketUtil.getKey()); + headers.put(HttpHeaders.Names.SEC_WEBSOCKET_VERSION, "13"); + } + + if (host != null) { + if (request.getVirtualHost() != null || uri.getPort() == -1) { + headers.put(HttpHeaders.Names.HOST, host); + } else { + headers.put(HttpHeaders.Names.HOST, host + ":" + uri.getPort()); + } + } else { + host = "127.0.0.1"; + } + + if (!m.equals(HttpMethod.CONNECT)) { + FluentCaseInsensitiveStringsMap h = request.getHeaders(); + if (h != null) { + for (Entry> header : h) { + String name = header.getKey(); + if (!HttpHeaders.Names.HOST.equalsIgnoreCase(name)) { + for (String value : header.getValue()) { + headers.put(name, value); + } + } + } + } + + if (config.isCompressionEnabled()) { + headers.put(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); + } + } else { + List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); + if (isNTLM(auth)) { + headers.put(HttpHeaders.Names.PROXY_AUTHORIZATION, auth.get(0)); + } + } + Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); + + if (realm != null && realm.getUsePreemptiveAuth()) { + + String domain = realm.getNtlmDomain(); + if (proxyServer != null && proxyServer.getNtlmDomain() != null) { + domain = proxyServer.getNtlmDomain(); + } + + String authHost = realm.getNtlmHost(); + if (proxyServer != null && proxyServer.getHost() != null) { + host = proxyServer.getHost(); + } + + switch (realm.getAuthScheme()) { + case BASIC: + headers.put(HttpHeaders.Names.AUTHORIZATION, AuthenticatorUtils.computeBasicAuthentication(realm)); + break; + case DIGEST: + if (isNonEmpty(realm.getNonce())) { + try { + headers.put(HttpHeaders.Names.AUTHORIZATION, AuthenticatorUtils.computeDigestAuthentication(realm)); + } catch (NoSuchAlgorithmException e) { + throw new SecurityException(e); + } + } + break; + case NTLM: + try { + String msg = NTLMEngine.INSTANCE.generateType1Msg("NTLM " + domain, authHost); + headers.put(HttpHeaders.Names.AUTHORIZATION, "NTLM " + msg); + } catch (NTLMEngineException e) { + IOException ie = new IOException(); + ie.initCause(e); + throw ie; + } + break; + case KERBEROS: + case SPNEGO: + String challengeHeader = null; + String server = proxyServer == null ? host : proxyServer.getHost(); + try { + challengeHeader = SpnegoEngine.instance().generateToken(server); + } catch (Throwable e) { + IOException ie = new IOException(); + ie.initCause(e); + throw ie; + } + headers.put(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); + break; + case NONE: + break; + default: + throw new IllegalStateException("Invalid Authentication " + realm); + } + } + + if (!webSocket && !request.getHeaders().containsKey(HttpHeaders.Names.CONNECTION)) { + headers.put(HttpHeaders.Names.CONNECTION, AsyncHttpProviderUtils.keepAliveHeaderValue(config)); + } + + if (proxyServer != null) { + if (!request.getHeaders().containsKey("Proxy-Connection")) { + headers.put("Proxy-Connection", AsyncHttpProviderUtils.keepAliveHeaderValue(config)); + } + + if (proxyServer.getPrincipal() != null) { + if (isNonEmpty(proxyServer.getNtlmDomain())) { + + List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); + if (!isNTLM(auth)) { + try { + String msg = NTLMEngine.INSTANCE.generateType1Msg(proxyServer.getNtlmDomain(), proxyServer.getHost()); + headers.put(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + msg); + } catch (NTLMEngineException e) { + IOException ie = new IOException(); + ie.initCause(e); + throw ie; + } + } + } else { + headers.put(HttpHeaders.Names.PROXY_AUTHORIZATION, AuthenticatorUtils.computeBasicAuthentication(proxyServer)); + } + } + } + + // Add default accept headers + if (!request.getHeaders().containsKey(HttpHeaders.Names.ACCEPT)) { + headers.put(HttpHeaders.Names.ACCEPT, "*/*"); + } + + String userAgentHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT); + if (userAgentHeader != null) { + headers.put(HttpHeaders.Names.USER_AGENT, userAgentHeader); + } else if (config.getUserAgent() != null) { + headers.put(HttpHeaders.Names.USER_AGENT, config.getUserAgent()); + } else { + headers.put(HttpHeaders.Names.USER_AGENT, AsyncHttpProviderUtils.constructUserAgent(NettyAsyncHttpProvider.class, config)); + } + + boolean hasDeferredContent = false; + if (!m.equals(HttpMethod.CONNECT)) { + if (isNonEmpty(request.getCookies())) { + headers.put(HttpHeaders.Names.COOKIE, CookieEncoder.encodeClientSide(request.getCookies(), config.isRfc6265CookieEncoding())); + } + + if (!m.equals(HttpMethod.HEAD) && !m.equals(HttpMethod.OPTIONS) && !m.equals(HttpMethod.TRACE)) { + + String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : request.getBodyEncoding(); + + if (request.getByteData() != null) { + headers.put(HttpHeaders.Names.CONTENT_LENGTH, request.getByteData().length); + content = Unpooled.wrappedBuffer(request.getByteData()); + + } else if (request.getStringData() != null) { + byte[] bytes = request.getStringData().getBytes(bodyCharset); + headers.put(HttpHeaders.Names.CONTENT_LENGTH, bytes.length); + content = Unpooled.wrappedBuffer(bytes); + + } else if (request.getStreamData() != null) { + hasDeferredContent = true; + headers.put(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); + + } else if (isNonEmpty(request.getParams())) { + StringBuilder sb = new StringBuilder(); + for (final Entry> paramEntry : request.getParams()) { + final String key = paramEntry.getKey(); + for (final String value : paramEntry.getValue()) { + UTF8UrlEncoder.appendEncoded(sb, key); + sb.append("="); + UTF8UrlEncoder.appendEncoded(sb, value); + sb.append("&"); + } + } + sb.setLength(sb.length() - 1); + byte[] bytes = sb.toString().getBytes(bodyCharset); + headers.put(HttpHeaders.Names.CONTENT_LENGTH, bytes.length); + content = Unpooled.wrappedBuffer(bytes); + + if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) { + headers.put(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); + } + + } else if (request.getParts() != null) { + MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); + + headers.put(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); + headers.put(HttpHeaders.Names.CONTENT_LENGTH, mre.getContentLength()); + + hasDeferredContent = true; + + } else if (request.getEntityWriter() != null) { + int length = getPredefinedContentLength(request, headers); + + if (length == -1) { + length = Constants.MAX_BUFFERED_BYTES; + } + + ByteBuf b = Unpooled.buffer(length); + // FIXME doesn't do what EntityWriter javadoc says + request.getEntityWriter().writeEntity(new ByteBufOutputStream(b)); + // FIXME seems wrong when length was original -1, not sure the ByteBug increase, and feels like should be streaming + headers.put(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); + content = b; + } else if (request.getFile() != null) { + File file = request.getFile(); + if (!file.isFile()) { + throw new IOException(String.format("File %s is not a file or doesn't exist", file.getAbsolutePath())); + } + headers.put(HttpHeaders.Names.CONTENT_LENGTH, file.length()); + hasDeferredContent = true; + + } else if (request.getBodyGenerator() != null) { + hasDeferredContent = true; + } + } + } + + HttpRequest nettyRequest; + if (hasDeferredContent) { + nettyRequest = new DefaultHttpRequest(httpVersion, m, requestUri); + } else if (content != null) { + nettyRequest = new DefaultFullHttpRequest(httpVersion, m, requestUri, content); + } else { + nettyRequest = new DefaultFullHttpRequest(httpVersion, m, requestUri); + } + for (Entry header : headers.entrySet()) { + nettyRequest.headers().set(header.getKey(), header.getValue()); + } + return nettyRequest; + } +} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponse.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java similarity index 71% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponse.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java index 9e9ea53d29..acf9a994c8 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponse.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java @@ -13,27 +13,24 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty_4; - -import org.asynchttpclient.Cookie; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.providers.ResponseBase; -import org.asynchttpclient.util.AsyncHttpProviderUtils; +package org.asynchttpclient.providers.netty4; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; -import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.Unpooled; +import org.asynchttpclient.Cookie; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; +import org.asynchttpclient.providers.ResponseBase; +import org.asynchttpclient.util.AsyncHttpProviderUtils; /** * Wrapper around the {@link org.asynchttpclient.Response} API. @@ -65,8 +62,7 @@ protected List buildCookies() { // TODO: ask for parsed header List v = header.getValue(); for (String value : v) { - Cookie cookie = AsyncHttpProviderUtils.parseCookie(value); - cookies.add(cookie); + cookies.addAll(CookieDecoder.decode(value)); } } } @@ -80,7 +76,16 @@ public byte[] getResponseBodyAsBytes() throws IOException { /* @Override */ public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { - return getResponseBodyAsByteBuf().nioBuffer(); + + int length = 0; + for (HttpResponseBodyPart part: bodyParts) + length += part.length(); + + ByteBuffer target = ByteBuffer.wrap(new byte[length]); + for (HttpResponseBodyPart part: bodyParts) + target.put(part.getBodyPartBytes()); + + return target; } /* @Override */ @@ -90,31 +95,11 @@ public String getResponseBody() throws IOException { /* @Override */ public String getResponseBody(String charset) throws IOException { - return getResponseBodyAsByteBuf().toString(Charset.forName(calculateCharset(charset))); + return new String(getResponseBodyAsBytes(), calculateCharset(charset)); } /* @Override */ public InputStream getResponseBodyAsStream() throws IOException { - return new ByteBufInputStream(getResponseBodyAsByteBuf()); - } - - public ByteBuf getResponseBodyAsByteBuf() throws IOException { - ByteBuf b = null; - switch (bodyParts.size()) { - case 0: - b = Unpooled.EMPTY_BUFFER; - break; - case 1: - b = ResponseBodyPart.class.cast(bodyParts.get(0)).getChannelBuffer(); - break; - default: - ByteBuf[] channelBuffers = new ByteBuf[bodyParts.size()]; - for (int i = 0; i < bodyParts.size(); i++) { - channelBuffers[i] = ResponseBodyPart.class.cast(bodyParts.get(i)).getChannelBuffer(); - } - b = Unpooled.wrappedBuffer(channelBuffers); - } - - return b; + return new ByteArrayInputStream(getResponseBodyAsBytes()); } } diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponseFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java old mode 100644 new mode 100755 similarity index 62% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponseFuture.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java index 6f5b2861cf..7eab45f3bb --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyResponseFuture.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java @@ -13,23 +13,14 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Request; -import org.asynchttpclient.listenable.AbstractListenableFuture; +import static org.asynchttpclient.util.DateUtil.millisTime; import io.netty.channel.Channel; -import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.net.MalformedURLException; import java.net.URI; -import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; @@ -41,9 +32,18 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ConnectionPoolKeyStrategy; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Request; +import org.asynchttpclient.listenable.AbstractListenableFuture; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * A {@link Future} that can be used to track when an asynchronous HTTP request has been fully processed. - * + * * @param */ public final class NettyResponseFuture extends AbstractListenableFuture { @@ -51,33 +51,29 @@ public final class NettyResponseFuture extends AbstractListenableFuture { private final static Logger logger = LoggerFactory.getLogger(NettyResponseFuture.class); public final static String MAX_RETRY = "org.asynchttpclient.providers.netty.maxRetry"; - enum STATE { - NEW, - POOLED, - RECONNECTED, - CLOSED, + public enum STATE { + NEW, POOLED, RECONNECTED, CLOSED, } - + private final CountDownLatch latch = new CountDownLatch(1); private final AtomicBoolean isDone = new AtomicBoolean(false); private final AtomicBoolean isCancelled = new AtomicBoolean(false); private AsyncHandler asyncHandler; - private final int responseTimeoutInMs; - private final int idleConnectionTimeoutInMs; + private final int requestTimeoutInMs; + private final AsyncHttpClientConfig config; private Request request; - private FullHttpRequest nettyRequest; + private HttpRequest nettyRequest; private final AtomicReference content = new AtomicReference(); private URI uri; private boolean keepAlive = true; private HttpResponse httpResponse; private final AtomicReference exEx = new AtomicReference(); private final AtomicInteger redirectCount = new AtomicInteger(); - private volatile Future reaperFuture; + private volatile ReaperFuture reaperFuture; private final AtomicBoolean inAuth = new AtomicBoolean(false); private final AtomicBoolean statusReceived = new AtomicBoolean(false); - private final AtomicLong touch = new AtomicLong(System.currentTimeMillis()); - private final long start = System.currentTimeMillis(); - private final NettyAsyncHttpProvider asyncHttpProvider; + private final AtomicLong touch = new AtomicLong(millisTime()); + private final long start = millisTime(); private final AtomicReference state = new AtomicReference(STATE.NEW); private final AtomicBoolean contentProcessed = new AtomicBoolean(false); private Channel channel; @@ -90,83 +86,75 @@ enum STATE { private boolean allowConnect = false; private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy; private final ProxyServer proxyServer; - - public NettyResponseFuture(URI uri, - Request request, - AsyncHandler asyncHandler, - FullHttpRequest nettyRequest, - int responseTimeoutInMs, - int idleConnectionTimeoutInMs, - NettyAsyncHttpProvider asyncHttpProvider, - ConnectionPoolKeyStrategy connectionPoolKeyStrategy, - ProxyServer proxyServer) { + private final AtomicBoolean ignoreNextContents = new AtomicBoolean(false); + private final AtomicBoolean streamWasAlreadyConsumed = new AtomicBoolean(false); + + public NettyResponseFuture(URI uri,// + Request request,// + AsyncHandler asyncHandler,// + HttpRequest nettyRequest,// + int requestTimeoutInMs,// + AsyncHttpClientConfig config,// + ConnectionPoolKeyStrategy connectionPoolKeyStrategy,// + ProxyServer proxyServer) { this.asyncHandler = asyncHandler; - this.responseTimeoutInMs = responseTimeoutInMs; - this.idleConnectionTimeoutInMs = idleConnectionTimeoutInMs; + this.requestTimeoutInMs = requestTimeoutInMs; this.request = request; this.nettyRequest = nettyRequest; this.uri = uri; - this.asyncHttpProvider = asyncHttpProvider; + this.config = config; this.connectionPoolKeyStrategy = connectionPoolKeyStrategy; this.proxyServer = proxyServer; if (System.getProperty(MAX_RETRY) != null) { maxRetry = Integer.valueOf(System.getProperty(MAX_RETRY)); } else { - maxRetry = asyncHttpProvider.getConfig().getMaxRequestRetry(); + maxRetry = config.getMaxRequestRetry(); } writeHeaders = true; writeBody = true; } - protected URI getURI() throws MalformedURLException { + public URI getURI() { return uri; } - protected void setURI(URI uri) { + public void setURI(URI uri) { this.uri = uri; } - public ConnectionPoolKeyStrategy getConnectionPoolKeyStrategy() { - return connectionPoolKeyStrategy; - } + public ConnectionPoolKeyStrategy getConnectionPoolKeyStrategy() { + return connectionPoolKeyStrategy; + } - public ProxyServer getProxyServer() { + public ProxyServer getProxyServer() { return proxyServer; } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public boolean isDone() { return isDone.get(); } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public boolean isCancelled() { return isCancelled.get(); } - void setAsyncHandler(AsyncHandler asyncHandler) { + public void setAsyncHandler(AsyncHandler asyncHandler) { this.asyncHandler = asyncHandler; } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public boolean cancel(boolean force) { cancelReaper(); - if (isCancelled.get()) return false; + if (isCancelled.get()) + return false; try { - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).set(new NettyAsyncHttpProvider.DiscardEvent()); + Channels.setDefaultAttribute(channel, DiscardEvent.INSTANCE); channel.close(); } catch (Throwable t) { // Ignore @@ -180,44 +168,45 @@ public boolean cancel(boolean force) { } latch.countDown(); isCancelled.set(true); - super.done(); + runListeners(); return true; } /** * Is the Future still valid - * + * * @return true if response has expired and should be terminated. */ public boolean hasExpired() { - long now = System.currentTimeMillis(); - return idleConnectionTimeoutInMs != -1 && ((now - touch.get()) >= idleConnectionTimeoutInMs) - || responseTimeoutInMs != -1 && ((now - start) >= responseTimeoutInMs); + long now = millisTime(); + return hasConnectionIdleTimedOut(now) || hasRequestTimedOut(now); } - /** - * {@inheritDoc} - */ - /* @Override */ + public boolean hasConnectionIdleTimedOut(long now) { + return config.getIdleConnectionTimeoutInMs() != -1 && (now - touch.get()) >= config.getIdleConnectionTimeoutInMs(); + } + + public boolean hasRequestTimedOut(long now) { + return requestTimeoutInMs != -1 && (now - start) >= requestTimeoutInMs; + } + + @Override public V get() throws InterruptedException, ExecutionException { try { - return get(responseTimeoutInMs, TimeUnit.MILLISECONDS); + return get(requestTimeoutInMs, TimeUnit.MILLISECONDS); } catch (TimeoutException e) { cancelReaper(); throw new ExecutionException(e); } } - void cancelReaper() { + public void cancelReaper() { if (reaperFuture != null) { - reaperFuture.cancel(true); + reaperFuture.cancel(false); } } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException { if (!isDone() && !isCancelled()) { boolean expired = false; @@ -230,7 +219,7 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, if (expired) { isCancelled.set(true); try { - channel.pipeline().context(NettyAsyncHttpProvider.class).attr(NettyAsyncHttpProvider.DEFAULT_ATTRIBUTE).set(new NettyAsyncHttpProvider.DiscardEvent()); + Channels.setDefaultAttribute(channel, DiscardEvent.INSTANCE); channel.close(); } catch (Throwable t) { // Ignore @@ -257,7 +246,7 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, return getContent(); } - V getContent() throws ExecutionException { + public V getContent() throws ExecutionException { ExecutionException e = exEx.getAndSet(null); if (e != null) { throw e; @@ -268,7 +257,7 @@ V getContent() throws ExecutionException { currentRetry.set(maxRetry); if (exEx.get() == null && !contentProcessed.getAndSet(true)) { try { - update = asyncHandler.onCompleted(); + update = (V) asyncHandler.onCompleted(); } catch (Throwable ex) { if (!throwableCalled.getAndSet(true)) { try { @@ -286,9 +275,7 @@ V getContent() throws ExecutionException { return update; } - public final void done(Callable callable) { - - Throwable exception = null; + public final void done() { try { cancelReaper(); @@ -298,32 +285,24 @@ public final void done(Callable callable) { } getContent(); isDone.set(true); - if (callable != null) { - try { - callable.call(); - } catch (Exception ex) { - exception = ex; - } - } } catch (ExecutionException t) { return; } catch (RuntimeException t) { - exception = t.getCause() != null ? t.getCause() : t; + Throwable exception = t.getCause() != null ? t.getCause() : t; + exEx.compareAndSet(null, new ExecutionException(exception)); } finally { latch.countDown(); } - if (exception != null) - exEx.compareAndSet(null, new ExecutionException(exception)); - - super.done(); + runListeners(); } public final void abort(final Throwable t) { cancelReaper(); - if (isDone.get() || isCancelled.get()) return; + if (isDone.get() || isCancelled.get()) + return; exEx.compareAndSet(null, new ExecutionException(t)); if (!throwableCalled.getAndSet(true)) { @@ -336,67 +315,67 @@ public final void abort(final Throwable t) { } } latch.countDown(); - super.done(); + runListeners(); } public void content(V v) { content.set(v); } - protected final Request getRequest() { + public final Request getRequest() { return request; } - public final FullHttpRequest getNettyRequest() { + public final HttpRequest getNettyRequest() { return nettyRequest; } - protected final void setNettyRequest(HttpRequest nettyRequest) { + public final void setNettyRequest(HttpRequest nettyRequest) { this.nettyRequest = nettyRequest; } - protected final AsyncHandler getAsyncHandler() { + public final AsyncHandler getAsyncHandler() { return asyncHandler; } - protected final boolean isKeepAlive() { + public final boolean isKeepAlive() { return keepAlive; } - protected final void setKeepAlive(final boolean keepAlive) { + public final void setKeepAlive(final boolean keepAlive) { this.keepAlive = keepAlive; } - protected final HttpResponse getHttpResponse() { + public final HttpResponse getHttpResponse() { return httpResponse; } - protected final void setHttpResponse(final HttpResponse httpResponse) { + public final void setHttpResponse(final HttpResponse httpResponse) { this.httpResponse = httpResponse; } - protected int incrementAndGetCurrentRedirectCount() { + public int incrementAndGetCurrentRedirectCount() { return redirectCount.incrementAndGet(); } - protected void setReaperFuture(Future reaperFuture) { + public void setReaperFuture(ReaperFuture reaperFuture) { cancelReaper(); this.reaperFuture = reaperFuture; } - protected boolean isInAuth() { + public boolean isInAuth() { return inAuth.get(); } - protected boolean getAndSetAuth(boolean inDigestAuth) { + public boolean getAndSetAuth(boolean inDigestAuth) { return inAuth.getAndSet(inDigestAuth); } - protected STATE getState() { + public STATE getState() { return state.get(); } - protected void setState(STATE state) { + public void setState(STATE state) { this.state.set(state); } @@ -404,39 +383,38 @@ public boolean getAndSetStatusReceived(boolean sr) { return statusReceived.getAndSet(sr); } - /** - * {@inheritDoc} - */ - /* @Override */ + public void setIgnoreNextContents(boolean b) { + ignoreNextContents.set(b); + } + + public boolean isIgnoreNextContents() { + return ignoreNextContents.get(); + } + + public boolean getAndSetStreamWasAlreadyConsumed() { + return streamWasAlreadyConsumed.getAndSet(true); + } + + @Override public void touch() { - touch.set(System.currentTimeMillis()); + touch.set(millisTime()); } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public boolean getAndSetWriteHeaders(boolean writeHeaders) { boolean b = this.writeHeaders; this.writeHeaders = writeHeaders; return b; } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public boolean getAndSetWriteBody(boolean writeBody) { boolean b = this.writeBody; this.writeBody = writeBody; return b; } - protected NettyAsyncHttpProvider provider() { - return asyncHttpProvider; - } - - protected void attachChannel(Channel channel) { + public void attachChannel(Channel channel) { this.channel = channel; } @@ -452,20 +430,20 @@ public void setConnectAllowed(boolean allowConnect) { this.allowConnect = allowConnect; } - protected void attachChannel(Channel channel, boolean reuseChannel) { + public void attachChannel(Channel channel, boolean reuseChannel) { this.channel = channel; this.reuseChannel = reuseChannel; } - protected Channel channel() { + public Channel channel() { return channel; } - protected boolean reuseChannel() { + public boolean reuseChannel() { return reuseChannel; } - protected boolean canRetry() { + public boolean canRetry() { if (currentRetry.incrementAndGet() > maxRetry) { return false; } @@ -477,39 +455,41 @@ public void setRequest(Request request) { } /** - * Return true if the {@link Future} cannot be recovered. There is some scenario where a connection can be - * closed by an unexpected IOException, and in some situation we can recover from that exception. - * + * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can recover from that exception. + * * @return true if that {@link Future} cannot be recovered. */ - public boolean cannotBeReplay() { - return isDone() - || !canRetry() - || isCancelled() - || (channel() != null && channel().isOpen() && uri.getScheme().compareToIgnoreCase("https") != 0) - || isInAuth(); + public boolean canBeReplayed() { + return !isDone() && canRetry() && !isCancelled() && !(channel != null && channel.isOpen() && !uri.getScheme().equalsIgnoreCase("https")) && !isInAuth(); + } + + public long getStart() { + return start; + } + + public long getRequestTimeoutInMs() { + return requestTimeoutInMs; } @Override public String toString() { - return "NettyResponseFuture{" + - "currentRetry=" + currentRetry + - ",\n\tisDone=" + isDone + - ",\n\tisCancelled=" + isCancelled + - ",\n\tasyncHandler=" + asyncHandler + - ",\n\tresponseTimeoutInMs=" + responseTimeoutInMs + - ",\n\tnettyRequest=" + nettyRequest + - ",\n\tcontent=" + content + - ",\n\turi=" + uri + - ",\n\tkeepAlive=" + keepAlive + - ",\n\thttpResponse=" + httpResponse + - ",\n\texEx=" + exEx + - ",\n\tredirectCount=" + redirectCount + - ",\n\treaperFuture=" + reaperFuture + - ",\n\tinAuth=" + inAuth + - ",\n\tstatusReceived=" + statusReceived + - ",\n\ttouch=" + touch + + return "NettyResponseFuture{" + // + "currentRetry=" + currentRetry + // + ",\n\tisDone=" + isDone + // + ",\n\tisCancelled=" + isCancelled + // + ",\n\tasyncHandler=" + asyncHandler + // + ",\n\trequestTimeoutInMs=" + requestTimeoutInMs + // + ",\n\tnettyRequest=" + nettyRequest + // + ",\n\tcontent=" + content + // + ",\n\turi=" + uri + // + ",\n\tkeepAlive=" + keepAlive + // + ",\n\thttpResponse=" + httpResponse + // + ",\n\texEx=" + exEx + // + ",\n\tredirectCount=" + redirectCount + // + ",\n\treaperFuture=" + reaperFuture + // + ",\n\tinAuth=" + inAuth + // + ",\n\tstatusReceived=" + statusReceived + // + ",\n\ttouch=" + touch + // '}'; } - } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java new file mode 100644 index 0000000000..2d3d34f74b --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java @@ -0,0 +1,98 @@ +package org.asynchttpclient.providers.netty4; + +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; + +import java.net.URI; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Request; +import org.asynchttpclient.util.AsyncHttpProviderUtils; + +public class NettyResponseFutures { + + public static NettyResponseFuture newNettyResponseFuture(URI uri, Request request, AsyncHandler asyncHandler, HttpRequest nettyRequest, AsyncHttpClientConfig config, ProxyServer proxyServer) { + + int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); + NettyResponseFuture f = new NettyResponseFuture(uri,// + request,// + asyncHandler,// + nettyRequest,// + requestTimeout,// + config,// + request.getConnectionPoolKeyStrategy(),// + proxyServer); + + String expectHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT); + if (expectHeader != null && expectHeader.equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) { + f.getAndSetWriteBody(false); + } + return f; + } + + public static boolean abortOnConnectCloseException(Throwable cause) { + try { + for (StackTraceElement element : cause.getStackTrace()) { + if (element.getClassName().equals("sun.nio.ch.SocketChannelImpl") && element.getMethodName().equals("checkConnect")) { + return true; + } + } + + if (cause.getCause() != null) { + return abortOnConnectCloseException(cause.getCause()); + } + + } catch (Throwable t) { + } + return false; + } + + public static boolean abortOnDisconnectException(Throwable cause) { + try { + for (StackTraceElement element : cause.getStackTrace()) { + if (element.getClassName().equals("io.netty.handler.ssl.SslHandler") && element.getMethodName().equals("channelDisconnected")) { + return true; + } + } + + if (cause.getCause() != null) { + return abortOnConnectCloseException(cause.getCause()); + } + + } catch (Throwable t) { + } + return false; + } + + public static boolean abortOnReadCloseException(Throwable cause) { + + for (StackTraceElement element : cause.getStackTrace()) { + if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") && element.getMethodName().equals("read")) { + return true; + } + } + + if (cause.getCause() != null) { + return abortOnReadCloseException(cause.getCause()); + } + + return false; + } + + public static boolean abortOnWriteCloseException(Throwable cause) { + + for (StackTraceElement element : cause.getStackTrace()) { + if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") && element.getMethodName().equals("write")) { + return true; + } + } + + if (cause.getCause() != null) { + return abortOnReadCloseException(cause.getCause()); + } + + return false; + } +} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java new file mode 100644 index 0000000000..fdeb04587c --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java @@ -0,0 +1,41 @@ +package org.asynchttpclient.providers.netty4; + +import io.netty.buffer.ByteBuf; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.listener.TransferCompletionHandler; + +class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter { + + private final ByteBuf content; + private final FileInputStream file; + private int byteRead = 0; + + public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf content, File file) throws IOException { + super(headers); + this.content = content; + if (file != null) { + this.file = new FileInputStream(file); + } else { + this.file = null; + } + } + + @Override + public void getBytes(byte[] bytes) { + if (content.writableBytes() != 0) { + content.getBytes(byteRead, bytes); + byteRead += bytes.length; + } else if (file != null) { + try { + byteRead += file.read(bytes); + } catch (IOException e) { + NettyAsyncHttpProvider.LOGGER.error(e.getMessage(), e); + } + } + } +} \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyWebSocket.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java similarity index 88% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyWebSocket.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java index b885930569..c935ee0e8d 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/NettyWebSocket.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.websocket.WebSocket; import org.asynchttpclient.websocket.WebSocketByteListener; @@ -19,15 +19,15 @@ import org.asynchttpclient.websocket.WebSocketTextListener; import io.netty.channel.Channel; import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.concurrent.ConcurrentLinkedQueue; - import java.io.ByteArrayOutputStream; +import java.util.concurrent.ConcurrentLinkedQueue; import static io.netty.buffer.Unpooled.wrappedBuffer; @@ -47,7 +47,7 @@ public NettyWebSocket(Channel channel) { // @Override public WebSocket sendMessage(byte[] message) { - channel.write(new BinaryWebSocketFrame(wrappedBuffer(message))); + channel.writeAndFlush(new BinaryWebSocketFrame(wrappedBuffer(message))); return this; } @@ -63,7 +63,7 @@ public WebSocket stream(byte[] fragment, int offset, int len, boolean last) { // @Override public WebSocket sendTextMessage(String message) { - channel.write(new TextWebSocketFrame(message)); + channel.writeAndFlush(new TextWebSocketFrame(message)); return this; } @@ -74,13 +74,13 @@ public WebSocket streamText(String fragment, boolean last) { // @Override public WebSocket sendPing(byte[] payload) { - channel.write(new PingWebSocketFrame(wrappedBuffer(payload))); + channel.writeAndFlush(new PingWebSocketFrame(wrappedBuffer(payload))); return this; } // @Override public WebSocket sendPong(byte[] payload) { - channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); + channel.writeAndFlush(new PongWebSocketFrame(wrappedBuffer(payload))); return this; } @@ -116,12 +116,23 @@ public boolean isOpen() { public void close() { onClose(); listeners.clear(); - channel.close(); + try { + channel.write(new CloseWebSocketFrame()); + channel.closeFuture().awaitUninterruptibly(); + } finally { + channel.close(); + } + } + + // @Override + public void close(int statusCode, String reason) { + onClose(statusCode, reason); + listeners.clear(); } protected void onBinaryFragment(byte[] message, boolean last) { for (WebSocketListener l : listeners) { - if (WebSocketByteListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketByteListener) { try { WebSocketByteListener.class.cast(l).onFragment(message,last); @@ -153,7 +164,7 @@ protected void onBinaryFragment(byte[] message, boolean last) { protected void onTextFragment(String message, boolean last) { for (WebSocketListener l : listeners) { - if (WebSocketTextListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketTextListener) { try { WebSocketTextListener.class.cast(l).onFragment(message,last); @@ -200,7 +211,7 @@ protected void onClose() { protected void onClose(int code, String reason) { for (WebSocketListener l : listeners) { try { - if (WebSocketCloseCodeReasonListener.class.isAssignableFrom(l.getClass())) { + if (l instanceof WebSocketCloseCodeReasonListener) { WebSocketCloseCodeReasonListener.class.cast(l).onClose(this, code, reason); } l.onClose(this); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java new file mode 100644 index 0000000000..ee7f9f98fb --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java @@ -0,0 +1,68 @@ +package org.asynchttpclient.providers.netty4; + +import io.netty.channel.FileRegion; +import io.netty.util.AbstractReferenceCounted; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.channels.FileChannel; +import java.nio.channels.WritableByteChannel; + +public class OptimizedFileRegion extends AbstractReferenceCounted implements FileRegion { + + private final FileChannel file; + private final RandomAccessFile raf; + private final long position; + private final long count; + private long byteWritten; + + public OptimizedFileRegion(RandomAccessFile raf, long position, long count) { + this.raf = raf; + this.file = raf.getChannel(); + this.position = position; + this.count = count; + } + + public long position() { + return position; + } + + public long count() { + return count; + } + + public long transfered() { + return byteWritten; + } + + public long transferTo(WritableByteChannel target, long position) throws IOException { + long count = this.count - position; + if (count < 0 || position < 0) { + throw new IllegalArgumentException("position out of range: " + position + " (expected: 0 - " + (this.count - 1) + ")"); + } + if (count == 0) { + return 0L; + } + + long bw = file.transferTo(this.position + position, count, target); + byteWritten += bw; + if (byteWritten == raf.length()) { + deallocate(); + } + return bw; + } + + public void deallocate() { + try { + file.close(); + } catch (IOException e) { + NettyAsyncHttpProvider.LOGGER.warn("Failed to close a file.", e); + } + + try { + raf.close(); + } catch (IOException e) { + NettyAsyncHttpProvider.LOGGER.warn("Failed to close a file.", e); + } + } +} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java new file mode 100644 index 0000000000..5670a3f6be --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java @@ -0,0 +1,86 @@ +package org.asynchttpclient.providers.netty4; + +import io.netty.channel.ChannelProgressiveFuture; +import io.netty.channel.ChannelProgressiveFutureListener; + +import java.nio.channels.ClosedChannelException; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ProgressAsyncHandler; +import org.asynchttpclient.Realm; + +public class ProgressListener implements ChannelProgressiveFutureListener { + + private final AsyncHttpClientConfig config; + private final boolean notifyHeaders; + private final AsyncHandler asyncHandler; + private final NettyResponseFuture future; + + public ProgressListener(AsyncHttpClientConfig config, boolean notifyHeaders, AsyncHandler asyncHandler, NettyResponseFuture future) { + this.config = config; + this.notifyHeaders = notifyHeaders; + this.asyncHandler = asyncHandler; + this.future = future; + } + + @Override + public void operationComplete(ChannelProgressiveFuture cf) { + // The write operation failed. If the channel was cached, it means it got asynchronously closed. + // Let's retry a second time. + Throwable cause = cf.cause(); + if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) { + + if (cause instanceof IllegalStateException) { + NettyAsyncHttpProvider.LOGGER.debug(cause.getMessage(), cause); + try { + cf.channel().close(); + } catch (RuntimeException ex) { + NettyAsyncHttpProvider.LOGGER.debug(ex.getMessage(), ex); + } + return; + } + + if (cause instanceof ClosedChannelException || NettyResponseFutures.abortOnReadCloseException(cause) || NettyResponseFutures.abortOnWriteCloseException(cause)) { + + if (NettyAsyncHttpProvider.LOGGER.isDebugEnabled()) { + NettyAsyncHttpProvider.LOGGER.debug(cf.cause() == null ? "" : cf.cause().getMessage(), cf.cause()); + } + + try { + cf.channel().close(); + } catch (RuntimeException ex) { + NettyAsyncHttpProvider.LOGGER.debug(ex.getMessage(), ex); + } + return; + } else { + future.abort(cause); + } + return; + } + future.touch(); + + /** + * We need to make sure we aren't in the middle of an authorization process before publishing events as we will re-publish again the same event after the authorization, causing unpredictable behavior. + */ + Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : config.getRealm(); + boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth(); + + if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) { + // FIXME WTF + if (notifyHeaders) { + ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); + } else { + ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteCompleted(); + } + } + } + + @Override + public void operationProgressed(ChannelProgressiveFuture f, long progress, long total) { + future.touch(); + if (asyncHandler instanceof ProgressAsyncHandler) { + ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(total - progress, progress, total); + } + } +} \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/Protocol.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java similarity index 82% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/Protocol.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java index c83043148f..19e62a52d9 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/Protocol.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java @@ -10,13 +10,13 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; import io.netty.channel.ChannelHandlerContext; -public interface Protocol { +public interface Protocol{ - void handle(ChannelHandlerContext ctx, T message) throws Exception; + void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception; void onError(ChannelHandlerContext ctx, Throwable error); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java new file mode 100644 index 0000000000..fa4f5adecb --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java @@ -0,0 +1,104 @@ +package org.asynchttpclient.providers.netty4; + +import static org.asynchttpclient.util.DateUtil.millisTime; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.asynchttpclient.AsyncHttpClientConfig; + +/** + * Because some implementation of the ThreadSchedulingService do not clean up cancel task until they try to run them, we wrap the task with the future so the when the NettyResponseFuture cancel the reaper future this wrapper will release the references to the channel and the + * nettyResponseFuture immediately. Otherwise, the memory referenced this way will only be released after the request timeout period which can be arbitrary long. + */ +public final class ReaperFuture implements Runnable { + + private final AtomicBoolean isClose; + private final Channels channels; + private Future scheduledFuture; + private NettyResponseFuture nettyResponseFuture; + private AsyncHttpClientConfig config; + + public ReaperFuture(NettyResponseFuture nettyResponseFuture, AsyncHttpClientConfig config, AtomicBoolean isClose, Channels channels) { + this.nettyResponseFuture = nettyResponseFuture; + this.channels = channels; + this.config = config; + this.isClose = isClose; + } + + public void setScheduledFuture(Future scheduledFuture) { + this.scheduledFuture = scheduledFuture; + } + + /** + * @Override + */ + public boolean cancel(boolean mayInterruptIfRunning) { + nettyResponseFuture = null; + return scheduledFuture.cancel(mayInterruptIfRunning); + } + + /** + * @Override + */ + public Object get() throws InterruptedException, ExecutionException { + return scheduledFuture.get(); + } + + /** + * @Override + */ + public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + return scheduledFuture.get(timeout, unit); + } + + /** + * @Override + */ + public boolean isCancelled() { + return scheduledFuture.isCancelled(); + } + + /** + * @Override + */ + public boolean isDone() { + return scheduledFuture.isDone(); + } + + private void expire(String message) { + NettyAsyncHttpProvider.LOGGER.debug("{} for {}", message, nettyResponseFuture); + channels.abort(nettyResponseFuture, new TimeoutException(message)); + nettyResponseFuture = null; + } + + /** + * @Override + */ + public synchronized void run() { + if (isClose.get()) { + cancel(true); + return; + } + + boolean futureDone = nettyResponseFuture.isDone(); + boolean futureCanceled = nettyResponseFuture.isCancelled(); + + if (nettyResponseFuture != null && !futureDone && !futureCanceled) { + long now = millisTime(); + if (nettyResponseFuture.hasRequestTimedOut(now)) { + long age = now - nettyResponseFuture.getStart(); + expire("Request reached time out of " + nettyResponseFuture.getRequestTimeoutInMs() + " ms after " + age + " ms"); + } else if (nettyResponseFuture.hasConnectionIdleTimedOut(now)) { + long age = now - nettyResponseFuture.getStart(); + expire("Request reached idle time out of " + config.getIdleConnectionTimeoutInMs() + " ms after " + age + " ms"); + } + + } else if (nettyResponseFuture == null || futureDone || futureCanceled) { + cancel(true); + } + } +} \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseBodyPart.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java similarity index 53% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseBodyPart.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java index 43ced26dec..7f0f8ca7a4 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseBodyPart.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java @@ -13,13 +13,10 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import io.netty.buffer.ByteBuf; -import io.netty.handler.codec.http.FullHttpResponse; import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.LastHttpContent; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -27,79 +24,55 @@ import java.io.OutputStream; import java.net.URI; import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicReference; + +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.providers.netty4.util.ByteBufUtil; /** * A callback class used when an HTTP response body is received. */ public class ResponseBodyPart extends HttpResponseBodyPart { - private final HttpContent chunk; - private final FullHttpResponse response; - private final AtomicReference bytes = new AtomicReference(null); + private final byte[] bytes; private final boolean isLast; private boolean closeConnection = false; - /** - * Constructor used for non-chunked GET requests and HEAD requests. - */ - public ResponseBodyPart(URI uri, FullHttpResponse response, AsyncHttpProvider provider, boolean last) { - this(uri, response, provider, null, last); + // FIXME unused AsyncHttpProvider provider + public ResponseBodyPart(URI uri, HttpContent chunk) { + super(uri, null); + bytes = ByteBufUtil.byteBuf2bytes(chunk.content()); + isLast = chunk instanceof LastHttpContent; } - public ResponseBodyPart(URI uri, FullHttpResponse response, AsyncHttpProvider provider, HttpContent chunk, boolean last) { - super(uri, provider); - this.chunk = chunk; - this.response = response; - isLast = last; - } - /** * Return the response body's part bytes received. - * + * * @return the response body's part bytes received. */ @Override public byte[] getBodyPartBytes() { - byte[] bp = bytes.get(); - if (bp != null) { - return bp; - } - - ByteBuf b = getChannelBuffer(); - byte[] rb = b.nioBuffer().array(); - bytes.set(rb); - return rb; + return bytes; } @Override public InputStream readBodyPartBytes() { - return new ByteArrayInputStream(getBodyPartBytes()); + return new ByteArrayInputStream(bytes); } @Override public int length() { - ByteBuf b = (chunk != null) ? chunk.data() : response.data(); - return b.readableBytes(); + return bytes.length; } - + @Override public int writeTo(OutputStream outputStream) throws IOException { - ByteBuf b = getChannelBuffer(); - int available = b.readableBytes(); - if (available > 0) { - b.getBytes(b.readerIndex(), outputStream, available); - } - return available; + outputStream.write(bytes); + return length(); } @Override public ByteBuffer getBodyByteBuffer() { - return ByteBuffer.wrap(getBodyPartBytes()); - } - - public ByteBuf getChannelBuffer() { - return chunk != null ? chunk.data() : response.data(); + return ByteBuffer.wrap(bytes); } /** @@ -125,8 +98,4 @@ public void markUnderlyingConnectionAsClosed() { public boolean closeUnderlyingConnection() { return closeConnection; } - - protected HttpContent chunk() { - return chunk; - } } diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseHeaders.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java similarity index 58% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseHeaders.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java index 3ee78ae74e..f3c02e262d 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseHeaders.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java @@ -13,52 +13,47 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseHeaders; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.HttpHeaders; import java.net.URI; +import java.util.Map; + +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.HttpResponseHeaders; /** * A class that represent the HTTP headers. */ public class ResponseHeaders extends HttpResponseHeaders { - private final LastHttpContent trailingHeaders; - private final HttpResponse response; + private final HttpHeaders responseHeaders; + private final HttpHeaders trailingHeaders; private final FluentCaseInsensitiveStringsMap headers; - public ResponseHeaders(URI uri, HttpResponse response, AsyncHttpProvider provider) { - super(uri, provider, false); - this.trailingHeaders = null; - this.response = response; - headers = computerHeaders(); + // FIXME unused AsyncHttpProvider provider + public ResponseHeaders(URI uri, HttpHeaders responseHeaders) { + this(uri, responseHeaders, null); } - public ResponseHeaders(URI uri, HttpResponse response, AsyncHttpProvider provider, LastHttpContent traillingHeaders) { - super(uri, provider, true); + // FIXME unused AsyncHttpProvider provider + public ResponseHeaders(URI uri,HttpHeaders responseHeaders, HttpHeaders traillingHeaders) { + super(uri, null, traillingHeaders != null); + this.responseHeaders = responseHeaders; this.trailingHeaders = traillingHeaders; - this.response = response; headers = computerHeaders(); } private FluentCaseInsensitiveStringsMap computerHeaders() { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - for (String s : response.headers().names()) { - for (String header : response.headers().getAll(s)) { - h.add(s, header); - } + for (Map.Entry header: responseHeaders) { + h.add(header.getKey(), header.getValue()); } if (trailingHeaders != null) { - for (final String s : trailingHeaders.trailingHeaders().names()) { - for (String header : response.headers().getAll(s)) { - h.add(s, header); - } + for (Map.Entry header: trailingHeaders) { + h.add(header.getKey(), header.getValue()); } } diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseStatus.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java similarity index 59% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseStatus.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java index 0f9ae49d2a..ff8f3cd77e 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/ResponseStatus.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java @@ -14,23 +14,49 @@ * under the License. * */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; +import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpProvider; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.Request; +import org.asynchttpclient.Response; + import io.netty.handler.codec.http.HttpResponse; +import java.io.IOException; import java.net.URI; +import java.util.List; /** * A class that represent the HTTP response' status line (code + text) */ public class ResponseStatus extends HttpResponseStatus { + + private static final AsyncHttpProvider fakeProvider = new AsyncHttpProvider() { + public ListenableFuture execute(Request request, AsyncHandler handler) throws IOException { + throw new UnsupportedOperationException("Mocked, should be refactored"); + } + + public void close() { + throw new UnsupportedOperationException("Mocked, should be refactored"); + } + + public Response prepareResponse(HttpResponseStatus status, + HttpResponseHeaders headers, + List bodyParts) { + return new NettyResponse(status, headers, bodyParts); + } + }; private final HttpResponse response; - public ResponseStatus(URI uri, HttpResponse response, AsyncHttpProvider provider) { - super(uri, provider); + // FIXME ResponseStatus should have an abstract prepareResponse(headers, bodyParts) method instead of being passed the provider! + public ResponseStatus(URI uri, HttpResponse response) { + super(uri, fakeProvider); this.response = response; } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java new file mode 100644 index 0000000000..90b67893ee --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java @@ -0,0 +1,19 @@ +package org.asynchttpclient.providers.netty4; + +public class ThreadLocalBoolean extends ThreadLocal { + + private final boolean defaultValue; + + public ThreadLocalBoolean() { + this(false); + } + + public ThreadLocalBoolean(boolean defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + protected Boolean initialValue() { + return defaultValue ? Boolean.TRUE : Boolean.FALSE; + } +} \ No newline at end of file diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/WebSocketUtil.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java similarity index 98% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/WebSocketUtil.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java index b4ffdeb543..5c92684365 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/WebSocketUtil.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty_4; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.util.Base64; diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoEngine.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java similarity index 96% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoEngine.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java index a712421ccc..eeeb83365f 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoEngine.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java @@ -35,7 +35,7 @@ * . */ -package org.asynchttpclient.providers.netty_4.spnego; +package org.asynchttpclient.providers.netty4.spnego; import org.asynchttpclient.util.Base64; import org.ietf.jgss.GSSContext; @@ -55,6 +55,7 @@ * @since 4.1 */ public class SpnegoEngine { + private static final String SPNEGO_OID = "1.3.6.1.5.5.2"; private static final String KERBEROS_OID = "1.2.840.113554.1.2.2"; @@ -69,6 +70,13 @@ public SpnegoEngine(final SpnegoTokenGenerator spnegoGenerator) { public SpnegoEngine() { this(null); } + + private static SpnegoEngine instance; + public static SpnegoEngine instance() { + if (instance == null) + instance = new SpnegoEngine(); + return instance; + } public String generateToken(String server) throws Throwable { GSSContext gssContext = null; diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoTokenGenerator.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java similarity index 97% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoTokenGenerator.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java index bc989540d1..be2d720842 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/spnego/SpnegoTokenGenerator.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java @@ -36,7 +36,7 @@ * */ -package org.asynchttpclient.providers.netty_4.spnego; +package org.asynchttpclient.providers.netty4.spnego; import java.io.IOException; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java new file mode 100644 index 0000000000..952d787828 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty4.util; + +import io.netty.buffer.ByteBuf; + +public class ByteBufUtil { + + public static byte[] byteBuf2bytes(ByteBuf b) { + int readable = b.readableBytes(); + int readerIndex = b.readerIndex(); + if (b.hasArray()) { + byte[] array = b.array(); + if (b.arrayOffset() == 0 && readerIndex == 0 && array.length == readable) { + return array; + } + } + byte[] array = new byte[readable]; + b.getBytes(readerIndex, array); + return array; + } +} diff --git a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/util/CleanupChannelGroup.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java similarity index 75% rename from providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/util/CleanupChannelGroup.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java index 74c2ec9525..2de4e4d7aa 100644 --- a/providers/netty-4/src/main/java/org/asynchttpclient/providers/netty_4/util/CleanupChannelGroup.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java @@ -26,21 +26,23 @@ * limitations under the License. */ -package org.asynchttpclient.providers.netty_4.util; +package org.asynchttpclient.providers.netty4.util; import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.group.ChannelGroup; +//import io.netty.channel.ChannelFuture; +//import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.ChannelGroupFuture; import io.netty.channel.group.DefaultChannelGroup; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.netty.util.concurrent.GlobalEventExecutor; -import java.util.ArrayList; -import java.util.Collection; +//import java.util.ArrayList; +//import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; + /** * Extension of {@link DefaultChannelGroup} that's used mainly as a cleanup container, where {@link #close()} is only * supposed to be called once. @@ -49,24 +51,21 @@ */ public class CleanupChannelGroup extends DefaultChannelGroup { - private final static Logger logger = LoggerFactory.getLogger(CleanupChannelGroup.class); +// private final static Logger logger = LoggerFactory.getLogger(CleanupChannelGroup.class); // internal vars -------------------------------------------------------------------------------------------------- - private final AtomicBoolean closed; - private final ReentrantReadWriteLock lock; + private final AtomicBoolean closed = new AtomicBoolean(false); + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); // constructors --------------------------------------------------------------------------------------------------- public CleanupChannelGroup() { - this.closed = new AtomicBoolean(false); - this.lock = new ReentrantReadWriteLock(); + super(GlobalEventExecutor.INSTANCE); } public CleanupChannelGroup(String name) { - super(name); - this.closed = new AtomicBoolean(false); - this.lock = new ReentrantReadWriteLock(); + super(name, GlobalEventExecutor.INSTANCE); } // DefaultChannelGroup -------------------------------------------------------------------------------------------- @@ -79,9 +78,11 @@ public ChannelGroupFuture close() { // First time close() is called. return super.close(); } else { - Collection futures = new ArrayList(); - logger.debug("CleanupChannelGroup Already closed"); - return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures); + // FIXME DefaultChannelGroupFuture is package protected +// Collection futures = new ArrayList(); +// logger.debug("CleanupChannelGroup already closed"); +// return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures, GlobalEventExecutor.INSTANCE); + throw new UnsupportedOperationException("CleanupChannelGroup already closed"); } } finally { this.lock.writeLock().unlock(); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java new file mode 100644 index 0000000000..cf6b49a3a6 --- /dev/null +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java @@ -0,0 +1,33 @@ +package org.asynchttpclient.providers.netty4.util; + +import static org.asynchttpclient.util.MiscUtil.isNonEmpty; + +import java.net.URI; +import java.util.List; + +public class HttpUtil { + + private HttpUtil() { + } + + public static final String HTTPS = "https"; + public static final String HTTP = "http"; + public static final String WEBSOCKET = "ws"; + public static final String WEBSOCKET_SSL = "wss"; + + public static boolean isNTLM(List auth) { + return isNonEmpty(auth) && auth.get(0).startsWith("NTLM"); + } + + public static boolean isWebSocket(URI uri) { + return WEBSOCKET.equalsIgnoreCase(uri.getScheme()) || WEBSOCKET_SSL.equalsIgnoreCase(uri.getScheme()); + } + + public static boolean isSecure(String scheme) { + return HTTPS.equalsIgnoreCase(scheme) || WEBSOCKET_SSL.equalsIgnoreCase(scheme); + } + + public static boolean isSecure(URI uri) { + return isSecure(uri.getScheme()); + } +} diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java similarity index 87% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java index 51739b1688..7e4fa7d82b 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java @@ -10,15 +10,12 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.providers.netty_4.NettyAsyncHttpProviderConfig; import static org.testng.Assert.assertEquals; -import java.util.concurrent.Executors; - +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; @@ -29,7 +26,6 @@ public class NettyAsyncHttpProviderTest extends AbstractBasicTest { @Test public void bossThreadPoolExecutor() throws Throwable { NettyAsyncHttpProviderConfig conf = new NettyAsyncHttpProviderConfig(); - conf.setBossExecutorService(Executors.newSingleThreadExecutor()); AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setAsyncHttpClientProviderConfig(conf).build(); AsyncHttpClient c = getAsyncHttpClient(cf); diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java similarity index 89% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java index 41aea3c951..113366e944 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java @@ -10,11 +10,10 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.providers.netty_4.NettyAsyncHttpProviderConfig; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; @@ -31,7 +30,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { @Override protected AsyncHttpProviderConfig getProviderConfig() { final NettyAsyncHttpProviderConfig config = new NettyAsyncHttpProviderConfig(); - config.addProperty("tcpNoDelay", true); + config.addProperty("TCP_NODELAY", true); return config; } } diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java similarity index 58% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java index 806c3a7ead..d4b2a959a1 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java @@ -11,40 +11,45 @@ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.providers.netty_4.NettyAsyncHttpProvider; import static org.testng.Assert.assertEquals; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.http.HttpMessage; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelHandler; -import org.jboss.netty.handler.codec.http.HttpMessage; -import org.testng.Assert; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; +import org.testng.Assert; +import org.testng.annotations.Test; public class NettyAsyncProviderPipelineTest extends AbstractBasicTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return new AsyncHttpClient(new CopyEncodingNettyAsyncHttpProvider(config), config); + return NettyProviderUtil.nettyProvider(config); } @Test(groups = { "standalone", "netty_provider" }) public void asyncPipelineTest() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build()); + + NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); + nettyConfig.setHttpAdditionalChannelInitializer(new AdditionalChannelInitializer() { + public void initChannel(Channel ch) throws Exception { + // super.initPlainChannel(ch); + ch.pipeline().addBefore("inflater", "copyEncodingHeader", new CopyEncodingHandler()); + } + }); + AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAsyncHttpClientProviderConfig(nettyConfig).build()); + try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); @@ -68,34 +73,17 @@ public Response onCompleted(Response response) throws Exception { } } - private static class CopyEncodingNettyAsyncHttpProvider extends NettyAsyncHttpProvider { - public CopyEncodingNettyAsyncHttpProvider(AsyncHttpClientConfig config) { - super(config); - } - - protected ChannelPipelineFactory createPlainPipelineFactory() { - final ChannelPipelineFactory pipelineFactory = super.createPlainPipelineFactory(); - return new ChannelPipelineFactory() { - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipelineFactory.getPipeline(); - pipeline.addBefore("inflater", "copyEncodingHeader", new CopyEncodingHandler()); - return pipeline; - } - }; - } - } - - private static class CopyEncodingHandler extends SimpleChannelHandler { + private static class CopyEncodingHandler extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { - Object msg = e.getMessage(); - if (msg instanceof HttpMessage) { - HttpMessage m = (HttpMessage) msg; - // for test there is no Content-Encoding header so just hard coding value + public void channelRead(ChannelHandlerContext ctx, Object e) { + if (e instanceof HttpMessage) { + HttpMessage m = (HttpMessage) e; + // for test there is no Content-Encoding header so just hard + // coding value // for verification - m.setHeader("X-Original-Content-Encoding", ""); + m.headers().set("X-Original-Content-Encoding", ""); } - ctx.sendUpstream(e); + ctx.fireChannelRead(e); } } } diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java similarity index 88% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java index 441048134a..653a89ceef 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java @@ -11,13 +11,13 @@ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.providers.netty_4.ResponseStatus; -import org.asynchttpclient.providers.netty_4.NettyResponse; import org.asynchttpclient.Cookie; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.providers.netty4.NettyResponse; +import org.asynchttpclient.providers.netty4.ResponseStatus; import org.testng.annotations.Test; import java.text.SimpleDateFormat; @@ -43,7 +43,8 @@ public void testCookieParseExpires() { Date date = new Date(System.currentTimeMillis() + 60000); // sdf.parse( dateString ); final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date)); - NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse + response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -60,7 +61,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseMaxAge() { final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -76,7 +77,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseWeirdExpiresValue() { final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamHandlerTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java index 1c1bea8935..cd292b06c1 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamHandlerTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamLifecycleTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamLifecycleTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java index 9760aa4296..acba9b815f 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncStreamLifecycleTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java index 61a633e002..7bf3ce2737 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java similarity index 69% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java index f8c7d3662d..749cf76f2c 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java @@ -10,28 +10,16 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; - -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.testng.annotations.Test; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; -@Test public class NettyBasicAuthTest extends BasicAuthTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - - @Override - @Test - public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException { - super.redirectAndBasicAuthTest(); // To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicHttpsTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicHttpsTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java index 5790fd96b1..31a20c5278 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBasicHttpsTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyChunkTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyChunkTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java index e8dacd9680..4cd124390f 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyChunkTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyDeferringAsyncHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyDeferringAsyncHandlerTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java index 01e8daba42..0a8e231014 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyBodyDeferringAsyncHandlerTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyByteBufferCapacityTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyByteBufferCapacityTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java index 8cabb0c637..b87ff9d130 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyByteBufferCapacityTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyChunkingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java similarity index 88% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyChunkingTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java index 7783e21d58..bc36fc0546 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyChunkingTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyComplexClientTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyComplexClientTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java index 7cb83020d0..f36fa3f814 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyComplexClientTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java similarity index 97% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java index 945761d5e1..1db87da20b 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit; -import org.jboss.netty.channel.Channel; +import io.netty.channel.Channel; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyDigestAuthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyDigestAuthTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java index 205fb73a1b..25d0771169 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyDigestAuthTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyEmptyBodyTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyEmptyBodyTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java index 8cdbe19e68..5c7f89ef2e 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyEmptyBodyTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyErrorResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyErrorResponseTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java index ee34de01fd..ed3a02549b 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyErrorResponseTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyExpect100ContinueTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyExpect100ContinueTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java index ce9759922e..62d52429e8 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyExpect100ContinueTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilePartLargeFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilePartLargeFileTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java index 8b9adcbd6b..02c459157e 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilePartLargeFileTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilterTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilterTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java index d1c6fd0ebb..bb0ea1fed4 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFilterTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFollowingThreadTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFollowingThreadTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java index c3e2c8b757..4461d5ef06 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyFollowingThreadTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHead302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHead302Test.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java index 8fc323e3b8..d4c13d3206 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHead302Test.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHostnameVerifierTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHostnameVerifierTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java index 004a2eb43e..f5051ec05c 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHostnameVerifierTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHttpToHttpsRedirectTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHttpToHttpsRedirectTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java index ec739b4065..89cf0d322a 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyHttpToHttpsRedirectTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyIdleStateHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyIdleStateHandlerTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java index 26dc2a2dbe..107cb8b0d5 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyIdleStateHandlerTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyInputStreamTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyInputStreamTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java index 5854ddc98f..1d271ee4ff 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyInputStreamTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyListenableFutureTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyListenableFutureTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java index 723fc12d59..cce436950d 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyListenableFutureTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxConnectionsInThreads.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxConnectionsInThreads.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java index 0e24c3d55d..593bb71bb8 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxConnectionsInThreads.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java @@ -9,7 +9,7 @@ * http://www.apache.org/licenses/LICENSE-2.0.html * You may elect to redistribute this code under either of these licenses. *******************************************************************************/ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxTotalConnectionTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxTotalConnectionTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java index 15e0892a69..5aef28ba4c 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMaxTotalConnectionTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java index fdbfb52d13..ff5a2028bb 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipleHeaderTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipleHeaderTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java index 2198b1b1f0..8cb91eae98 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyMultipleHeaderTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNoNullResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNoNullResponseTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java index d6b0122263..d74dc2d284 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNoNullResponseTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNonAsciiContentLengthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNonAsciiContentLengthTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java index 50fca62df0..098f63c3cb 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyNonAsciiContentLengthTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyParamEncodingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyParamEncodingTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java index d633d37979..380dbeb710 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyParamEncodingTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestRelative302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestRelative302Test.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java index b0fabf1ef6..c8a45f3c34 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestRelative302Test.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java similarity index 79% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java index 637a7ec365..4b669e81f9 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java @@ -10,13 +10,22 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; + +import static org.testng.Assert.assertTrue; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.PerRequestTimeoutTest; public class NettyPerRequestTimeoutTest extends PerRequestTimeoutTest { + + @Override + protected void checkTimeoutMessage(String message) { + assertTrue(message + .startsWith("Request reached time out of 100 ms after ")); + } + @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostRedirectGetTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostRedirectGetTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java index 979c761bd7..6c434178b4 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostRedirectGetTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java @@ -11,7 +11,7 @@ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostWithQSTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostWithQSTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java index c244b89c0b..44850262f6 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPostWithQSTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java similarity index 63% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java index 499e0025c4..d68cdb947d 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -21,16 +21,9 @@ public class NettyProviderUtil { public static AsyncHttpClient nettyProvider(AsyncHttpClientConfig config) { - // FIXME why do tests fail with this set up? Seems like we have a race condition - // if (config == null) { - // config = new AsyncHttpClientConfig.Builder().build(); - // } - // return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config); - - if (config == null) { - return new AsyncHttpClient(); - } else { - return new AsyncHttpClient(config); - } + if (config == null) { + config = new AsyncHttpClientConfig.Builder().build(); + } + return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config); } } diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java index 7c381c111d..b5cae8cefa 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java index a862e9ee8f..52c21987bc 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPutLargeFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPutLargeFileTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java index 550847c062..f71d57cea5 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyPutLargeFileTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyQueryParametersTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyQueryParametersTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java index 7a38145ef1..cc7fe3628a 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyQueryParametersTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRC10KTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRC10KTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java index 17f26efbb8..2c63c75b9d 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRC10KTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java similarity index 92% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java index 33810c3d3b..1283f47f60 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java @@ -10,13 +10,13 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.providers.netty_4.NettyAsyncHttpProviderConfig; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.RedirectConnectionUsageTest; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { @Override diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRelative302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRelative302Test.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java index 22fca88ad9..b9880e79c5 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRelative302Test.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRemoteSiteTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRemoteSiteTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java index 94c6f0d7aa..7a65ad5bca 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRemoteSiteTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java similarity index 99% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java index f0685b4561..314624c463 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRetryRequestTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRetryRequestTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java index d00acde3c2..ed148663e6 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyRetryRequestTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java @@ -14,7 +14,7 @@ * under the License. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java similarity index 84% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java index 27834862de..ad60dd6125 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncHttpClientTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java @@ -10,11 +10,12 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.SimpleAsyncHttpClientTest; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; public class NettySimpleAsyncHttpClientTest extends SimpleAsyncHttpClientTest { @@ -28,4 +29,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return null; } + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyTransferListenerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyTransferListenerTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java index 504607b654..deeb92e9c1 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyTransferListenerTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyWebDavBasicTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyWebDavBasicTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java index e3f938171b..5a26dbeac3 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyWebDavBasicTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyZeroCopyFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java similarity index 95% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyZeroCopyFileTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java index 3e98117d0d..04ee3c7a22 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/NettyZeroCopyFileTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java similarity index 97% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java index 0b781e7c6a..8b1aad25de 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java @@ -10,15 +10,15 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty; +package org.asynchttpclient.providers.netty4; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Request; import org.asynchttpclient.Response; -import org.asynchttpclient.providers.netty_4.NettyAsyncHttpProviderConfig; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; +import org.asynchttpclient.Request; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.nio.SelectChannelConnector; @@ -32,6 +32,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.net.ServerSocket; import java.net.URI; @@ -183,12 +184,8 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx bc.setMaximumConnectionsTotal(100); bc.setConnectionTimeoutInMs(60000); bc.setRequestTimeoutInMs(30000); + bc.setAsyncConnectMode(true); - NettyAsyncHttpProviderConfig config = new - NettyAsyncHttpProviderConfig(); - config.setAsyncConnect(true); - - bc.setAsyncHttpClientProviderConfig(config); c = new AsyncHttpClient(bc.build()); for (int i = 0; i < 32; i++) { diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyByteMessageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java similarity index 85% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyByteMessageTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java index 95b8d4cd53..5474f7f9f2 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyByteMessageTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java @@ -10,12 +10,11 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty.websocket; +package org.asynchttpclient.providers.netty4.websocket; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty.NettyProviderUtil; -import org.asynchttpclient.providers.netty.NettyProviderUtil; +import org.asynchttpclient.providers.netty4.NettyProviderUtil; import org.asynchttpclient.websocket.ByteMessageTest; public class NettyByteMessageTest extends ByteMessageTest { diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java similarity index 85% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java index 39feea5659..169b3189d6 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java @@ -11,12 +11,11 @@ * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty.websocket; +package org.asynchttpclient.providers.netty4.websocket; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty.NettyProviderUtil; -import org.asynchttpclient.providers.netty.NettyProviderUtil; +import org.asynchttpclient.providers.netty4.NettyProviderUtil; import org.asynchttpclient.websocket.CloseCodeReasonMessageTest; public class NettyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java similarity index 85% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java index 63b875480c..216083bf83 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java @@ -10,12 +10,11 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty.websocket; +package org.asynchttpclient.providers.netty4.websocket; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty.NettyProviderUtil; -import org.asynchttpclient.providers.netty.NettyProviderUtil; +import org.asynchttpclient.providers.netty4.NettyProviderUtil; import org.asynchttpclient.websocket.RedirectTest; public class NettyRedirectTest extends RedirectTest { diff --git a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java similarity index 85% rename from providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java rename to providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java index 7543bb7018..10832e370b 100644 --- a/providers/netty-4/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java @@ -10,12 +10,11 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty.websocket; +package org.asynchttpclient.providers.netty4.websocket; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty.NettyProviderUtil; -import org.asynchttpclient.providers.netty.NettyProviderUtil; +import org.asynchttpclient.providers.netty4.NettyProviderUtil; import org.asynchttpclient.websocket.TextMessageTest; public class NettyTextMessageTest extends TextMessageTest { diff --git a/providers/netty-4/src/test/resources/300k.png b/providers/netty4/src/test/resources/300k.png similarity index 100% rename from providers/netty-4/src/test/resources/300k.png rename to providers/netty4/src/test/resources/300k.png diff --git a/providers/netty-4/src/test/resources/SimpleTextFile.txt b/providers/netty4/src/test/resources/SimpleTextFile.txt similarity index 100% rename from providers/netty-4/src/test/resources/SimpleTextFile.txt rename to providers/netty4/src/test/resources/SimpleTextFile.txt diff --git a/providers/netty-4/src/test/resources/client.keystore b/providers/netty4/src/test/resources/client.keystore similarity index 100% rename from providers/netty-4/src/test/resources/client.keystore rename to providers/netty4/src/test/resources/client.keystore diff --git a/providers/netty-4/src/test/resources/gzip.txt.gz b/providers/netty4/src/test/resources/gzip.txt.gz similarity index 100% rename from providers/netty-4/src/test/resources/gzip.txt.gz rename to providers/netty4/src/test/resources/gzip.txt.gz diff --git a/providers/netty-4/src/test/resources/logback-test.xml b/providers/netty4/src/test/resources/logback-test.xml similarity index 100% rename from providers/netty-4/src/test/resources/logback-test.xml rename to providers/netty4/src/test/resources/logback-test.xml diff --git a/providers/netty-4/src/test/resources/realm.properties b/providers/netty4/src/test/resources/realm.properties similarity index 100% rename from providers/netty-4/src/test/resources/realm.properties rename to providers/netty4/src/test/resources/realm.properties diff --git a/providers/netty-4/src/test/resources/ssltest-cacerts.jks b/providers/netty4/src/test/resources/ssltest-cacerts.jks similarity index 100% rename from providers/netty-4/src/test/resources/ssltest-cacerts.jks rename to providers/netty4/src/test/resources/ssltest-cacerts.jks diff --git a/providers/netty-4/src/test/resources/ssltest-keystore.jks b/providers/netty4/src/test/resources/ssltest-keystore.jks similarity index 100% rename from providers/netty-4/src/test/resources/ssltest-keystore.jks rename to providers/netty4/src/test/resources/ssltest-keystore.jks diff --git a/providers/netty-4/src/test/resources/textfile.txt b/providers/netty4/src/test/resources/textfile.txt similarity index 100% rename from providers/netty-4/src/test/resources/textfile.txt rename to providers/netty4/src/test/resources/textfile.txt diff --git a/providers/netty-4/src/test/resources/textfile2.txt b/providers/netty4/src/test/resources/textfile2.txt similarity index 100% rename from providers/netty-4/src/test/resources/textfile2.txt rename to providers/netty4/src/test/resources/textfile2.txt diff --git a/providers/pom.xml b/providers/pom.xml index 64f8d23763..0fb9d7957e 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -47,7 +47,7 @@ grizzly netty From 99894b7e51d389af6959282d894a9243d45f55fd Mon Sep 17 00:00:00 2001 From: slandelle Date: Mon, 2 Sep 2013 16:23:16 +0200 Subject: [PATCH 0068/2389] Fix NPE --- .../providers/netty4/NettyAsyncHttpProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java index b331f6a61d..28a8a7184b 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java @@ -75,7 +75,7 @@ public void close() { isClose.set(true); try { channels.close(); - config.executorService().shutdown(); +// config.executorService().shutdown(); config.reaper().shutdown(); } catch (Throwable t) { LOGGER.warn("Unexpected error on close", t); From f5adef08f7fa7e8384c75e16e8929b2121278721 Mon Sep 17 00:00:00 2001 From: slandelle Date: Mon, 2 Sep 2013 23:27:36 +0200 Subject: [PATCH 0069/2389] Upgrade surefire, 2.12 causing malloc crashes --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5227949fc5..096d117982 100644 --- a/pom.xml +++ b/pom.xml @@ -584,7 +584,7 @@ 1.6 1.6 - 2.12 + 2.16 From 10b8ad8558e75618cdcccea74f91f1e71f7030ea Mon Sep 17 00:00:00 2001 From: slandelle Date: Mon, 2 Sep 2013 23:28:29 +0200 Subject: [PATCH 0070/2389] Properly configure provider when using a SimpleClient --- .../test/java/org/asynchttpclient/async/BasicAuthTest.java | 5 ++++- .../java/org/asynchttpclient/async/ProxyTunnellingTest.java | 4 +++- .../asynchttpclient/async/SimpleAsyncHttpClientTest.java | 1 - .../providers/grizzly/GrizzlyBasicAuthTest.java | 5 ++++- .../providers/grizzly/GrizzlyProxyTunnelingTest.java | 4 ++++ .../asynchttpclient/providers/netty/ResponseBodyPart.java | 1 + .../asynchttpclient/providers/netty/NettyBasicAuthTest.java | 6 +++++- .../providers/netty/NettyProxyTunnellingTest.java | 4 ++++ .../java/org/asynchttpclient/providers/netty4/Channels.java | 2 +- .../providers/netty4/NettyBasicAuthTest.java | 6 ++++++ .../providers/netty4/NettyProxyTunnellingTest.java | 5 +++++ .../providers/netty4/NettyRedirectConnectionUsageTest.java | 1 - 12 files changed, 37 insertions(+), 7 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 2a277caa2b..7638571cca 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -48,6 +48,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -72,6 +73,8 @@ public abstract class BasicAuthTest extends AbstractBasicTest { protected final static String admin = "admin"; private Server server2; + + public abstract String getProviderClass(); @BeforeClass(alwaysRun = true) @Override @@ -475,7 +478,7 @@ public AbstractHandler configureHandler() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void stringBuilderBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setRealmPrincipal(user).setRealmPassword(admin).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setRealmPrincipal(user).setRealmPassword(admin).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index 61a2bc551e..1b29a99f07 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -45,6 +45,8 @@ public abstract class ProxyTunnellingTest extends AbstractBasicTest { private Server server2; + public abstract String getProviderClass(); + public AbstractHandler configureHandler() throws Exception { ProxyHandler proxy = new ProxyHandler(); return proxy; @@ -152,7 +154,7 @@ public Response onCompleted(Response response) throws Exception { @Test(groups = { "online", "default_provider" }) public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProxyProtocol(ProxyServer.Protocol.HTTPS).setProxyHost("127.0.0.1").setProxyPort(port1).setFollowRedirects(true).setUrl(getTargetUrl2()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setProxyProtocol(ProxyServer.Protocol.HTTPS).setProxyHost("127.0.0.1").setProxyPort(port1).setFollowRedirects(true).setUrl(getTargetUrl2()).setHeader("Content-Type", "text/html").build(); try { Response r = client.get().get(); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 2d7d8e84f4..58265ff379 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -27,7 +27,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import static junit.framework.Assert.assertTrue; diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java index 06bd657f24..f7551168fd 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java @@ -19,10 +19,13 @@ public class GrizzlyBasicAuthTest extends BasicAuthTest { - @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } + @Override + public String getProviderClass() { + return GrizzlyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyProxyTunnelingTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyProxyTunnelingTest.java index eb6f39cd23..434cda5730 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyProxyTunnelingTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyProxyTunnelingTest.java @@ -24,4 +24,8 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } + @Override + public String getProviderClass() { + return GrizzlyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java index b8d6411d8f..7f138bbc36 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java @@ -45,6 +45,7 @@ public class ResponseBodyPart extends HttpResponseBodyPart { /** * Constructor used for non-chunked GET requests and HEAD requests. */ + // FIXME Why notify with a null chunk??? public ResponseBodyPart(URI uri, HttpResponse response, AsyncHttpProvider provider, boolean last) { this(uri, response, provider, null, last); } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java index f8c7d3662d..bce0962953 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java @@ -16,7 +16,6 @@ import java.util.concurrent.TimeoutException; import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; @@ -29,6 +28,11 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } + @Override + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } + @Override @Test public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException { diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java index a862e9ee8f..396964f8cd 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProxyTunnellingTest.java @@ -21,4 +21,8 @@ public class NettyProxyTunnellingTest extends ProxyTunnellingTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } + + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index 3fa4d6751c..fb4c15fba9 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -238,7 +238,6 @@ public Bootstrap getBootstrap(String url, boolean useSSl) { public void close() { connectionsPool.destroy(); - openChannels.close(); for (Channel channel : openChannels) { Object attribute = getDefaultAttribute(channel); if (attribute instanceof NettyResponseFuture) { @@ -246,6 +245,7 @@ public void close() { future.setReaperFuture(null); } } + openChannels.close(); if (this.allowReleaseSocketChannelFactory) { eventLoop.shutdownGracefully(); } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java index 749cf76f2c..971fe6b107 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java @@ -15,6 +15,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; public class NettyBasicAuthTest extends BasicAuthTest { @@ -22,4 +23,9 @@ public class NettyBasicAuthTest extends BasicAuthTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } + + @Override + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java index 52c21987bc..736b9d3699 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java @@ -15,10 +15,15 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.ProxyTunnellingTest; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; public class NettyProxyTunnellingTest extends ProxyTunnellingTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } + + public String getProviderClass() { + return NettyAsyncHttpProvider.class.getName(); + } } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java index 1283f47f60..e0e99cff6a 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java @@ -16,7 +16,6 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.RedirectConnectionUsageTest; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { @Override From 3ab0c6051286dca4f04e82b938a7cccdbfcc88e4 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 00:18:08 +0200 Subject: [PATCH 0071/2389] Add description --- extras/jdeferred/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/extras/jdeferred/pom.xml b/extras/jdeferred/pom.xml index c79702732e..b1db2e59f1 100644 --- a/extras/jdeferred/pom.xml +++ b/extras/jdeferred/pom.xml @@ -22,6 +22,7 @@ .. async-http-client-extras-jdeferred + The Async Http Client jDeffered Extras. org.jdeferred From 68ef9dea37ebf958ac32dfd46245a24d924ed5e4 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 00:18:33 +0200 Subject: [PATCH 0072/2389] Make BasicHttpsTest threadsafe! --- .../asynchttpclient/async/BasicHttpsTest.java | 77 +++++++++---------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index 619f523223..1aa8dc5581 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -207,7 +207,7 @@ public void setUpGlobal() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void zeroCopyPostTest() throws Throwable { - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { ClassLoader cl = getClass().getClassLoader(); // override system properties @@ -226,7 +226,7 @@ public void zeroCopyPostTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void multipleSSLRequestsTest() throws Throwable { - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext()).build()); + final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { String body = "hello there"; @@ -246,7 +246,7 @@ public void multipleSSLRequestsTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void multipleSSLWithoutCacheTest() throws Throwable { - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext()).setAllowSslConnectionPool(false).build()); + final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build()); try { String body = "hello there"; c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute(); @@ -263,40 +263,36 @@ public void multipleSSLWithoutCacheTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void reconnectsAfterFailedCertificationPath() throws Throwable { - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext()).build()); + AtomicBoolean trusted = new AtomicBoolean(false); + final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build()); try { final String body = "hello there"; - TRUST_SERVER_CERT.set(false); + // first request fails because server certificate is rejected try { - // first request fails because server certificate is rejected - try { - c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); - } catch (final ExecutionException e) { - Throwable cause = e.getCause(); - if (cause instanceof ConnectException) { - assertNotNull(cause.getCause()); - assertTrue(cause.getCause() instanceof SSLHandshakeException); - } else { - assertTrue(cause instanceof SSLHandshakeException); - } + c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); + } catch (final ExecutionException e) { + Throwable cause = e.getCause(); + if (cause instanceof ConnectException) { + assertNotNull(cause.getCause()); + assertTrue(cause.getCause() instanceof SSLHandshakeException); + } else { + assertTrue(cause instanceof SSLHandshakeException); } + } - TRUST_SERVER_CERT.set(true); + trusted.set(true); - // second request should succeed - final Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); + // second request should succeed + final Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); - assertEquals(response.getResponseBody(), body); - } finally { - TRUST_SERVER_CERT.set(true); - } + assertEquals(response.getResponseBody(), body); } finally { c.close(); } } - private static SSLContext createSSLContext() { + private static SSLContext createSSLContext(AtomicBoolean trusted) { try { InputStream keyStoreStream = BasicHttpsTest.class.getResourceAsStream("ssltest-cacerts.jks"); char[] keyStorePassword = "changeit".toCharArray(); @@ -310,7 +306,7 @@ private static SSLContext createSSLContext() { // Initialize the SSLContext to work with our key managers. KeyManager[] keyManagers = kmf.getKeyManagers(); - TrustManager[] trustManagers = new TrustManager[] { DUMMY_TRUST_MANAGER }; + TrustManager[] trustManagers = new TrustManager[] { dummyTrustManager(trusted) }; SecureRandom secureRandom = new SecureRandom(); SSLContext sslContext = SSLContext.getInstance("TLS"); @@ -322,20 +318,21 @@ private static SSLContext createSSLContext() { } } - private static final AtomicBoolean TRUST_SERVER_CERT = new AtomicBoolean(true); - private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - if (!TRUST_SERVER_CERT.get()) { - throw new CertificateException("Server certificate not trusted."); - } - } - }; + private static final TrustManager dummyTrustManager(final AtomicBoolean trusted) { + return new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + if (!trusted.get()) { + throw new CertificateException("Server certificate not trusted."); + } + } + }; + } } From 59494b7c323806055f8ee00d537224269bb7f79e Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 10:23:34 +0200 Subject: [PATCH 0073/2389] Clean up pom --- pom.xml | 143 ++++++++++++++++++++------------------------------------ 1 file changed, 50 insertions(+), 93 deletions(-) diff --git a/pom.xml b/pom.xml index 096d117982..8587006ded 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,6 @@ - + org.sonatype.oss oss-parent @@ -281,75 +280,28 @@ - - + + @@ -376,8 +328,10 @@ 1.0.3 - -hdf project.name "${project.name} ${project.version}" - -d ${project.reporting.outputDirectory}/apidocs + -hdf project.name "${project.name} + ${project.version}" + -d + ${project.reporting.outputDirectory}/apidocs @@ -460,8 +414,7 @@ test-output - false - + false @@ -499,92 +452,96 @@ ch.qos.logback logback-classic - 1.0.13 + ${logback.version} test log4j log4j - 1.2.13 + ${log4j.version} test org.testng testng - 5.8 + ${testng.version} test - jdk15 org.eclipse.jetty jetty-server - 8.1.1.v20120215 + ${jetty.version} test org.eclipse.jetty jetty-servlet - 8.1.1.v20120215 + ${jetty.version} test org.eclipse.jetty jetty-websocket - 8.1.1.v20120215 + ${jetty.version} test org.eclipse.jetty jetty-servlets - 8.1.1.v20120215 + ${jetty.version} test org.eclipse.jetty jetty-security - 8.1.1.v20120215 + ${jetty.version} test org.apache.tomcat coyote - 6.0.29 + ${tomcat.version} test org.apache.tomcat catalina - 6.0.29 + ${tomcat.version} test - servlet-api org.apache.tomcat + servlet-api commons-io commons-io - 2.0.1 + ${commons-io.version} test commons-fileupload commons-fileupload - 1.2.2 + ${commons-fileupload.version} test - - http://oss.sonatype.org/content/repositories/snapshots - + http://oss.sonatype.org/content/repositories/snapshots true 1.6 1.6 2.16 + 1.0.13 + 1.2.17 + 6.8.5 + 8.1.1.v20120215 + 6.0.29 + 2.4 + 1.3 From c8795e5d528080cf053d64480b13877c7820da83 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 10:23:45 +0200 Subject: [PATCH 0074/2389] Make NettyTransferAdapter thread safe --- .../providers/netty4/NettyTransferAdapter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java index fdeb04587c..e388e64545 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.listener.TransferCompletionHandler; @@ -13,7 +14,7 @@ class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter { private final ByteBuf content; private final FileInputStream file; - private int byteRead = 0; + private AtomicInteger byteRead = new AtomicInteger(0); public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf content, File file) throws IOException { super(headers); @@ -28,11 +29,10 @@ public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf con @Override public void getBytes(byte[] bytes) { if (content.writableBytes() != 0) { - content.getBytes(byteRead, bytes); - byteRead += bytes.length; + content.getBytes(byteRead.getAndAdd(bytes.length), bytes); } else if (file != null) { try { - byteRead += file.read(bytes); + byteRead.getAndAdd(file.read(bytes)); } catch (IOException e) { NettyAsyncHttpProvider.LOGGER.error(e.getMessage(), e); } From bed6e1f30a88a25d8b79ce7ba7da605f27aabbce Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 14:36:02 +0200 Subject: [PATCH 0075/2389] Minor clean up --- .../asynchttpclient/filter/FilterContext.java | 2 +- .../org/asynchttpclient/async/ProxyTest.java | 6 +++- extras/jdeferred/pom.xml | 1 + .../providers/netty/NettyBasicAuthTest.java | 11 +------- .../providers/netty4/Channels.java | 28 +++++++++++-------- .../providers/netty4/NettyChannelHandler.java | 2 ++ .../providers/netty4/NettyRequestSender.java | 1 + .../providers/netty4/Protocol.java | 2 +- 8 files changed, 29 insertions(+), 24 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/filter/FilterContext.java b/api/src/main/java/org/asynchttpclient/filter/FilterContext.java index 5a5dc14001..dfc6f9de22 100644 --- a/api/src/main/java/org/asynchttpclient/filter/FilterContext.java +++ b/api/src/main/java/org/asynchttpclient/filter/FilterContext.java @@ -23,7 +23,7 @@ * A {@link FilterContext} can be used to decorate {@link Request} and {@link AsyncHandler} from a list of {@link RequestFilter}. * {@link RequestFilter} gets executed before the HTTP request is made to the remote server. Once the response bytes are * received, a {@link FilterContext} is then passed to the list of {@link ResponseFilter}. {@link ResponseFilter} - * gets invoked before the response gets processed, e.g. before authorization, redirection and invokation of {@link AsyncHandler} + * gets invoked before the response gets processed, e.g. before authorization, redirection and invocation of {@link AsyncHandler} * gets processed. *

* Invoking {@link FilterContext#getResponseStatus()} returns an instance of {@link HttpResponseStatus} diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java index 1af6c073f1..2cbb8e3677 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java @@ -150,6 +150,7 @@ public void testProxyProperties() throws IOException, ExecutionException, Timeou Properties props = new Properties(); props.putAll(originalProps); + // FIXME most likely non threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -189,6 +190,7 @@ public void testIgnoreProxyPropertiesByDefault() throws IOException, ExecutionEx Properties props = new Properties(); props.putAll(originalProps); + // FIXME most likely non threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -220,6 +222,7 @@ public void testProxyActivationProperty() throws IOException, ExecutionException Properties props = new Properties(); props.putAll(originalProps); + // FIXME most likely non threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -259,6 +262,7 @@ public void testWildcardNonProxyHosts() throws IOException, ExecutionException, Properties props = new Properties(); props.putAll(originalProps); + // FIXME most likely non threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -323,8 +327,8 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { client.close(); } } finally { + // FIXME is this threadsafe??? ProxySelector.setDefault(originalProxySelector); } } - } diff --git a/extras/jdeferred/pom.xml b/extras/jdeferred/pom.xml index b1db2e59f1..af6ddab2ad 100644 --- a/extras/jdeferred/pom.xml +++ b/extras/jdeferred/pom.xml @@ -22,6 +22,7 @@ .. async-http-client-extras-jdeferred + Async Http Client jDeffered Extras The Async Http Client jDeffered Extras. diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java index bce0962953..d824606453 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java @@ -12,13 +12,10 @@ */ package org.asynchttpclient.providers.netty; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; - -import org.testng.annotations.Test; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; +import org.testng.annotations.Test; @Test public class NettyBasicAuthTest extends BasicAuthTest { @@ -32,10 +29,4 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return NettyAsyncHttpProvider.class.getName(); } - - @Override - @Test - public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException { - super.redirectAndBasicAuthTest(); // To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index fb4c15fba9..a6805581af 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -25,6 +25,7 @@ import io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder; import io.netty.handler.ssl.SslHandler; import io.netty.handler.stream.ChunkedWriteHandler; +import io.netty.util.Attribute; import io.netty.util.AttributeKey; import java.io.IOException; @@ -66,7 +67,7 @@ public class Channels { private final AsyncHttpClientConfig config; private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; - private EventLoopGroup eventLoop; + private EventLoopGroup eventLoopGroup; private final Class socketChannelFactory; private final boolean allowReleaseSocketChannelFactory; @@ -109,12 +110,12 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig this.allowReleaseSocketChannelFactory = false; } else { socketChannelFactory = NioSocketChannel.class; - eventLoop = asyncHttpProviderConfig.getEventLoopGroup(); - if (eventLoop == null) { + eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup(); + if (eventLoopGroup == null) { if (socketChannelFactory == OioSocketChannel.class) { - eventLoop = new OioEventLoopGroup(); + eventLoopGroup = new OioEventLoopGroup(); } else if (socketChannelFactory == NioSocketChannel.class) { - eventLoop = new NioEventLoopGroup(); + eventLoopGroup = new NioEventLoopGroup(); } else { throw new IllegalArgumentException("No set event loop compatbile with socket channel " + scf); } @@ -125,10 +126,10 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig } } - plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); - secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); - webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); - secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop); + plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); + secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); + webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); + secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); // This is dangerous as we can't catch a wrong typed ConnectionsPool ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); @@ -247,7 +248,7 @@ public void close() { } openChannels.close(); if (this.allowReleaseSocketChannelFactory) { - eventLoop.shutdownGracefully(); + eventLoopGroup.shutdownGracefully(); } } @@ -494,7 +495,12 @@ public static Object getDefaultAttribute(Channel channel) { } public static Object getDefaultAttribute(ChannelHandlerContext ctx) { - return ctx.attr(DEFAULT_ATTRIBUTE).get(); + if (ctx == null) { + // ctx might be null if the channel never reached the handler + return null; + } + Attribute attr = ctx.attr(DEFAULT_ATTRIBUTE); + return attr != null ? attr.get() : null; } public static void setDefaultAttribute(Channel channel, Object o) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index c35e985be7..570b53cfde 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -835,6 +835,8 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); } } + } else if (e instanceof LastHttpContent) { + // FIXME what to do with this kind of messages? } else { LOGGER.error("Invalid message {}", e); } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index 92572ccc74..87386a1ea1 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -340,6 +340,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie if (Channels.getSslHandler(channel) != null) { writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise()); } else { + // FIXME why not use io.netty.channel.DefaultFileRegion? FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); writeFuture = channel.write(region, channel.newProgressivePromise()); } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java index 19e62a52d9..57445877e8 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java @@ -16,7 +16,7 @@ public interface Protocol{ - void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception; + void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception; void onError(ChannelHandlerContext ctx, Throwable error); From 425c86201f4145171b27c6a0ca0256339812f4f1 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 15:51:41 +0200 Subject: [PATCH 0076/2389] Close clients in test! and in finally blocks! --- .../async/AsyncProvidersBasicTest.java | 16 ++-- .../async/BodyDeferringAsyncHandlerTest.java | 46 +++++----- .../asynchttpclient/async/ChunkingTest.java | 28 +++---- .../async/RedirectConnectionUsageTest.java | 34 +++----- .../asynchttpclient/async/RemoteSiteTest.java | 12 +-- .../async/SimpleAsyncHttpClientTest.java | 5 +- .../async/WebDavBasicTest.java | 9 +- .../websocket/ByteMessageTest.java | 84 ++++++++++--------- 8 files changed, 121 insertions(+), 113 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index c2564716f0..e5a8d4a503 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1704,12 +1704,16 @@ public void asyncHttpClientConfigBeanTest() throws Exception { @Test(groups = { "default_provider", "async" }) public void bodyAsByteTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); - Response r = client.prepareGet(getTargetUrl()).execute().get(); - - assertEquals(r.getStatusCode(), 200); - assertEquals(r.getResponseBodyAsBytes(), new byte[] {}); - - client.close(); + try { + Response r = client.prepareGet(getTargetUrl()).execute().get(); + + assertEquals(r.getStatusCode(), 200); + assertEquals(r.getResponseBodyAsBytes(), new byte[] {}); + + client.close(); + } finally { + client.close(); + } } @Test(groups = { "default_provider", "async" }) diff --git a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java index e6bf47bf9e..cf8a8c9934 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java @@ -214,29 +214,32 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T @Test(groups = { "standalone", "default_provider" }) public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(getAsyncHttpClientConfig()); - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString()); - - PipedOutputStream pos = new PipedOutputStream(); - PipedInputStream pis = new PipedInputStream(pos); - BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos); - - Future f = r.execute(bdah); - - BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis); - - Response resp = is.getAsapResponse(); - assertNotNull(resp); - assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); - // "consume" the body, but our code needs input stream - CountingOutputStream cos = new CountingOutputStream(); + try { - copy(is, cos); - Assert.fail("InputStream consumption should fail with IOException!"); - } catch (IOException e) { - // good! + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString()); + PipedOutputStream pos = new PipedOutputStream(); + PipedInputStream pis = new PipedInputStream(pos); + BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos); + + Future f = r.execute(bdah); + + BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis); + + Response resp = is.getAsapResponse(); + assertNotNull(resp); + assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); + assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); + // "consume" the body, but our code needs input stream + CountingOutputStream cos = new CountingOutputStream(); + try { + copy(is, cos); + Assert.fail("InputStream consumption should fail with IOException!"); + } catch (IOException e) { + // good! + } + } finally { + client.close(); } - client.close(); } @Test(groups = { "standalone", "default_provider" }) @@ -259,5 +262,4 @@ public void testConnectionRefused() throws IOException, ExecutionException, Time client.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index c4b008ec77..efffe05660 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -73,20 +73,19 @@ abstract public class ChunkingTest extends AbstractBasicTest { */ @Test() public void testCustomChunking() throws Throwable { - AsyncHttpClient c = null; + AsyncHttpClientConfig.Builder bc = + new AsyncHttpClientConfig.Builder(); + + bc.setAllowPoolingConnection(true); + bc.setMaximumConnectionsPerHost(1); + bc.setMaximumConnectionsTotal(1); + bc.setConnectionTimeoutInMs(1000); + bc.setRequestTimeoutInMs(1000); + bc.setFollowRedirects(true); + + + AsyncHttpClient c = getAsyncHttpClient(bc.build()); try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsPerHost(1); - bc.setMaximumConnectionsTotal(1); - bc.setConnectionTimeoutInMs(1000); - bc.setRequestTimeoutInMs(1000); - bc.setFollowRedirects(true); - - - c = getAsyncHttpClient(bc.build()); RequestBuilder builder = new RequestBuilder("POST"); builder.setUrl(getTargetUrl()); @@ -119,7 +118,7 @@ public void testCustomChunking() throws Throwable { } } finally { - if (c != null) c.close(); + c.close(); } } @@ -163,5 +162,4 @@ private static File getTestFile() { return testResource1File; } - } diff --git a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java index ee1c0c1065..2691ad3f38 100644 --- a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java @@ -104,19 +104,18 @@ public void tearDown() { @Test public void testGetRedirectFinalUrl() { - AsyncHttpClient c = null; + AsyncHttpClientConfig.Builder bc = + new AsyncHttpClientConfig.Builder(); + + bc.setAllowPoolingConnection(true); + bc.setMaximumConnectionsPerHost(1); + bc.setMaximumConnectionsTotal(1); + bc.setConnectionTimeoutInMs(1000); + bc.setRequestTimeoutInMs(1000); + bc.setFollowRedirects(true); + + AsyncHttpClient c = getAsyncHttpClient(bc.build()); try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsPerHost(1); - bc.setMaximumConnectionsTotal(1); - bc.setConnectionTimeoutInMs(1000); - bc.setRequestTimeoutInMs(1000); - bc.setFollowRedirects(true); - - c = getAsyncHttpClient(bc.build()); RequestBuilder builder = new RequestBuilder("GET"); builder.setUrl(servletEndpointRedirectUrl); @@ -138,14 +137,9 @@ public void testGetRedirectFinalUrl() { fail("Should not get here, The request threw an exception"); } - - } - finally { - // can hang here - if (c != null) c.close(); + } finally { + c.close(); } - - } protected abstract AsyncHttpProviderConfig getProviderConfig(); @@ -182,6 +176,4 @@ public void service(HttpServletRequest req, HttpServletResponse res) throws Serv os.close(); } } - - } diff --git a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java index 8e609af81d..f94ff385a3 100644 --- a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java @@ -90,10 +90,13 @@ public void testMicrosoftCom() throws Throwable { @Test(groups = { "online", "default_provider" }) public void testWwwMicrosoftCom() throws Throwable { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); - - Response response = c.prepareGet("http://www.microsoft.com/").execute().get(10, TimeUnit.SECONDS); - assertNotNull(response); - assertEquals(response.getStatusCode(), 302); + try { + Response response = c.prepareGet("http://www.microsoft.com/").execute().get(10, TimeUnit.SECONDS); + assertNotNull(response); + assertEquals(response.getStatusCode(), 302); + } finally { + c.close(); + } } @Test(groups = { "online", "default_provider" }) @@ -298,5 +301,4 @@ public Response onCompleted() throws Exception { c.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 58265ff379..d5849b1dad 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -217,11 +217,14 @@ public void onBytesReceived(String url, long amount, long current, long total) { @Test(groups = { "standalone", "default_provider" }) public void testNullUrl() throws Exception { + SimpleAsyncHttpClient client = null; try { - new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build().derive().build(); + client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build().derive().build(); assertTrue(true); } catch (NullPointerException ex) { fail(); + } finally { + if (client != null) client.close(); } } diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index fb8d5abff4..4d5374d447 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -83,9 +83,12 @@ protected String getTargetUrl() { @AfterMethod(alwaysRun = true) public void clean() throws InterruptedException, Exception { AsyncHttpClient c = getAsyncHttpClient(null); - - Request deleteRequest = new RequestBuilder("DELETE").setUrl(getTargetUrl()).build(); - c.executeRequest(deleteRequest).get(); + try { + Request deleteRequest = new RequestBuilder("DELETE").setUrl(getTargetUrl()).build(); + c.executeRequest(deleteRequest).get(); + } finally { + c.close(); + } } @AfterClass(alwaysRun = true) diff --git a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java index f9086515c7..8676d63628 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java @@ -214,46 +214,50 @@ public void onFragment(byte[] fragment, boolean last) { public void echoFragments() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); - final CountDownLatch latch = new CountDownLatch(1); - final AtomicReference text = new AtomicReference(null); - - WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketByteListener() { - - @Override - public void onOpen(WebSocket websocket) { - } - - @Override - public void onClose(WebSocket websocket) { - latch.countDown(); - } - - @Override - public void onError(Throwable t) { - t.printStackTrace(); - latch.countDown(); - } - - @Override - public void onMessage(byte[] message) { - if (text.get() == null) { - text.set(message); - } else { - byte[] n = new byte[text.get().length + message.length]; - System.arraycopy(text.get(), 0, n, 0, text.get().length); - System.arraycopy(message, 0, n, text.get().length, message.length); - text.set(n); + try { + final CountDownLatch latch = new CountDownLatch(1); + final AtomicReference text = new AtomicReference(null); + + WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketByteListener() { + + @Override + public void onOpen(WebSocket websocket) { } - latch.countDown(); - } - - @Override - public void onFragment(byte[] fragment, boolean last) { - } - }).build()).get(); - websocket.stream("ECHO".getBytes(), false); - websocket.stream("ECHO".getBytes(), true); - latch.await(); - assertEquals(text.get(), "ECHOECHO".getBytes()); + + @Override + public void onClose(WebSocket websocket) { + latch.countDown(); + } + + @Override + public void onError(Throwable t) { + t.printStackTrace(); + latch.countDown(); + } + + @Override + public void onMessage(byte[] message) { + if (text.get() == null) { + text.set(message); + } else { + byte[] n = new byte[text.get().length + message.length]; + System.arraycopy(text.get(), 0, n, 0, text.get().length); + System.arraycopy(message, 0, n, text.get().length, message.length); + text.set(n); + } + latch.countDown(); + } + + @Override + public void onFragment(byte[] fragment, boolean last) { + } + }).build()).get(); + websocket.stream("ECHO".getBytes(), false); + websocket.stream("ECHO".getBytes(), true); + latch.await(); + assertEquals(text.get(), "ECHOECHO".getBytes()); + } finally { + c.close(); + } } } From 9d62925ff7bd1144f6b138f4bbd47d33e375f935 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 3 Sep 2013 10:26:29 -0700 Subject: [PATCH 0077/2389] Call setMaxPendingBytesPerConnection() at the right time. --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 0f7e66ac94..c91c1af7a6 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -359,7 +359,8 @@ public void onTimeout(Connection connection) { secure.add(clientFilter); secure.add(new WebSocketClientFilter()); - + clientTransport.getAsyncQueueIO().getWriter() + .setMaxPendingBytesPerConnection(AUTO_SIZE); if (providerConfig != null) { final TransportCustomizer customizer = (TransportCustomizer) providerConfig.getProperty(Property.TRANSPORT_CUSTOMIZER); @@ -383,10 +384,6 @@ public void onTimeout(Connection connection) { .setClientSideNegotiator(clientTransport, pn); } - // Don't limit the number of bytes the client can have queued to write. - clientTransport.getAsyncQueueIO().getWriter() - .setMaxPendingBytesPerConnection(AUTO_SIZE); - // Install the HTTP filter chain. //clientTransport.setProcessor(fcb.build()); FilterChainBuilder nonSecure = FilterChainBuilder.stateless(); From 6a92c2d3fefaa23cd6fef20492e58a569f49f35c Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 21:12:14 +0200 Subject: [PATCH 0078/2389] Remove EntityWriter, close #372 --- .../org/asynchttpclient/AsyncHttpClient.java | 10 ---- .../java/org/asynchttpclient/Request.java | 16 ------ .../org/asynchttpclient/RequestBuilder.java | 12 ---- .../asynchttpclient/RequestBuilderBase.java | 23 -------- .../providers/jdk/JDKAsyncHttpProvider.java | 7 --- .../async/AsyncProvidersBasicTest.java | 51 ----------------- .../bodyhandler/BodyHandlerFactory.java | 1 - .../bodyhandler/EntityWriterBodyHandler.java | 57 ------------------- .../netty/NettyAsyncHttpProvider.java | 16 +----- .../providers/netty4/NettyRequests.java | 24 -------- 10 files changed, 1 insertion(+), 216 deletions(-) delete mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/EntityWriterBodyHandler.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 4a8661a3b5..bc5c170d7d 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -316,16 +316,6 @@ public BoundRequestBuilder setBody(byte[] data) throws IllegalArgumentException return super.setBody(data); } - @Override - public BoundRequestBuilder setBody(Request.EntityWriter dataWriter, long length) throws IllegalArgumentException { - return super.setBody(dataWriter, length); - } - - @Override - public BoundRequestBuilder setBody(Request.EntityWriter dataWriter) { - return super.setBody(dataWriter); - } - @Override public BoundRequestBuilder setBody(InputStream stream) throws IllegalArgumentException { return super.setBody(stream); diff --git a/api/src/main/java/org/asynchttpclient/Request.java b/api/src/main/java/org/asynchttpclient/Request.java index 34b41bcb27..2c68f6df5b 100644 --- a/api/src/main/java/org/asynchttpclient/Request.java +++ b/api/src/main/java/org/asynchttpclient/Request.java @@ -17,9 +17,7 @@ package org.asynchttpclient; import java.io.File; -import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.net.InetAddress; import java.net.URI; import java.util.Collection; @@ -38,13 +36,6 @@ */ public interface Request { - /** - * An entity that can be used to manipulate the Request's body output before it get sent. - */ - public static interface EntityWriter { - public void writeEntity(OutputStream out) throws IOException; - } - /** * Return the request's method name (GET, POST, etc.) * @@ -122,13 +113,6 @@ public static interface EntityWriter { */ public InputStream getStreamData(); - /** - * Return the current request's body as an EntityWriter - * - * @return an EntityWriter representation of the current request's body. - */ - public EntityWriter getEntityWriter(); - /** * Return the current request's body generator. * diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilder.java b/api/src/main/java/org/asynchttpclient/RequestBuilder.java index b1b608284b..034249a5a7 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilder.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilder.java @@ -15,8 +15,6 @@ */ package org.asynchttpclient; -import org.asynchttpclient.Request.EntityWriter; - import java.io.InputStream; import java.util.Collection; import java.util.Map; @@ -88,16 +86,6 @@ public RequestBuilder setBody(byte[] data) throws IllegalArgumentException { return super.setBody(data); } - @Override - public RequestBuilder setBody(EntityWriter dataWriter, long length) throws IllegalArgumentException { - return super.setBody(dataWriter, length); - } - - @Override - public RequestBuilder setBody(EntityWriter dataWriter) { - return super.setBody(dataWriter); - } - /** * Deprecated - Use setBody(new InputStreamBodyGenerator(inputStream)). * diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index e082ea8741..c1bbc4b289 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -17,7 +17,6 @@ import static org.asynchttpclient.util.MiscUtil.isNonEmpty; -import org.asynchttpclient.Request.EntityWriter; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.asynchttpclient.util.UTF8UrlEncoder; import org.slf4j.Logger; @@ -59,7 +58,6 @@ private static final class RequestImpl implements Request { private byte[] byteData; private String stringData; private InputStream streamData; - private EntityWriter entityWriter; private BodyGenerator bodyGenerator; private FluentStringsMap params; private List parts; @@ -91,7 +89,6 @@ public RequestImpl(Request prototype) { this.byteData = prototype.getByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); - this.entityWriter = prototype.getEntityWriter(); this.bodyGenerator = prototype.getBodyGenerator(); this.params = (prototype.getParams() == null ? null : new FluentStringsMap(prototype.getParams())); this.queryParams = (prototype.getQueryParams() == null ? null : new FluentStringsMap(prototype.getQueryParams())); @@ -247,11 +244,6 @@ public InputStream getStreamData() { return streamData; } - /* @Override */ - public EntityWriter getEntityWriter() { - return entityWriter; - } - /* @Override */ public BodyGenerator getBodyGenerator() { return bodyGenerator; @@ -497,7 +489,6 @@ private void resetNonMultipartData() { request.byteData = null; request.stringData = null; request.streamData = null; - request.entityWriter = null; request.length = -1; } @@ -544,20 +535,6 @@ public T setBody(InputStream stream) throws IllegalArgumentException { return derived.cast(this); } - public T setBody(EntityWriter dataWriter) { - return setBody(dataWriter, -1); - } - - public T setBody(EntityWriter dataWriter, long length) throws IllegalArgumentException { - checkIfBodyAllowed(); - resetParameters(); - resetNonMultipartData(); - resetMultipartData(); - request.entityWriter = dataWriter; - request.length = length; - return derived.cast(this); - } - public T setBody(BodyGenerator bodyGenerator) { checkIfBodyAllowed(); request.bodyGenerator = bodyGenerator; diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index 7f5ec241dc..9268f67cc9 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -622,13 +622,6 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request urlConnection.setRequestProperty("Content-Length", String.valueOf(mre.getContentLength())); mre.writeRequest(urlConnection.getOutputStream()); - } else if (request.getEntityWriter() != null) { - int lenght = (int) request.getContentLength(); - if (lenght != -1) { - urlConnection.setRequestProperty("Content-Length", String.valueOf(lenght)); - urlConnection.setFixedLengthStreamingMode(lenght); - } - request.getEntityWriter().writeEntity(urlConnection.getOutputStream()); } else if (request.getFile() != null) { File file = request.getFile(); if (!file.isFile()) { diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index e5a8d4a503..8b412ba97d 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -23,7 +23,6 @@ import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.OutputStream; import java.net.ConnectException; import java.net.HttpURLConnection; import java.net.URL; @@ -673,56 +672,6 @@ public Response onCompleted(Response response) throws Exception { } } - @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostEntityWriterTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); - try { - final CountDownLatch l = new CountDownLatch(1); - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - h.add("Content-Type", "application/x-www-form-urlencoded"); - - final StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); - } - sb.setLength(sb.length() - 1); - byte[] bytes = sb.toString().getBytes(); - h.add("Content-Length", String.valueOf(bytes.length)); - - c.preparePost(getTargetUrl()).setHeaders(h).setBody(new Request.EntityWriter() { - - /* @Override */ - public void writeEntity(OutputStream out) throws IOException { - out.write(sb.toString().getBytes("UTF-8")); - } - }).execute(new AsyncCompletionHandlerAdapter() { - - @Override - public Response onCompleted(Response response) throws Exception { - try { - assertEquals(response.getStatusCode(), 200); - for (int i = 1; i < 5; i++) { - System.out.println(">>>>> " + response.getHeader("X-param_" + i)); - assertEquals(response.getHeader("X-param_" + i), "value_" + i); - } - } finally { - l.countDown(); - } - return response; - } - }).get(); - if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); - } - } finally { - c.close(); - } - } - @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostMultiPartTest() throws Throwable { AsyncHttpClient c = getAsyncHttpClient(null); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java index f5486f3d8b..ef43fc445e 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyHandlerFactory.java @@ -25,7 +25,6 @@ public BodyHandlerFactory(GrizzlyAsyncHttpProvider grizzlyAsyncHttpProvider) { new StringBodyHandler(grizzlyAsyncHttpProvider), new ByteArrayBodyHandler(grizzlyAsyncHttpProvider), new ParamsBodyHandler(grizzlyAsyncHttpProvider), - new EntityWriterBodyHandler(), new StreamDataBodyHandler(), new PartsBodyHandler(), new FileBodyHandler(), diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/EntityWriterBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/EntityWriterBodyHandler.java deleted file mode 100644 index 7b2aad63a3..0000000000 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/EntityWriterBodyHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2013 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.grizzly.bodyhandler; - -import org.asynchttpclient.Request; -import org.glassfish.grizzly.Buffer; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.http.HttpContent; -import org.glassfish.grizzly.http.HttpRequestPacket; -import org.glassfish.grizzly.memory.MemoryManager; -import org.glassfish.grizzly.utils.BufferOutputStream; - -import java.io.IOException; - -public final class EntityWriterBodyHandler implements BodyHandler { - - // -------------------------------------------- Methods from BodyHandler - - - public boolean handlesBodyType(final Request request) { - return (request.getEntityWriter() != null); - } - - @SuppressWarnings({"unchecked"}) - public boolean doHandle(final FilterChainContext ctx, - final Request request, - final HttpRequestPacket requestPacket) - throws IOException { - - final MemoryManager mm = ctx.getMemoryManager(); - Buffer b = mm.allocate(512); - BufferOutputStream o = new BufferOutputStream(mm, b, true); - final Request.EntityWriter writer = request.getEntityWriter(); - writer.writeEntity(o); - b = o.getBuffer(); - b.trim(); - if (b.hasRemaining()) { - final HttpContent content = requestPacket.httpContentBuilder().content(b).build(); - content.setLast(true); - ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); - } - - return true; - } - -} // END EntityWriterBodyHandler diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 4559250d3f..33132e549d 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -60,7 +60,6 @@ import org.asynchttpclient.websocket.WebSocketUpgradeHandler; import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferOutputStream; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; @@ -132,11 +131,9 @@ import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.Semaphore; -import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; import static org.asynchttpclient.util.DateUtil.millisTime; @@ -802,17 +799,6 @@ else if (uri.getRawQuery() != null) nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength())); - } else if (request.getEntityWriter() != null) { - int length = getPredefinedContentLength(request, nettyRequest); - - if (length == -1) { - length = MAX_BUFFERED_BYTES; - } - - ChannelBuffer b = ChannelBuffers.dynamicBuffer(length); - request.getEntityWriter().writeEntity(new ChannelBufferOutputStream(b)); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); - nettyRequest.setContent(b); } else if (request.getFile() != null) { File file = request.getFile(); if (!file.isFile()) { @@ -2209,7 +2195,7 @@ private void invokeOnSucces(ChannelHandlerContext ctx, WebSocketUpgradeHandler h try { h.onSuccess(new NettyWebSocket(ctx.getChannel())); } catch (Exception ex) { - NettyAsyncHttpProvider.this.log.warn("onSuccess unexexpected exception", ex); + NettyAsyncHttpProvider.log.warn("onSuccess unexexpected exception", ex); } } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java index 960bd2009a..d392678abc 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java @@ -6,7 +6,6 @@ import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; import static org.asynchttpclient.util.MiscUtil.isNonEmpty; import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.Unpooled; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultHttpRequest; @@ -49,16 +48,6 @@ public static HttpRequest newNettyRequest(AsyncHttpClientConfig config, Request return construct(config, request, new HttpMethod(method), uri, proxyServer); } - private static int getPredefinedContentLength(Request request, Map headers) { - int length = (int) request.getContentLength(); - Object contentLength = headers.get(HttpHeaders.Names.CONTENT_LENGTH); - if (length == -1 && contentLength != null) { - length = Integer.valueOf(contentLength.toString()); - } - - return length; - } - private static HttpRequest construct(AsyncHttpClientConfig config, Request request, HttpMethod m, URI uri, ProxyServer proxyServer) throws IOException { String host = null; @@ -278,19 +267,6 @@ else if (uri.getRawQuery() != null) hasDeferredContent = true; - } else if (request.getEntityWriter() != null) { - int length = getPredefinedContentLength(request, headers); - - if (length == -1) { - length = Constants.MAX_BUFFERED_BYTES; - } - - ByteBuf b = Unpooled.buffer(length); - // FIXME doesn't do what EntityWriter javadoc says - request.getEntityWriter().writeEntity(new ByteBufOutputStream(b)); - // FIXME seems wrong when length was original -1, not sure the ByteBug increase, and feels like should be streaming - headers.put(HttpHeaders.Names.CONTENT_LENGTH, b.writerIndex()); - content = b; } else if (request.getFile() != null) { File file = request.getFile(); if (!file.isFile()) { From c737c0dadff9d3434d5dd95bb709f5f9b19d0573 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 21:13:53 +0200 Subject: [PATCH 0079/2389] Don't deprecate RequestBuilder.setBody(InputStream), close #373 --- api/src/main/java/org/asynchttpclient/RequestBuilder.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilder.java b/api/src/main/java/org/asynchttpclient/RequestBuilder.java index 034249a5a7..09c43c6d9f 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilder.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilder.java @@ -87,18 +87,12 @@ public RequestBuilder setBody(byte[] data) throws IllegalArgumentException { } /** - * Deprecated - Use setBody(new InputStreamBodyGenerator(inputStream)). - * + * Set a Stream for chunking * @param stream - An {@link InputStream} * @return a {@link RequestBuilder} * @throws IllegalArgumentException - * @see #setBody(BodyGenerator) InputStreamBodyGenerator(inputStream) - * @see org.asynchttpclient.generators.InputStreamBodyGenerator - * @deprecated {@link #setBody(BodyGenerator)} setBody(new InputStreamBodyGenerator(inputStream)) */ @Override - // FIXME I'd do the exact opposite: deprecate InputStreamBodyGenerator - @Deprecated public RequestBuilder setBody(InputStream stream) throws IllegalArgumentException { return super.setBody(stream); } From f052c028c767439483d9f8f125c2c958d983a769 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 22:34:10 +0200 Subject: [PATCH 0080/2389] Remove TransferCompletionHandler.TransferAdapter.getBytes, close #374 --- .../AsyncCompletionHandler.java | 2 +- .../ResumableRandomAccessFileListener.java | 3 +- .../listener/TransferCompletionHandler.java | 87 +++---------------- .../listener/TransferListener.java | 6 +- .../resumable/ResumableAsyncHandler.java | 4 +- .../filters/AsyncHttpClientFilter.java | 25 +----- .../netty/NettyAsyncHttpProvider.java | 35 +------- .../providers/netty4/NettyRequestSender.java | 7 +- .../netty4/NettyTransferAdapter.java | 41 --------- 9 files changed, 27 insertions(+), 183 deletions(-) delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java b/api/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java index b8e8d70889..b27a99dfb4 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/AsyncCompletionHandler.java @@ -105,7 +105,7 @@ public STATE onContentWriteCompleted() { /** * Invoked when the I/O operation associated with the {@link Request} body as been progressed. * - * @param amount The amount of bytes to transfer. + * @param amount The amount of bytes to transfer * @param current The amount of bytes transferred * @param total The total number of bytes transferred * @return a {@link org.asynchttpclient.AsyncHandler.STATE} telling to CONTINUE or ABORT the current processing. diff --git a/api/src/main/java/org/asynchttpclient/extra/ResumableRandomAccessFileListener.java b/api/src/main/java/org/asynchttpclient/extra/ResumableRandomAccessFileListener.java index 546b59a117..e8a63a0f6c 100644 --- a/api/src/main/java/org/asynchttpclient/extra/ResumableRandomAccessFileListener.java +++ b/api/src/main/java/org/asynchttpclient/extra/ResumableRandomAccessFileListener.java @@ -12,7 +12,6 @@ */ package org.asynchttpclient.extra; -import org.asynchttpclient.resumable.ResumableListener; import org.asynchttpclient.resumable.ResumableListener; import java.io.IOException; @@ -20,7 +19,7 @@ import java.nio.ByteBuffer; /** - * A {@link org.asynchttpclient.listener.TransferListener} which use a {@link RandomAccessFile} for storing the received bytes. + * A {@link org.asynchttpclient.resumable.ResumableListener} which use a {@link RandomAccessFile} for storing the received bytes. */ public class ResumableRandomAccessFileListener implements ResumableListener { private final RandomAccessFile file; diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index 833387cad7..0fa9a90968 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -12,8 +12,6 @@ */ package org.asynchttpclient.listener; -import static org.asynchttpclient.util.MiscUtil.isNonEmpty; - import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseBodyPart; @@ -24,9 +22,7 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicLong; /** * A {@link org.asynchttpclient.AsyncHandler} that can be used to notify a set of {@link TransferListener} @@ -63,8 +59,6 @@ public class TransferCompletionHandler extends AsyncCompletionHandlerBase { private final ConcurrentLinkedQueue listeners = new ConcurrentLinkedQueue(); private final boolean accumulateResponseBytes; private TransferAdapter transferAdapter; - private AtomicLong bytesTransferred = new AtomicLong(); - private AtomicLong totalBytesToTransfer = new AtomicLong(0); /** * Create a TransferCompletionHandler that will not accumulate bytes. The resulting {@link org.asynchttpclient.Response#getResponseBody()}, @@ -116,10 +110,7 @@ public void transferAdapter(TransferAdapter transferAdapter) { this.transferAdapter = transferAdapter; } - /** - * {@inheritDoc} - */ - /* @Override */ + @Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { fireOnHeaderReceived(headers.getHeaders()); return super.onHeadersReceived(headers); @@ -131,7 +122,7 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep if (accumulateResponseBytes) { s = super.onBodyPartReceived(content); } - fireOnBytesReceived(content.getBodyPartBytes()); + fireOnBytesReceived(content.getBodyByteBuffer()); return s; } @@ -141,46 +132,22 @@ public Response onCompleted(Response response) throws Exception { return response; } - /** - * {@inheritDoc} - */ + @Override public STATE onHeaderWriteCompleted() { - List list = transferAdapter.getHeaders().get("Content-Length"); - if (isNonEmpty(list) && !list.get(0).isEmpty()) { - totalBytesToTransfer.set(Long.valueOf(list.get(0))); + if (transferAdapter != null) { + fireOnHeadersSent(transferAdapter.getHeaders()); } - - fireOnHeadersSent(transferAdapter.getHeaders()); return STATE.CONTINUE; } - /** - * {@inheritDoc} - */ + @Override public STATE onContentWriteCompleted() { return STATE.CONTINUE; } - /** - * {@inheritDoc} - */ + @Override public STATE onContentWriteProgress(long amount, long current, long total) { - if (bytesTransferred.get() == -1) { - return STATE.CONTINUE; - } - - if (totalBytesToTransfer.get() == 0) { - totalBytesToTransfer.set(total); - } - - // We need to track the count because all is asynchronous and Netty may not invoke us on time. - bytesTransferred.addAndGet(amount); - - if (transferAdapter != null) { - byte[] bytes = new byte[(int) (amount)]; - transferAdapter.getBytes(bytes); - fireOnBytesSent(bytes); - } + fireOnBytesSent(amount, current, total); return STATE.CONTINUE; } @@ -211,32 +178,6 @@ private void fireOnHeaderReceived(FluentCaseInsensitiveStringsMap headers) { } private void fireOnEnd() { - // There is a probability that the asynchronous listener never gets called, so we fake it at the end once - // we are 100% sure the response has been received. - long count = bytesTransferred.getAndSet(-1); - if (count != totalBytesToTransfer.get()) { - if (transferAdapter != null) { - byte[] bytes = new byte[8192]; - int leftBytes = (int) (totalBytesToTransfer.get() - count); - int length = 8192; - while (leftBytes > 0) { - if (leftBytes > 8192) { - leftBytes -= 8192; - } else { - length = leftBytes; - leftBytes = 0; - } - - if (length < 8192) { - bytes = new byte[length]; - } - - transferAdapter.getBytes(bytes); - fireOnBytesSent(bytes); - } - } - } - for (TransferListener l : listeners) { try { l.onRequestResponseCompleted(); @@ -246,20 +187,20 @@ private void fireOnEnd() { } } - private void fireOnBytesReceived(byte[] b) { + private void fireOnBytesReceived(ByteBuffer b) { for (TransferListener l : listeners) { try { - l.onBytesReceived(ByteBuffer.wrap(b)); + l.onBytesReceived(b); } catch (Throwable t) { l.onThrowable(t); } } } - private void fireOnBytesSent(byte[] b) { + private void fireOnBytesSent(long amount, long current, long total) { for (TransferListener l : listeners) { try { - l.onBytesSent(ByteBuffer.wrap(b)); + l.onBytesSent(amount, current, total); } catch (Throwable t) { l.onThrowable(t); } @@ -276,7 +217,7 @@ private void fireOnThrowable(Throwable t) { } } - public abstract static class TransferAdapter { + public static class TransferAdapter { private final FluentCaseInsensitiveStringsMap headers; public TransferAdapter(FluentCaseInsensitiveStringsMap headers) throws IOException { @@ -286,7 +227,5 @@ public TransferAdapter(FluentCaseInsensitiveStringsMap headers) throws IOExcepti public FluentCaseInsensitiveStringsMap getHeaders() { return headers; } - - public abstract void getBytes(byte[] bytes); } } diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferListener.java b/api/src/main/java/org/asynchttpclient/listener/TransferListener.java index 7ae2344462..a793996f34 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferListener.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferListener.java @@ -42,9 +42,11 @@ public interface TransferListener { /** * Invoked every time request's chunk are sent. * - * @param buffer a {@link ByteBuffer} + * @param amount The amount of bytes to transfer + * @param current The amount of bytes transferred + * @param total The total number of bytes transferred */ - public void onBytesSent(ByteBuffer buffer); + public void onBytesSent(long amount, long current, long total); /** * Invoked when the response bytes are been fully received. diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java index ec3a4f17e7..6991d05383 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java @@ -33,8 +33,8 @@ /** * An {@link AsyncHandler} which support resumable download, e.g when used with an {@link ResumableIOExceptionFilter}, - * this handler can resume the download operation at the point it was before the interruption occured. This prevent having to - * download the entire file again. It's the responsibility of the {@link org.asynchttpclient.listener.TransferListener} + * this handler can resume the download operation at the point it was before the interruption occurred. This prevent having to + * download the entire file again. It's the responsibility of the {@link org.asynchttpclient.resumable.ResumableAsyncHandler} * to track how many bytes has been transferred and to properly adjust the file's write position. *

* In case of a JVM crash/shutdown, you can create an instance of this class and pass the last valid bytes position. diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index fccf36361c..ce9078d5ea 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -25,6 +25,7 @@ import org.asynchttpclient.Response; import org.asynchttpclient.UpgradeHandler; import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.GrizzlyResponseFuture; import org.asynchttpclient.providers.grizzly.HttpTransactionContext; @@ -289,7 +290,7 @@ private static void initTransferCompletionHandler(final Request request, final FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(request.getHeaders()); TransferCompletionHandler.class.cast(h) - .transferAdapter(new GrizzlyTransferAdapter(map)); + .transferAdapter(new TransferAdapter(map)); } } @@ -472,28 +473,6 @@ private static void addQueryString(final Request request, } - public static final class GrizzlyTransferAdapter extends TransferCompletionHandler.TransferAdapter { - - - // -------------------------------------------------------- Constructors - - - public GrizzlyTransferAdapter(FluentCaseInsensitiveStringsMap headers) throws IOException { - super(headers); - } - - - // ---------------------------------------- Methods from TransferAdapter - - - @Override - public void getBytes(byte[] bytes) { - // TODO implement - } - - } // END GrizzlyTransferAdapter - - class HttpRequestPacketImpl extends HttpRequestPacket { private ProcessingState processingState = new ProcessingState(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 33132e549d..f5b6879d10 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -43,6 +43,7 @@ import org.asynchttpclient.filter.ResponseFilter; import org.asynchttpclient.generators.InputStreamBodyGenerator; import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.multipart.MultipartBody; import org.asynchttpclient.multipart.MultipartRequestEntity; import org.asynchttpclient.ntlm.NTLMEngine; @@ -107,7 +108,6 @@ import javax.net.ssl.SSLEngine; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.RandomAccessFile; import java.net.ConnectException; @@ -452,7 +452,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie } } - TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new NettyTransferAdapter(h, nettyRequest.getContent(), future.getRequest().getFile())); + TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new TransferAdapter(h)); } // Leave it to true. @@ -1833,37 +1833,6 @@ public void releaseExternalResources() { } } - private static class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter { - - private final ChannelBuffer content; - private final FileInputStream file; - private int byteRead = 0; - - public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ChannelBuffer content, File file) throws IOException { - super(headers); - this.content = content; - if (file != null) { - this.file = new FileInputStream(file); - } else { - this.file = null; - } - } - - @Override - public void getBytes(byte[] bytes) { - if (content.writableBytes() != 0) { - content.getBytes(byteRead, bytes); - byteRead += bytes.length; - } else if (file != null) { - try { - byteRead += file.read(bytes); - } catch (IOException e) { - log.error(e.getMessage(), e); - } - } - } - } - protected AsyncHttpClientConfig getConfig() { return config; } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index 87386a1ea1..49e1a35b88 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -3,14 +3,11 @@ import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; import io.netty.bootstrap.Bootstrap; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelProgressiveFuture; import io.netty.channel.FileRegion; -import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpRequest; @@ -44,6 +41,7 @@ import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.generators.InputStreamBodyGenerator; import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.multipart.MultipartBody; import org.asynchttpclient.providers.netty4.FeedableBodyGenerator.FeedListener; import org.asynchttpclient.util.AsyncHttpProviderUtils; @@ -303,8 +301,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie h.add(entries.getKey(), entries.getValue()); } - ByteBuf content = nettyRequest instanceof FullHttpRequest ? FullHttpRequest.class.cast(nettyRequest).content() : Unpooled.buffer(0); - TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new NettyTransferAdapter(h, content, future.getRequest().getFile())); + TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new TransferAdapter(h)); } // Leave it to true. diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java deleted file mode 100644 index e388e64545..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyTransferAdapter.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -import io.netty.buffer.ByteBuf; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; - -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.listener.TransferCompletionHandler; - -class NettyTransferAdapter extends TransferCompletionHandler.TransferAdapter { - - private final ByteBuf content; - private final FileInputStream file; - private AtomicInteger byteRead = new AtomicInteger(0); - - public NettyTransferAdapter(FluentCaseInsensitiveStringsMap headers, ByteBuf content, File file) throws IOException { - super(headers); - this.content = content; - if (file != null) { - this.file = new FileInputStream(file); - } else { - this.file = null; - } - } - - @Override - public void getBytes(byte[] bytes) { - if (content.writableBytes() != 0) { - content.getBytes(byteRead.getAndAdd(bytes.length), bytes); - } else if (file != null) { - try { - byteRead.getAndAdd(file.read(bytes)); - } catch (IOException e) { - NettyAsyncHttpProvider.LOGGER.error(e.getMessage(), e); - } - } - } -} \ No newline at end of file From 017bc92ee4939546ad7ec525b5fa98f55a45a911 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 22:34:27 +0200 Subject: [PATCH 0081/2389] Make PutLargeFileTest thread safe --- .../async/PutLargeFileTest.java | 84 ++++++++----------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index c058c689a9..2fafcdeff7 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -12,6 +12,16 @@ */ package org.asynchttpclient.async; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.UUID; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; import org.asynchttpclient.AsyncHttpClientConfig; @@ -19,37 +29,37 @@ import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; import org.testng.Assert; -import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.UUID; - /** * @author Benjamin Hanzelmann */ public abstract class PutLargeFileTest extends AbstractBasicTest { - private File largeFile; + private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); + private static final byte[] PATTERN_BYTES = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes(Charset.forName("UTF-16")); + + static { + TMP.mkdirs(); + TMP.deleteOnExit(); + } @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeFile() throws Exception { - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 1024 * 100 / bytes.length) + 1; - largeFile = createTempFile(bytes, (int) repeats); - int timeout = (int) (largeFile.length() / 1000); + + long repeats = (1024 * 1024 * 100 / PATTERN_BYTES.length) + 1; + File file = createTempFile(PATTERN_BYTES, (int) repeats); + long expectedFileSize = PATTERN_BYTES.length * repeats; + Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); + + int timeout = (int) (repeats / 1000); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build(); AsyncHttpClient client = getAsyncHttpClient(config); try { BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - rb.setBody(largeFile); + rb.setBody(file); Response response = rb.execute().get(); Assert.assertEquals(200, response.getStatusCode()); @@ -60,16 +70,17 @@ public void testPutLargeFile() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testPutSmallFile() throws Exception { - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 / bytes.length) + 1; - // int timeout = (5000); - largeFile = createTempFile(bytes, (int) repeats); + + long repeats = (1024 / PATTERN_BYTES.length) + 1; + File file = createTempFile(PATTERN_BYTES, (int) repeats); + long expectedFileSize = PATTERN_BYTES.length * repeats; + Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); AsyncHttpClient client = getAsyncHttpClient(null); try { BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - rb.setBody(largeFile); + rb.setBody(file); Response response = rb.execute().get(); Assert.assertEquals(200, response.getStatusCode()); @@ -78,26 +89,12 @@ public void testPutSmallFile() throws Exception { } } - @AfterMethod - public void after() { - largeFile.delete(); - } - @Override public AbstractHandler configureHandler() throws Exception { return new AbstractHandler() { public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { - ServletInputStream in = req.getInputStream(); - byte[] b = new byte[8092]; - - int count = -1; - int total = 0; - while ((count = in.read(b)) != -1) { - total += count; - } - resp.setStatus(200); resp.getOutputStream().flush(); resp.getOutputStream().close(); @@ -107,24 +104,12 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle }; } - private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); - public static File createTempFile(byte[] pattern, int repeat) throws IOException { - TMP.mkdirs(); - TMP.deleteOnExit(); File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); tmpFile.deleteOnExit(); - write(pattern, repeat, tmpFile); - - return tmpFile; - } - - public static void write(byte[] pattern, int repeat, File file) throws IOException { - file.deleteOnExit(); - file.getParentFile().mkdirs(); FileOutputStream out = null; try { - out = new FileOutputStream(file); + out = new FileOutputStream(tmpFile); for (int i = 0; i < repeat; i++) { out.write(pattern); } @@ -133,6 +118,7 @@ public static void write(byte[] pattern, int repeat, File file) throws IOExcepti out.close(); } } - } + return tmpFile; + } } From 8abdd5ea86c1790df11ebbbaac676d53c9934ac4 Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 23:05:51 +0200 Subject: [PATCH 0082/2389] Make TransferListener. onBytesReceived receive a byte array --- .../listener/TransferCompletionHandler.java | 5 +- .../listener/TransferListener.java | 5 +- .../async/TransferListenerTest.java | 135 ++++++++++-------- 3 files changed, 76 insertions(+), 69 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index 0fa9a90968..00962814a5 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; -import java.nio.ByteBuffer; import java.util.concurrent.ConcurrentLinkedQueue; /** @@ -122,7 +121,7 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep if (accumulateResponseBytes) { s = super.onBodyPartReceived(content); } - fireOnBytesReceived(content.getBodyByteBuffer()); + fireOnBytesReceived(content.getBodyPartBytes()); return s; } @@ -187,7 +186,7 @@ private void fireOnEnd() { } } - private void fireOnBytesReceived(ByteBuffer b) { + private void fireOnBytesReceived(byte[] b) { for (TransferListener l : listeners) { try { l.onBytesReceived(b); diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferListener.java b/api/src/main/java/org/asynchttpclient/listener/TransferListener.java index a793996f34..d61a675295 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferListener.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferListener.java @@ -15,7 +15,6 @@ import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import java.io.IOException; -import java.nio.ByteBuffer; /** * A simple interface an application can implements in order to received byte transfer information. @@ -35,9 +34,9 @@ public interface TransferListener { /** * Invoked every time response's chunk are received. * - * @param buffer a {@link ByteBuffer} + * @param bytes a {@link byte[]} */ - public void onBytesReceived(ByteBuffer buffer) throws IOException; + public void onBytesReceived(byte[] bytes) throws IOException; /** * Invoked every time request's chunk are sent. diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 48e18c1bed..7fb60b8969 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -12,35 +12,46 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.Response; -import org.asynchttpclient.generators.FileBodyGenerator; -import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.listener.TransferListener; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.util.Enumeration; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.Response; +import org.asynchttpclient.generators.FileBodyGenerator; +import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.listener.TransferListener; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.Assert; +import org.testng.annotations.Test; public abstract class TransferListenerTest extends AbstractBasicTest { + private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); + private static final byte[] PATTERN_BYTES = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes(Charset.forName("UTF-16")); + + static { + TMP.mkdirs(); + TMP.deleteOnExit(); + } private class BasicHandler extends AbstractHandler { @@ -81,7 +92,7 @@ public void basicGetTest() throws Throwable { final AtomicReference throwable = new AtomicReference(); final AtomicReference hSent = new AtomicReference(); final AtomicReference hRead = new AtomicReference(); - final AtomicReference bb = new AtomicReference(); + final AtomicReference bb = new AtomicReference(); final AtomicBoolean completed = new AtomicBoolean(false); TransferCompletionHandler tl = new TransferCompletionHandler(); @@ -95,11 +106,11 @@ public void onResponseHeadersReceived(FluentCaseInsensitiveStringsMap headers) { hRead.set(headers); } - public void onBytesReceived(ByteBuffer buffer) { - bb.set(buffer); + public void onBytesReceived(byte[] b) { + bb.set(b); } - public void onBytesSent(ByteBuffer buffer) { + public void onBytesSent(long amount, long current, long total) { } public void onRequestResponseCompleted() { @@ -130,20 +141,24 @@ public void onThrowable(Throwable t) { @Test(groups = { "standalone", "default_provider" }) public void basicPutTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); - try { - final AtomicReference throwable = new AtomicReference(); - final AtomicReference hSent = new AtomicReference(); - final AtomicReference hRead = new AtomicReference(); - final AtomicInteger bbReceivedLenght = new AtomicInteger(0); - final AtomicInteger bbSentLenght = new AtomicInteger(0); + final AtomicReference throwable = new AtomicReference(); + final AtomicReference hSent = new AtomicReference(); + final AtomicReference hRead = new AtomicReference(); + final AtomicInteger bbReceivedLenght = new AtomicInteger(0); + final AtomicLong bbSentLenght = new AtomicLong(0L); - final AtomicBoolean completed = new AtomicBoolean(false); + final AtomicBoolean completed = new AtomicBoolean(false); + + byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); + long repeats = (1024 * 100 * 10 / bytes.length) + 1; + File file = createTempFile(bytes, (int) repeats); + long expectedFileSize = PATTERN_BYTES.length * repeats; + Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 100 * 10 / bytes.length) + 1; - File largeFile = createTempFile(bytes, (int) repeats); + int timeout = (int) (repeats / 1000); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); + try { TransferCompletionHandler tl = new TransferCompletionHandler(); tl.addTransferListener(new TransferListener() { @@ -155,12 +170,12 @@ public void onResponseHeadersReceived(FluentCaseInsensitiveStringsMap headers) { hRead.set(headers); } - public void onBytesReceived(ByteBuffer buffer) { - bbReceivedLenght.addAndGet(buffer.capacity()); + public void onBytesReceived(byte[] b) { + bbReceivedLenght.addAndGet(b.length); } - public void onBytesSent(ByteBuffer buffer) { - bbSentLenght.addAndGet(buffer.capacity()); + public void onBytesSent(long amount, long current, long total) { + bbSentLenght.addAndGet(amount); } public void onRequestResponseCompleted() { @@ -173,37 +188,38 @@ public void onThrowable(Throwable t) { }); try { - Response response = c.preparePut(getTargetUrl()).setBody(largeFile).execute(tl).get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute(tl).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertNotNull(hRead.get()); assertNotNull(hSent.get()); - assertEquals(bbReceivedLenght.get(), largeFile.length()); - assertEquals(bbSentLenght.get(), largeFile.length()); + assertEquals(bbReceivedLenght.get(), expectedFileSize, "Number of received bytes incorrect"); + assertEquals(bbSentLenght.get(), expectedFileSize, "Number of sent bytes incorrect"); } catch (IOException ex) { fail("Should have timed out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider" }) public void basicPutBodyTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicReference throwable = new AtomicReference(); final AtomicReference hSent = new AtomicReference(); final AtomicReference hRead = new AtomicReference(); final AtomicInteger bbReceivedLenght = new AtomicInteger(0); - final AtomicInteger bbSentLenght = new AtomicInteger(0); + final AtomicLong bbSentLenght = new AtomicLong(0L); final AtomicBoolean completed = new AtomicBoolean(false); - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 100 * 10 / bytes.length) + 1; - File largeFile = createTempFile(bytes, (int) repeats); + long repeats = (1024 * 100 * 10 / PATTERN_BYTES.length) + 1; + File file = createTempFile(PATTERN_BYTES, (int) repeats); + long expectedFileSize = PATTERN_BYTES.length * repeats; + Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); TransferCompletionHandler tl = new TransferCompletionHandler(); tl.addTransferListener(new TransferListener() { @@ -216,12 +232,12 @@ public void onResponseHeadersReceived(FluentCaseInsensitiveStringsMap headers) { hRead.set(headers); } - public void onBytesReceived(ByteBuffer buffer) { - bbReceivedLenght.addAndGet(buffer.capacity()); + public void onBytesReceived(byte[] b) { + bbReceivedLenght.addAndGet(b.length); } - public void onBytesSent(ByteBuffer buffer) { - bbSentLenght.addAndGet(buffer.capacity()); + public void onBytesSent(long amount, long current, long total) { + bbSentLenght.addAndGet(amount); } public void onRequestResponseCompleted() { @@ -234,19 +250,19 @@ public void onThrowable(Throwable t) { }); try { - Response response = c.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(largeFile)).execute(tl).get(); + Response response = client.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(file)).execute(tl).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertNotNull(hRead.get()); assertNotNull(hSent.get()); - assertEquals(bbReceivedLenght.get(), largeFile.length()); - assertEquals(bbSentLenght.get(), largeFile.length()); + assertEquals(bbReceivedLenght.get(), expectedFileSize, "Number of received bytes incorrect"); + assertEquals(bbSentLenght.get(), expectedFileSize, "Number of sent bytes incorrect"); } catch (IOException ex) { fail("Should have timed out"); } } finally { - c.close(); + client.close(); } } @@ -255,20 +271,11 @@ public String getTargetUrl() { } public static File createTempFile(byte[] pattern, int repeat) throws IOException { - TMP.mkdirs(); - TMP.deleteOnExit(); File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); - write(pattern, repeat, tmpFile); - - return tmpFile; - } - - public static void write(byte[] pattern, int repeat, File file) throws IOException { - file.deleteOnExit(); - file.getParentFile().mkdirs(); + tmpFile.deleteOnExit(); FileOutputStream out = null; try { - out = new FileOutputStream(file); + out = new FileOutputStream(tmpFile); for (int i = 0; i < repeat; i++) { out.write(pattern); } @@ -277,5 +284,7 @@ public static void write(byte[] pattern, int repeat, File file) throws IOExcepti out.close(); } } + + return tmpFile; } } From 6993a49b2792a1c8cc7506cd945a18adb14178bd Mon Sep 17 00:00:00 2001 From: slandelle Date: Tue, 3 Sep 2013 23:28:50 +0200 Subject: [PATCH 0083/2389] ChannelProgressiveFutureListener.operationProgressed should be working this way --- .../asynchttpclient/async/TransferListenerTest.java | 5 ++--- .../providers/netty4/ProgressListener.java | 11 +++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 7fb60b8969..61561a4fb4 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -149,9 +149,8 @@ public void basicPutTest() throws Throwable { final AtomicBoolean completed = new AtomicBoolean(false); - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 100 * 10 / bytes.length) + 1; - File file = createTempFile(bytes, (int) repeats); + long repeats = (1024 * 100 * 10 / PATTERN_BYTES.length) + 1; + File file = createTempFile(PATTERN_BYTES, (int) repeats); long expectedFileSize = PATTERN_BYTES.length * repeats; Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java index 5670a3f6be..37f6c68bf0 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java @@ -4,6 +4,7 @@ import io.netty.channel.ChannelProgressiveFutureListener; import java.nio.channels.ClosedChannelException; +import java.util.concurrent.atomic.AtomicLong; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; @@ -16,6 +17,7 @@ public class ProgressListener implements ChannelProgressiveFutureListener { private final boolean notifyHeaders; private final AsyncHandler asyncHandler; private final NettyResponseFuture future; + private final AtomicLong lastProgress = new AtomicLong(0); public ProgressListener(AsyncHttpClientConfig config, boolean notifyHeaders, AsyncHandler asyncHandler, NettyResponseFuture future) { this.config = config; @@ -61,13 +63,13 @@ public void operationComplete(ChannelProgressiveFuture cf) { future.touch(); /** - * We need to make sure we aren't in the middle of an authorization process before publishing events as we will re-publish again the same event after the authorization, causing unpredictable behavior. + * We need to make sure we aren't in the middle of an authorization process before publishing events as we will re-publish again the same event after the authorization, + * causing unpredictable behavior. */ Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : config.getRealm(); boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth(); if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) { - // FIXME WTF if (notifyHeaders) { ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); } else { @@ -80,7 +82,8 @@ public void operationComplete(ChannelProgressiveFuture cf) { public void operationProgressed(ChannelProgressiveFuture f, long progress, long total) { future.touch(); if (asyncHandler instanceof ProgressAsyncHandler) { - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(total - progress, progress, total); + long lastProgressValue = lastProgress.getAndSet(progress); + ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(progress - lastProgressValue, progress, total); } } -} \ No newline at end of file +} From e2401e8e200594b0a2e23b11b728f816f08266a7 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 00:40:54 +0200 Subject: [PATCH 0084/2389] Don't forget to shutdown server2 --- .../org/asynchttpclient/async/ProxyTunnellingTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index 1b29a99f07..22e5a9764c 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.server.handler.ProxyHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.server.ssl.SslSocketConnector; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -87,6 +88,12 @@ public void setUpGlobal() throws Exception { server2.start(); log.info("Local HTTP server started successfully"); } + + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + super.tearDownGlobal(); + server2.stop(); + } @Test(groups = { "online", "default_provider" }) public void testRequestProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException { From c71c7f272a050ae70e40e312856c8cbb13d4ee50 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 00:47:30 +0200 Subject: [PATCH 0085/2389] Workaround for test thread safety issue --- .../async/HttpToHttpsRedirectTest.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java index 45fa838423..90b81dbd43 100644 --- a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java @@ -134,7 +134,15 @@ private static int getPort(URI uri) { } @Test(groups = { "standalone", "default_provider" }) - public void httpToHttpsRedirect() throws Throwable { + // FIXME find a way to make this threadsafe, other, set @Test(singleThreaded = true) + public void httpToHttpsRunAllTestsSequentially() throws Exception { + httpToHttpsRedirect(); + httpToHttpsProperConfig(); + relativeLocationUrl(); + } + + // @Test(groups = { "standalone", "default_provider" }) + public void httpToHttpsRedirect() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); @@ -153,8 +161,8 @@ public String getTargetUrl2() { return String.format("https://127.0.0.1:%d/foo/test", port2); } - @Test(groups = { "standalone", "default_provider" }) - public void httpToHttpsProperConfig() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void httpToHttpsProperConfig() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); @@ -175,8 +183,8 @@ public void httpToHttpsProperConfig() throws Throwable { } } - @Test(groups = { "standalone", "default_provider" }) - public void relativeLocationUrl() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void relativeLocationUrl() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); From 44fb968143d7cfe8a925f1198a1a4a059a4fd360 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 11:35:52 +0200 Subject: [PATCH 0086/2389] Split writeRequest --- .../listener/TransferCompletionHandler.java | 2 +- .../providers/netty4/NettyRequestSender.java | 310 ++++++++++-------- 2 files changed, 172 insertions(+), 140 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index 00962814a5..f642128d1a 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -219,7 +219,7 @@ private void fireOnThrowable(Throwable t) { public static class TransferAdapter { private final FluentCaseInsensitiveStringsMap headers; - public TransferAdapter(FluentCaseInsensitiveStringsMap headers) throws IOException { + public TransferAdapter(FluentCaseInsensitiveStringsMap headers) { this.headers = headers; } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index 49e1a35b88..06402fe576 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -182,7 +182,7 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl boolean acquiredConnection = !reclaimCache && channels.acquireConnection(asyncHandler); NettyConnectListener cl = new NettyConnectListener.Builder(config, this, request, asyncHandler, future).build(uri); - + boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost()); if (useSSl) { @@ -261,7 +261,158 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl } return cl.future(); } - + + private void sendFileBody(Channel channel, File file, NettyResponseFuture future) throws IOException { + final RandomAccessFile raf = new RandomAccessFile(file, "r"); + + try { + long fileLength = raf.length(); + + ChannelFuture writeFuture; + if (Channels.getSslHandler(channel) != null) { + writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise()); + } else { + // FIXME why not use io.netty.channel.DefaultFileRegion? + FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); + writeFuture = channel.write(region, channel.newProgressivePromise()); + } + writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + raf.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } catch (IOException ex) { + if (raf != null) { + try { + raf.close(); + } catch (IOException e) { + } + } + throw ex; + } + } + + private boolean sendStreamAndExit(Channel channel, final InputStream is, NettyResponseFuture future) throws IOException { + + if (future.getAndSetStreamWasAlreadyConsumed()) { + if (is.markSupported()) + is.reset(); + else { + LOGGER.warn("Stream has already been consumed and cannot be reset"); + return true; + } + } + + channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + is.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + + return false; + } + + public void sendBody(final Channel channel, final Body body, NettyResponseFuture future) { + Object msg; + if (Channels.getSslHandler(channel) == null && body instanceof RandomAccessBody) { + msg = new BodyFileRegion((RandomAccessBody) body); + } else { + BodyGenerator bg = future.getRequest().getBodyGenerator(); + msg = new BodyChunkedInput(body); + if (bg instanceof FeedableBodyGenerator) { + FeedableBodyGenerator.class.cast(bg).setListener(new FeedListener() { + @Override + public void onContentAdded() { + channel.pipeline().get(ChunkedWriteHandler.class).resumeTransfer(); + } + }); + } + } + ChannelFuture writeFuture = channel.write(msg, channel.newProgressivePromise()); + + final Body b = body; + writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { + public void operationComplete(ChannelProgressiveFuture cf) { + try { + b.close(); + } catch (IOException e) { + LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); + } + super.operationComplete(cf); + } + }); + channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } + + private Body computeBody(HttpRequest nettyRequest, NettyResponseFuture future) { + + if (nettyRequest.getMethod().equals(HttpMethod.CONNECT)) { + return null; + } + + HttpHeaders headers = nettyRequest.headers(); + BodyGenerator bg = future.getRequest().getBodyGenerator(); + Body body = null; + if (bg != null) { + try { + body = bg.createBody(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + long length = body.getContentLength(); + if (length >= 0) { + headers.set(HttpHeaders.Names.CONTENT_LENGTH, length); + } else { + headers.set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); + } + } else if (future.getRequest().getParts() != null) { + String contentType = headers.get(HttpHeaders.Names.CONTENT_TYPE); + String length = headers.get(HttpHeaders.Names.CONTENT_LENGTH); + body = new MultipartBody(future.getRequest().getParts(), contentType, length); + } + + return body; + } + + private void configureTransferAdapter(AsyncHandler handler, HttpRequest nettyRequest) { + FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); + for (Map.Entry entries : nettyRequest.headers()) { + h.add(entries.getKey(), entries.getValue()); + } + + TransferCompletionHandler.class.cast(handler).transferAdapter(new TransferAdapter(h)); + } + + private void scheduleReaper(NettyResponseFuture future) { + try { + future.touch(); + int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, future.getRequest()); + int schedulePeriod = requestTimeout != -1 ? (config.getIdleConnectionTimeoutInMs() != -1 ? Math.min(requestTimeout, config.getIdleConnectionTimeoutInMs()) + : requestTimeout) : config.getIdleConnectionTimeoutInMs(); + + if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { + ReaperFuture reaperFuture = new ReaperFuture(future, config, isClose, channels); + Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); + reaperFuture.setScheduledFuture(scheduledFuture); + future.setReaperFuture(reaperFuture); + } + } catch (RejectedExecutionException ex) { + channels.abort(future, ex); + } + } + protected final void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture future) { try { // If the channel is dead because it was pooled and the remote @@ -272,41 +423,15 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie } HttpRequest nettyRequest = future.getNettyRequest(); - Body body = null; - if (!nettyRequest.getMethod().equals(HttpMethod.CONNECT)) { - BodyGenerator bg = future.getRequest().getBodyGenerator(); - if (bg != null) { - try { - body = bg.createBody(); - } catch (IOException ex) { - throw new IllegalStateException(ex); - } - long length = body.getContentLength(); - if (length >= 0) { - nettyRequest.headers().set(HttpHeaders.Names.CONTENT_LENGTH, length); - } else { - nettyRequest.headers().set(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); - } - } else if (future.getRequest().getParts() != null) { - String contentType = nettyRequest.headers().get(HttpHeaders.Names.CONTENT_TYPE); - String length = nettyRequest.headers().get(HttpHeaders.Names.CONTENT_LENGTH); - body = new MultipartBody(future.getRequest().getParts(), contentType, length); - } - } - - if (future.getAsyncHandler() instanceof TransferCompletionHandler) { - - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - for (Map.Entry entries : future.getNettyRequest().headers()) { - h.add(entries.getKey(), entries.getValue()); - } + AsyncHandler handler = future.getAsyncHandler(); + Body body = computeBody(nettyRequest, future); - TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new TransferAdapter(h)); + if (handler instanceof TransferCompletionHandler) { + configureTransferAdapter(handler, nettyRequest); } // Leave it to true. - // FIXME Yeah... explain why instead of saying the same thing as the - // code + // FIXME That doesn't just leave to true, the set is always done? and what's the point of not having a is/get? if (future.getAndSetWriteHeaders(true)) { try { channel.writeAndFlush(nettyRequest, channel.newProgressivePromise()).addListener(new ProgressListener(config, true, future.getAsyncHandler(), future)); @@ -322,104 +447,25 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie } } + // FIXME OK, why? and what's the point of not having a is/get? if (future.getAndSetWriteBody(true)) { if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { - if (future.getRequest().getFile() != null) { - final File file = future.getRequest().getFile(); - long fileLength = 0; - final RandomAccessFile raf = new RandomAccessFile(file, "r"); - - try { - fileLength = raf.length(); - - ChannelFuture writeFuture; - if (Channels.getSslHandler(channel) != null) { - writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise()); - } else { - // FIXME why not use io.netty.channel.DefaultFileRegion? - FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); - writeFuture = channel.write(region, channel.newProgressivePromise()); - } - writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelProgressiveFuture cf) { - try { - raf.close(); - } catch (IOException e) { - LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); - } catch (IOException ex) { - if (raf != null) { - try { - raf.close(); - } catch (IOException e) { - } - } - throw ex; - } - } else if (future.getRequest().getStreamData() != null || future.getRequest().getBodyGenerator() instanceof InputStreamBodyGenerator) { - final InputStream is = future.getRequest().getStreamData() != null ? future.getRequest().getStreamData() : InputStreamBodyGenerator.class.cast( - future.getRequest().getBodyGenerator()).getInputStream(); - - if (future.getAndSetStreamWasAlreadyConsumed()) { - if (is.markSupported()) - is.reset(); - else { - LOGGER.warn("Stream has already been consumed and cannot be reset"); - return; - } - } - - channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelProgressiveFuture cf) { - try { - is.close(); - } catch (IOException e) { - LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + sendFileBody(channel, future.getRequest().getFile(), future); - } else if (body != null) { + } else if (future.getRequest().getStreamData() != null) { + if (sendStreamAndExit(channel, future.getRequest().getStreamData(), future)) + return; + } else if (future.getRequest().getBodyGenerator() instanceof InputStreamBodyGenerator) { + if (sendStreamAndExit(channel, InputStreamBodyGenerator.class.cast(future.getRequest().getBodyGenerator()).getInputStream(), future)) + return; - Object msg; - if (Channels.getSslHandler(channel) == null && body instanceof RandomAccessBody) { - msg = new BodyFileRegion((RandomAccessBody) body); - } else { - BodyGenerator bg = future.getRequest().getBodyGenerator(); - msg = new BodyChunkedInput(body); - if (bg instanceof FeedableBodyGenerator) { - FeedableBodyGenerator.class.cast(bg).setListener(new FeedListener() { - @Override - public void onContentAdded() { - channel.pipeline().get(ChunkedWriteHandler.class).resumeTransfer(); - } - }); - } - } - ChannelFuture writeFuture = channel.write(msg, channel.newProgressivePromise()); - - final Body b = body; - writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelProgressiveFuture cf) { - try { - b.close(); - } catch (IOException e) { - LOGGER.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); + } else if (body != null) { + sendBody(channel, body, future); } } } + } catch (Throwable ioe) { try { channel.close(); @@ -428,23 +474,9 @@ public void operationComplete(ChannelProgressiveFuture cf) { } } - try { - future.touch(); - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, future.getRequest()); - int schedulePeriod = requestTimeout != -1 ? (config.getIdleConnectionTimeoutInMs() != -1 ? Math.min(requestTimeout, config.getIdleConnectionTimeoutInMs()) - : requestTimeout) : config.getIdleConnectionTimeoutInMs(); - - if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { - ReaperFuture reaperFuture = new ReaperFuture(future, config, isClose, channels); - Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); - reaperFuture.setScheduledFuture(scheduledFuture); - future.setReaperFuture(reaperFuture); - } - } catch (RejectedExecutionException ex) { - channels.abort(future, ex); - } + scheduleReaper(future); } - + // FIXME Clean up Netty 3: replayRequest's response parameter is unused + // WTF return??? public void replayRequest(final NettyResponseFuture future, FilterContext fc, ChannelHandlerContext ctx) throws IOException { From eb92a69a604609c597f30aea46ff7fda15b9731c Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 11:44:56 +0200 Subject: [PATCH 0087/2389] Rename ReaperFuture into FutureReaper --- .../providers/netty4/{ReaperFuture.java => FutureReaper.java} | 4 ++-- .../asynchttpclient/providers/netty4/NettyRequestSender.java | 2 +- .../asynchttpclient/providers/netty4/NettyResponseFuture.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/{ReaperFuture.java => FutureReaper.java} (96%) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java similarity index 96% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java rename to providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java index fa4f5adecb..644359e52c 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ReaperFuture.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java @@ -14,7 +14,7 @@ * Because some implementation of the ThreadSchedulingService do not clean up cancel task until they try to run them, we wrap the task with the future so the when the NettyResponseFuture cancel the reaper future this wrapper will release the references to the channel and the * nettyResponseFuture immediately. Otherwise, the memory referenced this way will only be released after the request timeout period which can be arbitrary long. */ -public final class ReaperFuture implements Runnable { +public final class FutureReaper implements Runnable { private final AtomicBoolean isClose; private final Channels channels; @@ -22,7 +22,7 @@ public final class ReaperFuture implements Runnable { private NettyResponseFuture nettyResponseFuture; private AsyncHttpClientConfig config; - public ReaperFuture(NettyResponseFuture nettyResponseFuture, AsyncHttpClientConfig config, AtomicBoolean isClose, Channels channels) { + public FutureReaper(NettyResponseFuture nettyResponseFuture, AsyncHttpClientConfig config, AtomicBoolean isClose, Channels channels) { this.nettyResponseFuture = nettyResponseFuture; this.channels = channels; this.config = config; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index 06402fe576..37cc5fac3f 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -403,7 +403,7 @@ private void scheduleReaper(NettyResponseFuture future) { : requestTimeout) : config.getIdleConnectionTimeoutInMs(); if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { - ReaperFuture reaperFuture = new ReaperFuture(future, config, isClose, channels); + FutureReaper reaperFuture = new FutureReaper(future, config, isClose, channels); Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); reaperFuture.setScheduledFuture(scheduledFuture); future.setReaperFuture(reaperFuture); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java index 7eab45f3bb..ba49de0338 100755 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java @@ -69,7 +69,7 @@ public enum STATE { private HttpResponse httpResponse; private final AtomicReference exEx = new AtomicReference(); private final AtomicInteger redirectCount = new AtomicInteger(); - private volatile ReaperFuture reaperFuture; + private volatile FutureReaper reaperFuture; private final AtomicBoolean inAuth = new AtomicBoolean(false); private final AtomicBoolean statusReceived = new AtomicBoolean(false); private final AtomicLong touch = new AtomicLong(millisTime()); @@ -358,7 +358,7 @@ public int incrementAndGetCurrentRedirectCount() { return redirectCount.incrementAndGet(); } - public void setReaperFuture(ReaperFuture reaperFuture) { + public void setReaperFuture(FutureReaper reaperFuture) { cancelReaper(); this.reaperFuture = reaperFuture; } From b3a95b91101b0aa97f6af6c1908fcc74df542b6c Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 11:53:48 +0200 Subject: [PATCH 0088/2389] Use cached HttpMethod instances --- .../providers/netty4/NettyRequests.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java index d392678abc..e41b387115 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java @@ -41,15 +41,12 @@ public class NettyRequests { public static HttpRequest newNettyRequest(AsyncHttpClientConfig config, Request request, URI uri, boolean allowConnect, ProxyServer proxyServer) throws IOException { - String method = request.getMethod(); - if (allowConnect && proxyServer != null && isSecure(uri)) { - method = HttpMethod.CONNECT.toString(); - } - return construct(config, request, new HttpMethod(method), uri, proxyServer); - } - - private static HttpRequest construct(AsyncHttpClientConfig config, Request request, HttpMethod m, URI uri, ProxyServer proxyServer) throws IOException { - + HttpMethod method = null; + if (allowConnect && proxyServer != null && isSecure(uri)) + method = HttpMethod.CONNECT; + else + method = HttpMethod.valueOf(request.getMethod()); + String host = null; HttpVersion httpVersion; String requestUri; @@ -63,7 +60,7 @@ private static HttpRequest construct(AsyncHttpClientConfig config, Request reque host = AsyncHttpProviderUtils.getHost(uri); } - if (m.equals(HttpMethod.CONNECT)) { + if (method == HttpMethod.CONNECT) { httpVersion = HttpVersion.HTTP_1_0; requestUri = AsyncHttpProviderUtils.getAuthority(uri); } else { @@ -94,7 +91,7 @@ else if (uri.getRawQuery() != null) host = "127.0.0.1"; } - if (!m.equals(HttpMethod.CONNECT)) { + if (method != HttpMethod.CONNECT) { FluentCaseInsensitiveStringsMap h = request.getHeaders(); if (h != null) { for (Entry> header : h) { @@ -217,12 +214,12 @@ else if (uri.getRawQuery() != null) } boolean hasDeferredContent = false; - if (!m.equals(HttpMethod.CONNECT)) { + if (method != HttpMethod.CONNECT) { if (isNonEmpty(request.getCookies())) { headers.put(HttpHeaders.Names.COOKIE, CookieEncoder.encodeClientSide(request.getCookies(), config.isRfc6265CookieEncoding())); } - if (!m.equals(HttpMethod.HEAD) && !m.equals(HttpMethod.OPTIONS) && !m.equals(HttpMethod.TRACE)) { + if (method != HttpMethod.HEAD && method != HttpMethod.OPTIONS && method != HttpMethod.TRACE) { String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : request.getBodyEncoding(); @@ -283,11 +280,11 @@ else if (uri.getRawQuery() != null) HttpRequest nettyRequest; if (hasDeferredContent) { - nettyRequest = new DefaultHttpRequest(httpVersion, m, requestUri); + nettyRequest = new DefaultHttpRequest(httpVersion, method, requestUri); } else if (content != null) { - nettyRequest = new DefaultFullHttpRequest(httpVersion, m, requestUri, content); + nettyRequest = new DefaultFullHttpRequest(httpVersion, method, requestUri, content); } else { - nettyRequest = new DefaultFullHttpRequest(httpVersion, m, requestUri); + nettyRequest = new DefaultFullHttpRequest(httpVersion, method, requestUri); } for (Entry header : headers.entrySet()) { nettyRequest.headers().set(header.getKey(), header.getValue()); From db8c908245f022de9af5a58fca2f9caec00502dd Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 12:47:52 +0200 Subject: [PATCH 0089/2389] Minor clean up --- .../providers/netty4/Constants.java | 2 +- .../providers/netty4/FutureReaper.java | 8 +-- .../netty4/NettyAsyncHttpProvider.java | 8 +-- .../providers/netty4/NettyChannelHandler.java | 51 ++++++++----------- .../netty4/NettyConnectionsPool.java | 14 ++--- .../providers/netty4/NettyRequestSender.java | 14 ++--- 6 files changed, 46 insertions(+), 51 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java index e8f408c095..9fae1fbd2b 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java @@ -4,7 +4,7 @@ public class Constants { - // FIXME move into a state class along with isClose + // FIXME move into a state class along with closed public static final ThreadLocal IN_IO_THREAD = new ThreadLocalBoolean(); // FIXME what to do with this??? diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java index 644359e52c..974e2bc618 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java @@ -16,17 +16,17 @@ */ public final class FutureReaper implements Runnable { - private final AtomicBoolean isClose; + private final AtomicBoolean closed; private final Channels channels; private Future scheduledFuture; private NettyResponseFuture nettyResponseFuture; private AsyncHttpClientConfig config; - public FutureReaper(NettyResponseFuture nettyResponseFuture, AsyncHttpClientConfig config, AtomicBoolean isClose, Channels channels) { + public FutureReaper(NettyResponseFuture nettyResponseFuture, AsyncHttpClientConfig config, AtomicBoolean closed, Channels channels) { this.nettyResponseFuture = nettyResponseFuture; this.channels = channels; this.config = config; - this.isClose = isClose; + this.closed = closed; } public void setScheduledFuture(Future scheduledFuture) { @@ -79,7 +79,7 @@ private void expire(String message) { * @Override */ public synchronized void run() { - if (isClose.get()) { + if (closed.get()) { cancel(true); return; } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java index 28a8a7184b..a17fc9e1e5 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java @@ -37,7 +37,7 @@ public class NettyAsyncHttpProvider implements AsyncHttpProvider { private final AsyncHttpClientConfig config; private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; - private final AtomicBoolean isClose = new AtomicBoolean(false); + private final AtomicBoolean closed = new AtomicBoolean(false); private final Channels channels; private final NettyRequestSender requestSender; private final NettyChannelHandler channelHandler; @@ -53,8 +53,8 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { } channels = new Channels(config, asyncHttpProviderConfig); - requestSender = new NettyRequestSender(isClose, config, channels); - channelHandler = new NettyChannelHandler(config, requestSender, channels, isClose); + requestSender = new NettyRequestSender(closed, config, channels); + channelHandler = new NettyChannelHandler(config, requestSender, channels, closed); channels.configure(channelHandler); executeConnectAsync = asyncHttpProviderConfig.isAsyncConnect(); @@ -72,7 +72,7 @@ public String toString() { @Override public void close() { - isClose.set(true); + closed.set(true); try { channels.close(); // config.executorService().shutdown(); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index 570b53cfde..8dc1ee1fd8 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -1,21 +1,12 @@ package org.asynchttpclient.providers.netty4; -import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE; -import static io.netty.handler.codec.http.HttpResponseStatus.FOUND; -import static io.netty.handler.codec.http.HttpResponseStatus.MOVED_PERMANENTLY; -import static io.netty.handler.codec.http.HttpResponseStatus.OK; -import static io.netty.handler.codec.http.HttpResponseStatus.PROXY_AUTHENTICATION_REQUIRED; -import static io.netty.handler.codec.http.HttpResponseStatus.SEE_OTHER; -import static io.netty.handler.codec.http.HttpResponseStatus.TEMPORARY_REDIRECT; -import static io.netty.handler.codec.http.HttpResponseStatus.UNAUTHORIZED; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.HTTP; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isNTLM; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static org.asynchttpclient.providers.netty4.util.HttpUtil.*; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.channel.ChannelHandler.Sharable; import io.netty.handler.codec.PrematureChannelClosureException; import io.netty.handler.codec.http.DefaultHttpContent; import io.netty.handler.codec.http.HttpClientCodec; @@ -73,7 +64,7 @@ public class NettyChannelHandler extends ChannelInboundHandlerAdapter { private final AsyncHttpClientConfig config; private final NettyRequestSender requestSender; private final Channels channels; - private final AtomicBoolean isClose; + private final AtomicBoolean closed; private final Protocol httpProtocol = new HttpProtocol(); private final Protocol webSocketProtocol = new WebSocketProtocol(); @@ -81,7 +72,7 @@ public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requ this.config = config; this.requestSender = requestSender; this.channels = channels; - this.isClose = isClose; + this.closed = isClose; } @Override @@ -117,7 +108,7 @@ public void channelRead(final ChannelHandlerContext ctx, Object e) throws Except public void channelInactive(ChannelHandlerContext ctx) throws Exception { - if (isClose.get()) { + if (closed.get()) { return; } @@ -137,7 +128,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { callback.call(); } else if (attachment instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) attachment; + NettyResponseFuture future = NettyResponseFuture.class.cast(attachment); future.touch(); if (!config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { @@ -219,8 +210,8 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Excep } } - Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onError(ctx, e); + Protocol protocol = ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol; + protocol.onError(ctx, e); channels.closeChannel(ctx); // FIXME not really sure @@ -253,9 +244,11 @@ private boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ct private boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { - int statusCode = response.getStatus().code(); + io.netty.handler.codec.http.HttpResponseStatus status = response.getStatus(); + // int statusCode = response.getStatus().code(); boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); - if (redirectEnabled && (statusCode == MOVED_PERMANENTLY.code() || statusCode == FOUND.code() || statusCode == SEE_OTHER.code() || statusCode == TEMPORARY_REDIRECT.code())) { + boolean isRedirectStatus = status == MOVED_PERMANENTLY || status == FOUND || status == SEE_OTHER || status == TEMPORARY_REDIRECT; + if (redirectEnabled && isRedirectStatus) { if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { // We must allow 401 handling again. @@ -270,13 +263,12 @@ private boolean redirect(Request request, NettyResponseFuture future, HttpRes nBuilder.setQueryParameters(null); } - // FIXME what about 307? - if (!(statusCode < FOUND.code() || statusCode > SEE_OTHER.code()) && !(statusCode == FOUND.code() && config.isStrict302Handling())) { + // FIXME why not do that for 301 and 307 too? + if ((status == FOUND || status == SEE_OTHER) && !(status == FOUND && config.isStrict302Handling())) { nBuilder.setMethod(HttpMethod.GET.name()); } - // in case of a redirect from HTTP to HTTPS, those values - // might be different + // in case of a redirect from HTTP to HTTPS, future attributes might change final boolean initialConnectionKeepAlive = future.isKeepAlive(); final String initialPoolKey = channels.getPoolKey(future); @@ -285,8 +277,8 @@ private boolean redirect(Request request, NettyResponseFuture future, HttpRes if (request.getUrl().startsWith(WEBSOCKET)) { newUrl = newUrl.replace(HTTP, WEBSOCKET); } - LOGGER.debug("Redirecting to {}", newUrl); + for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE)) { for (Cookie c : CookieDecoder.decode(cookieStr)) { nBuilder.addOrReplaceCookie(c); @@ -310,8 +302,10 @@ public void call() throws Exception { if (HttpHeaders.isTransferEncodingChunked(response)) { // We must make sure there is no bytes left before // executing the next request. + // FIXME investigate this Channels.setDefaultAttribute(ctx, callback); } else { + // FIXME don't understand: this offers the connection to the pool, or even closes it, while the request has not been sent, right? callback.call(); } @@ -590,6 +584,7 @@ public void call() throws Exception { } else if (statusCode == CONTINUE.code()) { future.getAndSetWriteHeaders(false); future.getAndSetWriteBody(true); + // FIXME is this necessary future.setIgnoreNextContents(true); requestSender.writeRequest(ctx.channel(), config, future); return; @@ -623,7 +618,7 @@ public void call() throws Exception { return; } - } else if (statusCode == OK.code() && nettyRequest.getMethod().equals(HttpMethod.CONNECT)) { + } else if (statusCode == OK.code() && nettyRequest.getMethod() == HttpMethod.CONNECT) { LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); @@ -764,9 +759,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object if (redirect(request, future, response, ctx)) return; - io.netty.handler.codec.http.HttpResponseStatus status = io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; - - boolean validStatus = response.getStatus().equals(status); + boolean validStatus = response.getStatus() == SWITCHING_PROTOCOLS; boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null; String c = response.headers().get(HttpHeaders.Names.CONNECTION); if (c == null) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java index 16d9c43ecb..0da9e4a0cd 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java @@ -38,7 +38,7 @@ public class NettyConnectionsPool implements ConnectionsPool { private final ConcurrentHashMap> connectionsPool = new ConcurrentHashMap>(); private final ConcurrentHashMap channel2IdleChannel = new ConcurrentHashMap(); private final ConcurrentHashMap channel2CreationDate = new ConcurrentHashMap(); - private final AtomicBoolean isClosed = new AtomicBoolean(false); + private final AtomicBoolean closed = new AtomicBoolean(false); private final Timer idleConnectionDetector; private final boolean sslConnectionPoolEnabled; private final int maxTotalConnections; @@ -93,7 +93,7 @@ private class IdleChannelDetector extends TimerTask { @Override public void run() { try { - if (isClosed.get()) return; + if (closed.get()) return; if (log.isDebugEnabled()) { Set keys = connectionsPool.keySet(); @@ -155,7 +155,7 @@ public void run() { * {@inheritDoc} */ public boolean offer(String uri, Channel channel) { - if (isClosed.get()) return false; + if (closed.get()) return false; if (!sslConnectionPoolEnabled && uri.startsWith("https")) { return false; @@ -232,7 +232,7 @@ public Channel poll(String uri) { } private boolean remove(IdleChannel pooledChannel) { - if (pooledChannel == null || isClosed.get()) return false; + if (pooledChannel == null || closed.get()) return false; boolean isRemoved = false; ConcurrentLinkedQueue pooledConnectionForHost = connectionsPool.get(pooledChannel.uri); @@ -248,14 +248,14 @@ private boolean remove(IdleChannel pooledChannel) { */ public boolean removeAll(Channel channel) { channel2CreationDate.remove(channel); - return !isClosed.get() && remove(channel2IdleChannel.get(channel)); + return !closed.get() && remove(channel2IdleChannel.get(channel)); } /** * {@inheritDoc} */ public boolean canCacheConnection() { - if (!isClosed.get() && maxTotalConnections != -1 && channel2IdleChannel.size() >= maxTotalConnections) { + if (!closed.get() && maxTotalConnections != -1 && channel2IdleChannel.size() >= maxTotalConnections) { return false; } else { return true; @@ -266,7 +266,7 @@ public boolean canCacheConnection() { * {@inheritDoc} */ public void destroy() { - if (isClosed.getAndSet(true)) return; + if (closed.getAndSet(true)) return; // stop timer idleConnectionDetector.cancel(); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index 37cc5fac3f..cb0810143b 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -54,12 +54,12 @@ public class NettyRequestSender { private static final Logger LOGGER = LoggerFactory.getLogger(NettyRequestSender.class); - private final AtomicBoolean isClose; + private final AtomicBoolean closed; private final AsyncHttpClientConfig config; private final Channels channels; - public NettyRequestSender(AtomicBoolean isClose, AsyncHttpClientConfig config, Channels channels) { - this.isClose = isClose; + public NettyRequestSender(AtomicBoolean closed, AsyncHttpClientConfig config, Channels channels) { + this.closed = closed; this.config = config; this.channels = channels; } @@ -68,7 +68,7 @@ public boolean retry(Channel channel, NettyResponseFuture future) { boolean success = false; - if (!isClose.get()) { + if (!closed.get()) { channels.removeAll(channel); if (future == null) { @@ -105,6 +105,7 @@ public void execute(final Request request, final NettyResponseFuture f) t doConnect(request, f.getAsyncHandler(), f, true, true, true); } + // FIXME is this useful? Can't we do that when building the request? private final boolean validateWebSocketRequest(Request request, AsyncHandler asyncHandler) { return request.getMethod().equals(HttpMethod.GET.name()) && asyncHandler instanceof WebSocketUpgradeHandler; } @@ -112,7 +113,7 @@ private final boolean validateWebSocketRequest(Request request, AsyncHandler public ListenableFuture doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture future, boolean useCache, boolean asyncConnect, boolean reclaimCache) throws IOException { - if (isClose.get()) { + if (closed.get()) { throw new IOException("Closed"); } @@ -122,6 +123,7 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); boolean useProxy = proxyServer != null; + URI uri; if (config.isUseRawUrl()) { uri = request.getRawURI(); @@ -403,7 +405,7 @@ private void scheduleReaper(NettyResponseFuture future) { : requestTimeout) : config.getIdleConnectionTimeoutInMs(); if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { - FutureReaper reaperFuture = new FutureReaper(future, config, isClose, channels); + FutureReaper reaperFuture = new FutureReaper(future, config, closed, channels); Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); reaperFuture.setScheduledFuture(scheduledFuture); future.setReaperFuture(reaperFuture); From f16fb4fca0ac34118dc3bc6849021755daa1ba60 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 14:37:42 +0200 Subject: [PATCH 0090/2389] Fix TransferListener --- .../listener/TransferCompletionHandler.java | 68 ++++++++++++++----- .../async/TransferListenerTest.java | 4 +- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index f642128d1a..ff7417be3b 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -12,6 +12,9 @@ */ package org.asynchttpclient.listener; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.atomic.AtomicLong; + import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseBodyPart; @@ -20,13 +23,12 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; -import java.util.concurrent.ConcurrentLinkedQueue; - /** * A {@link org.asynchttpclient.AsyncHandler} that can be used to notify a set of {@link TransferListener} *

- *

+ * 
+ * + *
  * AsyncHttpClient client = new AsyncHttpClient();
  * TransferCompletionHandler tl = new TransferCompletionHandler();
  * tl.addTransferListener(new TransferListener() {
@@ -51,28 +53,32 @@
  * });
  * 

* Response response = httpClient.prepareGet("http://.../").execute(tl).get(); - *

+ *
+ * + *
*/ public class TransferCompletionHandler extends AsyncCompletionHandlerBase { private final static Logger logger = LoggerFactory.getLogger(TransferCompletionHandler.class); private final ConcurrentLinkedQueue listeners = new ConcurrentLinkedQueue(); private final boolean accumulateResponseBytes; private TransferAdapter transferAdapter; + private AtomicLong bytesTransferred = new AtomicLong(0); + private AtomicLong totalBytesToTransfer = new AtomicLong(-1); /** * Create a TransferCompletionHandler that will not accumulate bytes. The resulting {@link org.asynchttpclient.Response#getResponseBody()}, - * {@link org.asynchttpclient.Response#getResponseBodyAsStream()} and {@link Response#getResponseBodyExcerpt(int)} will - * throw an IllegalStateException if called. + * {@link org.asynchttpclient.Response#getResponseBodyAsStream()} and {@link Response#getResponseBodyExcerpt(int)} will throw an IllegalStateException if called. */ public TransferCompletionHandler() { this(false); } /** - * Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available when - * {@link org.asynchttpclient.Response#getResponseBody()} get called. The default is false. - * - * @param accumulateResponseBytes true to accumulates bytes in memory. + * Create a TransferCompletionHandler that can or cannot accumulate bytes and make it available when {@link org.asynchttpclient.Response#getResponseBody()} get called. The + * default is false. + * + * @param accumulateResponseBytes + * true to accumulates bytes in memory. */ public TransferCompletionHandler(boolean accumulateResponseBytes) { this.accumulateResponseBytes = accumulateResponseBytes; @@ -80,8 +86,9 @@ public TransferCompletionHandler(boolean accumulateResponseBytes) { /** * Add a {@link TransferListener} - * - * @param t a {@link TransferListener} + * + * @param t + * a {@link TransferListener} * @return this */ public TransferCompletionHandler addTransferListener(TransferListener t) { @@ -91,8 +98,9 @@ public TransferCompletionHandler addTransferListener(TransferListener t) { /** * Remove a {@link TransferListener} - * - * @param t a {@link TransferListener} + * + * @param t + * a {@link TransferListener} * @return this */ public TransferCompletionHandler removeTransferListener(TransferListener t) { @@ -102,8 +110,9 @@ public TransferCompletionHandler removeTransferListener(TransferListener t) { /** * Associate a {@link TransferCompletionHandler.TransferAdapter} with this listener. - * - * @param transferAdapter {@link TransferAdapter} + * + * @param transferAdapter + * {@link TransferAdapter} */ public void transferAdapter(TransferAdapter transferAdapter) { this.transferAdapter = transferAdapter; @@ -127,6 +136,10 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep @Override public Response onCompleted(Response response) throws Exception { + if (bytesTransferred.get() > 0L) { + // onContentWriteCompleted hasn't been notified, it would have been set to -1L (async race) + onContentWriteCompleted(); + } fireOnEnd(); return response; } @@ -141,16 +154,35 @@ public STATE onHeaderWriteCompleted() { @Override public STATE onContentWriteCompleted() { + // onContentWriteProgress might not have been called on last write + long transferred = bytesTransferred.getAndSet(-1L); + long expected = totalBytesToTransfer.get(); + + if (expected <= 0L && transferAdapter != null) { + FluentCaseInsensitiveStringsMap headers = transferAdapter.getHeaders(); + String contentLengthString = headers.getFirstValue("Content-Length"); + if (contentLengthString != null) + expected = Long.valueOf(contentLengthString); + } + + if (expected > 0L && transferred != expected) { + fireOnBytesSent(expected - transferred, expected, expected); + } + return STATE.CONTINUE; } @Override public STATE onContentWriteProgress(long amount, long current, long total) { + bytesTransferred.addAndGet(amount); + + if (total > 0L) + totalBytesToTransfer.set(total); + fireOnBytesSent(amount, current, total); return STATE.CONTINUE; } - @Override public void onThrowable(Throwable t) { fireOnThrowable(t); diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 61561a4fb4..42961acca6 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -140,7 +140,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void basicPutTest() throws Throwable { + public void basicPutFileTest() throws Throwable { final AtomicReference throwable = new AtomicReference(); final AtomicReference hSent = new AtomicReference(); final AtomicReference hRead = new AtomicReference(); @@ -204,7 +204,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void basicPutBodyTest() throws Throwable { + public void basicPutFileBodyGeneratorTest() throws Throwable { AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicReference throwable = new AtomicReference(); From b19345681ab67bd8032dda6907e062c56463582a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 16:14:30 +0200 Subject: [PATCH 0091/2389] Enabling Netty4 module, as all tests are green!!! --- providers/pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/providers/pom.xml b/providers/pom.xml index 0fb9d7957e..9a7178b576 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -46,9 +46,7 @@ grizzly netty - From 04c951469cef00ad957932871b1d51738e1ccc8c Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 18:10:13 +0200 Subject: [PATCH 0092/2389] Let one pass an external EventLoop --- .../AsyncHttpClientConfig.java | 2 - .../netty4/AdditionalChannelInitializer.java | 8 --- .../providers/netty4/Channels.java | 52 ++++++++----------- .../netty4/NettyAsyncHttpProviderConfig.java | 20 ++----- .../NettyAsyncProviderPipelineTest.java | 1 + 5 files changed, 29 insertions(+), 54 deletions(-) delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 35f7f1881d..104137ea0b 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -26,7 +26,6 @@ import javax.net.ssl.SSLEngine; import java.io.IOException; import java.io.InputStream; -import java.security.GeneralSecurityException; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -35,7 +34,6 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; /** * Configuration class to use with a {@link AsyncHttpClient}. System property can be also used to configure this diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java deleted file mode 100644 index 94fff93730..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/AdditionalChannelInitializer.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -import io.netty.channel.Channel; - -public interface AdditionalChannelInitializer { - - void initChannel(Channel ch) throws Exception; -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index a6805581af..c82980d7df 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -68,8 +68,7 @@ public class Channels { private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; private EventLoopGroup eventLoopGroup; - private final Class socketChannelFactory; - private final boolean allowReleaseSocketChannelFactory; + private final boolean allowReleaseEventLoopGroup; private final Bootstrap plainBootstrap; private final Bootstrap secureBootstrap; @@ -97,39 +96,34 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig this.config = config; this.asyncHttpProviderConfig = asyncHttpProviderConfig; + Class socketChannelClass = null; if (asyncHttpProviderConfig.isUseBlockingIO()) { - socketChannelFactory = OioSocketChannel.class; - this.allowReleaseSocketChannelFactory = true; + socketChannelClass = OioSocketChannel.class; + eventLoopGroup = new OioEventLoopGroup(); + allowReleaseEventLoopGroup = true; + } else { - // check if external NioClientSocketChannelFactory is defined - Class scf = asyncHttpProviderConfig.getSocketChannel(); - if (scf != null) { - this.socketChannelFactory = scf; + // check if external EventLoopGroup is defined + eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup(); + if (eventLoopGroup instanceof OioEventLoopGroup) { + socketChannelClass = OioSocketChannel.class; + allowReleaseEventLoopGroup = false; + + } else if (eventLoopGroup instanceof NioEventLoopGroup) { + socketChannelClass = NioSocketChannel.class; + allowReleaseEventLoopGroup = false; - // cannot allow releasing shared channel factory - this.allowReleaseSocketChannelFactory = false; } else { - socketChannelFactory = NioSocketChannel.class; - eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup(); - if (eventLoopGroup == null) { - if (socketChannelFactory == OioSocketChannel.class) { - eventLoopGroup = new OioEventLoopGroup(); - } else if (socketChannelFactory == NioSocketChannel.class) { - eventLoopGroup = new NioEventLoopGroup(); - } else { - throw new IllegalArgumentException("No set event loop compatbile with socket channel " + scf); - } - } - int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); - LOGGER.debug("Number of application's worker threads is {}", numWorkers); - this.allowReleaseSocketChannelFactory = true; + socketChannelClass = NioSocketChannel.class; + eventLoopGroup = new NioEventLoopGroup(); + allowReleaseEventLoopGroup = true; } } - plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); - secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); - webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); - secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup); + plainBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); + secureBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); + webSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); + secureWebSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); // This is dangerous as we can't catch a wrong typed ConnectionsPool ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); @@ -247,7 +241,7 @@ public void close() { } } openChannels.close(); - if (this.allowReleaseSocketChannelFactory) { + if (this.allowReleaseEventLoopGroup) { eventLoopGroup.shutdownGracefully(); } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java index d008d6b825..be8aa75d44 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java @@ -17,10 +17,8 @@ package org.asynchttpclient.providers.netty4; import io.netty.channel.Channel; -import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; -import io.netty.channel.socket.SocketChannel; import java.util.HashMap; import java.util.Map; @@ -46,11 +44,6 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig socketChannel; private AdditionalChannelInitializer httpAdditionalChannelInitializer; private AdditionalChannelInitializer wsAdditionalChannelInitializer; @@ -155,14 +148,6 @@ public void setUseBlockingIO(boolean useBlockingIO) { this.useBlockingIO = useBlockingIO; } - public Class getSocketChannel() { - return socketChannel; - } - - public void setSocketChannel(Class socketChannel) { - this.socketChannel = socketChannel; - } - public EventLoopGroup getEventLoopGroup() { return eventLoopGroup; } @@ -234,4 +219,9 @@ public AdditionalChannelInitializer getWssAdditionalChannelInitializer() { public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssAdditionalChannelInitializer) { this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer; } + + public static interface AdditionalChannelInitializer { + + void initChannel(Channel ch) throws Exception; + } } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java index d4b2a959a1..64aba79512 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java @@ -28,6 +28,7 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; +import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig.AdditionalChannelInitializer; import org.testng.Assert; import org.testng.annotations.Test; From 7d52ef43b8ef72d57d8b98fecf53010819c880cc Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 18:42:20 +0200 Subject: [PATCH 0093/2389] Minor clean up --- .../asynchttpclient/HttpResponseBodyPart.java | 20 +++++++++---------- .../providers/netty4/Channels.java | 2 +- .../providers/netty4/NettyChannelHandler.java | 7 ++----- .../providers/netty4/ResponseBodyPart.java | 13 ++++++------ 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java index 2a8655e2d0..e7f350e439 100644 --- a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java +++ b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java @@ -33,23 +33,23 @@ public HttpResponseBodyPart(URI uri, AsyncHttpProvider provider) { /** * Return length of this part in bytes. * - * @since 1.8.0 + * @since 2.0.0 */ - abstract public int length(); + public abstract int length(); /** * Return the response body's part bytes received. * * @return the response body's part bytes received. */ - abstract public byte[] getBodyPartBytes(); + public abstract byte[] getBodyPartBytes(); /** * Method for accessing contents of this part via stream. * - * @since 1.8.0 + * @since 2.0.0 */ - abstract public InputStream readBodyPartBytes(); + public abstract InputStream readBodyPartBytes(); /** * Write the available bytes to the {@link java.io.OutputStream} @@ -58,7 +58,7 @@ public HttpResponseBodyPart(URI uri, AsyncHttpProvider provider) { * @return The number of bytes written * @throws IOException */ - abstract public int writeTo(OutputStream outputStream) throws IOException; + public abstract int writeTo(OutputStream outputStream) throws IOException; /** * Return a {@link ByteBuffer} that wraps the actual bytes read from the response's chunk. The {@link ByteBuffer} @@ -66,27 +66,27 @@ public HttpResponseBodyPart(URI uri, AsyncHttpProvider provider) { * * @return {@link ByteBuffer} */ - abstract public ByteBuffer getBodyByteBuffer(); + public abstract ByteBuffer getBodyByteBuffer(); /** * Return true if this is the last part. * * @return true if this is the last part. */ - abstract public boolean isLast(); + public abstract boolean isLast(); /** * Close the underlying connection once the processing has completed. Invoking that method means the * underlying TCP connection will be closed as soon as the processing of the response is completed. That * means the underlying connection will never get pooled. */ - abstract public void markUnderlyingConnectionAsClosed(); + public abstract void markUnderlyingConnectionAsClosed(); /** * Return true of the underlying connection will be closed once the response has been fully processed. * * @return true of the underlying connection will be closed once the response has been fully processed. */ - abstract public boolean closeUnderlyingConnection(); + public abstract boolean closeUnderlyingConnection(); } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index c82980d7df..7f866c7924 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -241,7 +241,7 @@ public void close() { } } openChannels.close(); - if (this.allowReleaseEventLoopGroup) { + if (allowReleaseEventLoopGroup) { eventLoopGroup.shutdownGracefully(); } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index 8dc1ee1fd8..548edc867f 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -2,13 +2,11 @@ import static io.netty.handler.codec.http.HttpResponseStatus.*; import static org.asynchttpclient.providers.netty4.util.HttpUtil.*; -import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.codec.PrematureChannelClosureException; -import io.netty.handler.codec.http.DefaultHttpContent; import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpHeaders; @@ -673,7 +671,7 @@ public void call() throws Exception { if (!interrupt && chunk.content().readableBytes() > 0) { // FIXME why - interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk)); + interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); } if (interrupt || last) { @@ -801,8 +799,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object } if (frame.content() != null && frame.content().readableBytes() > 0) { - HttpContent webSocketChunk = new DefaultHttpContent(Unpooled.wrappedBuffer(frame.content())); - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), webSocketChunk); + ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); h.onBodyPartReceived(rp); NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java index 7f0f8ca7a4..2206317f25 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java @@ -15,8 +15,7 @@ */ package org.asynchttpclient.providers.netty4; -import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.LastHttpContent; +import io.netty.buffer.ByteBuf; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -34,14 +33,14 @@ public class ResponseBodyPart extends HttpResponseBodyPart { private final byte[] bytes; - private final boolean isLast; + private final boolean last; private boolean closeConnection = false; // FIXME unused AsyncHttpProvider provider - public ResponseBodyPart(URI uri, HttpContent chunk) { + public ResponseBodyPart(URI uri, ByteBuf buf, boolean last) { super(uri, null); - bytes = ByteBufUtil.byteBuf2bytes(chunk.content()); - isLast = chunk instanceof LastHttpContent; + bytes = ByteBufUtil.byteBuf2bytes(buf); + this.last = last; } /** @@ -80,7 +79,7 @@ public ByteBuffer getBodyByteBuffer() { */ @Override public boolean isLast() { - return isLast; + return last; } /** From a2211ded60856461d47a54733a826ba136202fdb Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 4 Sep 2013 10:55:23 -0700 Subject: [PATCH 0094/2389] Two fixes: - Test bug: server-side handler assuming the PUT content would arrive in a single chunk and ignored the return result from the read() call. - Grizzly bug: TransferListeners were only notified of content when updated and not when completed. So the last delta was missing. --- .../async/TransferListenerTest.java | 11 +++-- .../grizzly/bodyhandler/FileBodyHandler.java | 41 ++++++++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 42961acca6..91a3a534f1 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -70,8 +70,13 @@ public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequ } byte[] bytes = new byte[size]; if (bytes.length > 0) { - httpRequest.getInputStream().read(bytes); - httpResponse.getOutputStream().write(bytes); + int read = 0; + while (read != -1) { + read = httpRequest.getInputStream().read(bytes); + if (read > 0) { + httpResponse.getOutputStream().write(bytes, 0, read); + } + } } httpResponse.setStatus(200); @@ -129,7 +134,7 @@ public void onThrowable(Throwable t) { assertEquals(response.getStatusCode(), 200); assertNotNull(hRead.get()); assertNotNull(hSent.get()); - assertNotNull(bb.get()); + assertNull(bb.get()); assertNull(throwable.get()); } catch (IOException ex) { fail("Should have timed out"); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java index cb26e1ab0f..8029d7f80c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java @@ -92,20 +92,12 @@ public boolean doHandle(final FilterChainContext ctx, @Override public void updated(WriteResult result) { - final AsyncHandler handler = context.getHandler(); - if (handler != null) { - if (handler instanceof TransferCompletionHandler) { - // WriteResult keeps a track of the total amount written, - // so we need to calculate the delta ourselves. - final long resultTotal = result.getWrittenSize(); - final long written = resultTotal - context.getTotalBodyWritten().get(); - final long total = context.getTotalBodyWritten().addAndGet(written); - ((TransferCompletionHandler) handler).onContentWriteProgress( - written, - total, - requestPacket.getContentLength()); - } - } + notifyHandlerIfNeeded(context, requestPacket, result); + } + + @Override + public void completed(WriteResult result) { + notifyHandlerIfNeeded(context, requestPacket, result); } }); } @@ -117,6 +109,27 @@ public void updated(WriteResult result) { // --------------------------------------------------------- Private Methods + private static void notifyHandlerIfNeeded(final HttpTransactionContext context, + final HttpRequestPacket requestPacket, + final WriteResult writeResult) { + final AsyncHandler handler = context.getHandler(); + if (handler != null) { + if (handler instanceof TransferCompletionHandler) { + // WriteResult keeps a track of the total amount written, + // so we need to calculate the delta ourselves. + final long resultTotal = writeResult.getWrittenSize(); + final long written = + (resultTotal - context.getTotalBodyWritten().get()); + final long total = context.getTotalBodyWritten().addAndGet(written); + ((TransferCompletionHandler) handler).onContentWriteProgress( + written, + total, + requestPacket.getContentLength()); + } + } + } + + private static boolean configSendFileSupport() { return !((System.getProperty("os.name").equalsIgnoreCase("linux") && !linuxSendFileSupported()) From 87473b044071bda33e65c0d4ab8dea6ecb171ab2 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 4 Sep 2013 21:31:34 +0200 Subject: [PATCH 0095/2389] Use getHostName instead of getHostString for JDK6 compat --- api/src/main/java/org/asynchttpclient/util/ProxyUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java index 5331dfa7d1..ef0bfbc017 100644 --- a/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/ProxyUtils.java @@ -208,7 +208,7 @@ public ProxyServer select(URI uri) { log.warn("Don't know how to connect to address " + proxy.address()); } else { InetSocketAddress address = (InetSocketAddress) proxy.address(); - return new ProxyServer(Protocol.HTTP, address.getHostString(), address.getPort()); + return new ProxyServer(Protocol.HTTP, address.getHostName(), address.getPort()); } case DIRECT: return null; From 586ed3e8bef7661babe2f121cf9cad0b52c87326 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 00:38:51 +0200 Subject: [PATCH 0096/2389] Status instances are not cached by the codec (message might change) --- .../providers/netty4/NettyChannelHandler.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index 548edc867f..c78e3aef06 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -243,9 +243,8 @@ private boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ct private boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { io.netty.handler.codec.http.HttpResponseStatus status = response.getStatus(); - // int statusCode = response.getStatus().code(); boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); - boolean isRedirectStatus = status == MOVED_PERMANENTLY || status == FOUND || status == SEE_OTHER || status == TEMPORARY_REDIRECT; + boolean isRedirectStatus = status.equals(MOVED_PERMANENTLY) || status.equals(FOUND) || status.equals(SEE_OTHER) || status.equals(TEMPORARY_REDIRECT); if (redirectEnabled && isRedirectStatus) { if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { @@ -262,7 +261,7 @@ private boolean redirect(Request request, NettyResponseFuture future, HttpRes } // FIXME why not do that for 301 and 307 too? - if ((status == FOUND || status == SEE_OTHER) && !(status == FOUND && config.isStrict302Handling())) { + if ((status.equals(FOUND) || status.equals(SEE_OTHER)) && !(status.equals(FOUND) && config.isStrict302Handling())) { nBuilder.setMethod(HttpMethod.GET.name()); } @@ -757,7 +756,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object if (redirect(request, future, response, ctx)) return; - boolean validStatus = response.getStatus() == SWITCHING_PROTOCOLS; + boolean validStatus = response.getStatus().equals(SWITCHING_PROTOCOLS); boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null; String c = response.headers().get(HttpHeaders.Names.CONNECTION); if (c == null) { From c3288fcc8da92d357010d8f7f094884c8e11a75c Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 00:41:32 +0200 Subject: [PATCH 0097/2389] Raise memory leak message to error --- .../org/asynchttpclient/AsyncHttpClient.java | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index bc5c170d7d..7097322940 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -214,26 +214,25 @@ public AsyncHttpClient(AsyncHttpClientConfig config) { /** * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and - * and a {@link AsyncHttpProvider}. + * and a AsyncHttpProvider class' name. * - * @param config a {@link AsyncHttpClientConfig} - * @param httpProvider a {@link AsyncHttpProvider} + * @param config a {@link AsyncHttpClientConfig} + * @param providerClass a {@link AsyncHttpProvider} */ - public AsyncHttpClient(AsyncHttpProvider httpProvider, AsyncHttpClientConfig config) { - this.config = config; - this.httpProvider = httpProvider; + public AsyncHttpClient(String providerClass, AsyncHttpClientConfig config) { + this(loadProvider(providerClass, config), new AsyncHttpClientConfig.Builder().build()); } /** * Create a new HTTP Asynchronous Client using a {@link AsyncHttpClientConfig} configuration and - * and a AsyncHttpProvider class' name. + * and a {@link AsyncHttpProvider}. * - * @param config a {@link AsyncHttpClientConfig} - * @param providerClass a {@link AsyncHttpProvider} + * @param config a {@link AsyncHttpClientConfig} + * @param httpProvider a {@link AsyncHttpProvider} */ - public AsyncHttpClient(String providerClass, AsyncHttpClientConfig config) { - this.config = new AsyncHttpClientConfig.Builder().build(); - this.httpProvider = loadProvider(providerClass, config); + public AsyncHttpClient(AsyncHttpProvider httpProvider, AsyncHttpClientConfig config) { + this.config = config; + this.httpProvider = httpProvider; } public class BoundRequestBuilder extends RequestBuilderBase { @@ -405,7 +404,7 @@ public void run() { protected void finalize() throws Throwable { try { if (!isClosed.get()) { - logger.debug("AsyncHttpClient.close() hasn't been invoked, which may produce file descriptor leaks"); + logger.error("AsyncHttpClient.close() hasn't been invoked, which may produce file descriptor leaks"); } } finally { super.finalize(); From 8c3deddb81cb1671b5f513e3cdeabb76c03aaf5a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 00:52:33 +0200 Subject: [PATCH 0098/2389] Shouldn't be closing client twice --- .../java/org/asynchttpclient/async/AsyncProvidersBasicTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 8b412ba97d..f400e45cba 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1659,7 +1659,6 @@ public void bodyAsByteTest() throws Throwable { assertEquals(r.getStatusCode(), 200); assertEquals(r.getResponseBodyAsBytes(), new byte[] {}); - client.close(); } finally { client.close(); } From 3259e0c9213d1a7c91fd9716b6d0e9b48849f3a5 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 00:57:06 +0200 Subject: [PATCH 0099/2389] Minor clean up --- .../async/AsyncProvidersBasicTest.java | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index f400e45cba..11651cf430 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1542,14 +1542,7 @@ public void idleRequestTimeoutTest() throws Exception { long t1 = millisTime(); try { - c.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute(new AsyncHandlerAdapter() { - - /* @Override */ - public void onThrowable(Throwable t) { - // t.printStackTrace(); - } - - }).get(); + c.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); Assert.fail(); } catch (Throwable ex) { final long elapsedTime = millisTime() - t1; @@ -1602,9 +1595,7 @@ public void onThrowable(Throwable t) { public void getShouldAllowBody() throws IllegalArgumentException, IOException { AsyncHttpClient c = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder builder = c.prepareGet(getTargetUrl()); - builder.setBody("Boo!"); - builder.execute(); + c.prepareGet(getTargetUrl()).setBody("Boo!").execute(); } finally { c.close(); } @@ -1614,9 +1605,7 @@ public void getShouldAllowBody() throws IllegalArgumentException, IOException { public void headShouldNotAllowBody() throws IllegalArgumentException, IOException { AsyncHttpClient c = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder builder = c.prepareHead(getTargetUrl()); - builder.setBody("Boo!"); - builder.execute(); + c.prepareHead(getTargetUrl()).setBody("Boo!").execute(); } finally { c.close(); } @@ -1630,8 +1619,7 @@ protected String getBrokenTargetUrl() { public void invalidUri() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder builder = c.prepareGet(getBrokenTargetUrl()); - Response r = c.executeRequest(builder.build()).get(); + Response r = c.executeRequest(c.prepareGet(getBrokenTargetUrl()).build()).get(); assertEquals(200, r.getStatusCode()); } finally { c.close(); @@ -1642,8 +1630,7 @@ public void invalidUri() throws Exception { public void asyncHttpClientConfigBeanTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test")); try { - AsyncHttpClient.BoundRequestBuilder builder = c.prepareGet(getTargetUrl()); - Response r = c.executeRequest(builder.build()).get(); + Response r = c.executeRequest(c.prepareGet(getTargetUrl()).build()).get(); assertEquals(200, r.getStatusCode()); } finally { c.close(); @@ -1655,10 +1642,8 @@ public void bodyAsByteTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response r = client.prepareGet(getTargetUrl()).execute().get(); - assertEquals(r.getStatusCode(), 200); assertEquals(r.getResponseBodyAsBytes(), new byte[] {}); - } finally { client.close(); } @@ -1669,7 +1654,6 @@ public void mirrorByteTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response r = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); - assertEquals(r.getStatusCode(), 200); assertEquals(new String(r.getResponseBodyAsBytes(), "UTF-8"), "MIRROR"); } finally { From 3a3c43bd64b678c0ca15d0030cc036826c3e22a8 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 01:12:55 +0200 Subject: [PATCH 0100/2389] Don't derive --- .../org/asynchttpclient/async/SimpleAsyncHttpClientTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index d5849b1dad..d8b8bedcdb 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -219,7 +219,7 @@ public void onBytesReceived(String url, long amount, long current, long total) { public void testNullUrl() throws Exception { SimpleAsyncHttpClient client = null; try { - client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build().derive().build(); + client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).build(); assertTrue(true); } catch (NullPointerException ex) { fail(); From fb78a3f316ca0d0a11269afe4cc975bec49ef870 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 01:50:25 +0200 Subject: [PATCH 0101/2389] Upgrade Jetty --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8587006ded..f7601bc353 100644 --- a/pom.xml +++ b/pom.xml @@ -530,15 +530,14 @@ http://oss.sonatype.org/content/repositories/snapshots - true - + true 1.6 1.6 2.16 1.0.13 1.2.17 6.8.5 - 8.1.1.v20120215 + 8.1.12.v20130726 6.0.29 2.4 1.3 From 9f118927895f9c461e1a8071a630ae6021d42515 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 13:50:38 +0200 Subject: [PATCH 0102/2389] Properly initialize AsyncHttpClientConfigBean.ioThreadMultiplier --- .../java/org/asynchttpclient/AsyncHttpClientConfigBean.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java index 9a7d75bf47..46eb9fe311 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java @@ -54,7 +54,8 @@ void configureDefaults() { maxDefaultRedirects = Integer.getInteger(ASYNC_CLIENT + "defaultMaxRedirects", 5); compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled"); userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "AsyncHttpClient/" + AHC_VERSION); - + ioThreadMultiplier = Integer.getInteger(ASYNC_CLIENT + "ioThreadMultiplier", 8); + boolean useProxySelector = Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector"); boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties"); if (useProxySelector) { From b9f1ca733d05530f19d66c4afbb9ee0aeafd05d1 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 13:51:02 +0200 Subject: [PATCH 0103/2389] Don't make standalone tests target http://foo.com --- .../async/AsyncProvidersBasicTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 11651cf430..4d51edc0d9 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -68,9 +68,9 @@ public abstract class AsyncProvidersBasicTest extends AbstractBasicTest { public void asyncProviderEncodingTest() throws Throwable { AsyncHttpClient p = getAsyncHttpClient(null); try { - Request request = new RequestBuilder("GET").setUrl("http://foo.com/foo.html?q=+%20x").build(); + Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "?q=+%20x").build(); String requestUrl = request.getUrl(); - Assert.assertEquals(requestUrl, "http://foo.com/foo.html?q=%20%20x"); + Assert.assertEquals(requestUrl, getTargetUrl() + "?q=%20%20x"); Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { @Override public String onCompleted(Response response) throws Exception { @@ -85,7 +85,7 @@ public void onThrowable(Throwable t) { }); String url = responseFuture.get(); - Assert.assertEquals(url, "http://foo.com/foo.html?q=%20%20x"); + Assert.assertEquals(url, getTargetUrl() + "?q=%20%20x"); } finally { p.close(); } @@ -95,7 +95,7 @@ public void onThrowable(Throwable t) { public void asyncProviderEncodingTest2() throws Throwable { AsyncHttpClient p = getAsyncHttpClient(null); try { - Request request = new RequestBuilder("GET").setUrl("http://foo.com/foo.html").addQueryParameter("q", "a b").build(); + Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "").addQueryParameter("q", "a b").build(); Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { @Override @@ -111,7 +111,7 @@ public void onThrowable(Throwable t) { }); String url = responseFuture.get(); - Assert.assertEquals(url, "http://foo.com/foo.html?q=a%20b"); + Assert.assertEquals(url, getTargetUrl() + "?q=a%20b"); } finally { p.close(); } @@ -121,7 +121,7 @@ public void onThrowable(Throwable t) { public void emptyRequestURI() throws Throwable { AsyncHttpClient p = getAsyncHttpClient(null); try { - Request request = new RequestBuilder("GET").setUrl("http://foo.com/").build(); + Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { @Override @@ -137,7 +137,7 @@ public void onThrowable(Throwable t) { }); String url = responseFuture.get(); - Assert.assertEquals(url, "http://foo.com/"); + Assert.assertEquals(url, getTargetUrl()); } finally { p.close(); } From 8eb212be82587eaf2979b2e8e1a0787f5f60b86a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 15:12:11 +0200 Subject: [PATCH 0104/2389] Note to remove hack --- .../org/asynchttpclient/providers/netty4/ProgressListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java index 37f6c68bf0..10739dac52 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java @@ -28,6 +28,7 @@ public ProgressListener(AsyncHttpClientConfig config, boolean notifyHeaders, Asy @Override public void operationComplete(ChannelProgressiveFuture cf) { + // FIXME remove this with next 4.0.9: https://github.com/netty/netty/issues/1809 // The write operation failed. If the channel was cached, it means it got asynchronously closed. // Let's retry a second time. Throwable cause = cf.cause(); From 9cff47c432c55709a4d1cd644f88e0817e855304 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 17:06:49 +0200 Subject: [PATCH 0105/2389] Test clean up --- .../async/AbstractBasicHttpsTest.java | 61 +++++++ .../async/AbstractBasicTest.java | 146 ++++++++++------ .../async/AsyncProvidersBasicTest.java | 1 + .../async/AsyncStreamHandlerTest.java | 5 +- .../async/AuthTimeoutTest.java | 12 +- .../asynchttpclient/async/BasicAuthTest.java | 110 ++++++------ .../asynchttpclient/async/BasicHttpsTest.java | 155 +++++------------ .../asynchttpclient/async/BodyChunkTest.java | 3 +- .../asynchttpclient/async/ChunkingTest.java | 110 ++---------- .../async/ConnectionPoolTest.java | 1 - .../asynchttpclient/async/DigestAuthTest.java | 16 +- .../async/Expect100ContinueTest.java | 1 - .../async/FilePartLargeFileTest.java | 82 ++------- .../async/FollowingThreadTest.java | 5 +- .../async/HostnameVerifierTest.java | 162 ++++-------------- .../async/HttpToHttpsRedirectTest.java | 59 ++----- .../async/IdleStateHandlerTest.java | 30 ++-- .../async/MaxConnectionsInThreads.java | 1 + .../async/MultipartUploadTest.java | 116 ++++++------- .../async/MultipleHeaderTest.java | 84 ++++----- .../async/NonAsciiContentLengthTest.java | 7 +- .../async/PerRequestRelative302Test.java | 18 +- .../org/asynchttpclient/async/ProxyTest.java | 45 +++-- .../async/ProxyTunnellingTest.java | 2 +- .../async/PutLargeFileTest.java | 33 ---- .../async/QueryParametersTest.java | 1 - .../async/RedirectConnectionUsageTest.java | 65 +++---- .../async/SimpleAsyncHttpClientTest.java | 1 - .../async/TransferListenerTest.java | 38 +--- .../async/WebDavBasicTest.java | 14 +- .../ByteArrayBodyGeneratorTest.java | 1 - ...PropertiesBasedResumableProcesserTest.java | 1 - .../asynchttpclient/util/ProxyUtilsTest.java | 7 +- .../util/TestUTF8UrlCodec.java | 8 +- .../websocket/AbstractBasicTest.java | 86 ++++------ .../websocket/CloseCodeReasonMessageTest.java | 6 +- .../websocket/RedirectTest.java | 52 +++--- .../websocket/TextMessageTest.java | 3 +- .../grizzly/GrizzlyBasicHttpsTest.java | 5 - .../NettyRequestThrottleTimeoutTest.java | 23 ++- 40 files changed, 613 insertions(+), 963 deletions(-) create mode 100644 api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java diff --git a/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java new file mode 100644 index 0000000000..3210dc9916 --- /dev/null +++ b/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2010 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.async; + +import java.io.File; +import java.net.URL; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ssl.SslSocketConnector; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeClass; + +public abstract class AbstractBasicHttpsTest extends AbstractBasicTest { + protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractBasicHttpsTest.class); + protected Server server; + protected int port1; + protected int port2; + + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { + server = new Server(); + port1 = findFreePort(); + + ClassLoader cl = getClass().getClassLoader(); + + URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); + String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); + LOGGER.info("SSL keystore path: {}", keyStoreFile); + SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile); + sslContextFactory.setKeyStorePassword("changeit"); + + String trustStoreFile = new File(cl.getResource("ssltest-cacerts.jks").toURI()).getAbsolutePath(); + LOGGER.info("SSL certs path: {}", trustStoreFile); + sslContextFactory.setTrustStore(trustStoreFile); + sslContextFactory.setTrustStorePassword("changeit"); + + SslSocketConnector connector = new SslSocketConnector(sslContextFactory); + connector.setHost("127.0.0.1"); + connector.setPort(port1); + server.addConnector(connector); + + server.setHandler(configureHandler()); + server.start(); + LOGGER.info("Local HTTP server started successfully"); + } +} diff --git a/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java index 3e6c368f73..73a1d4c6d6 100644 --- a/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java @@ -15,6 +15,20 @@ */ package org.asynchttpclient.async; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.ServerSocket; +import java.nio.charset.Charset; +import java.util.Enumeration; +import java.util.UUID; + +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FileUtils; import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; @@ -34,13 +48,6 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.ServerSocket; -import java.util.Enumeration; - public abstract class AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); protected Server server; @@ -48,14 +55,49 @@ public abstract class AbstractBasicTest { protected int port2; public final static int TIMEOUT = 30; + public static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); + public static final byte[] PATTERN_BYTES = "FooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQix".getBytes(Charset.forName("UTF-16")); + public static final File LARGE_IMAGE_FILE; + public static byte[] LARGE_IMAGE_BYTES; + public static final File SIMPLE_TEXT_FILE; + + static { + try { + TMP.mkdirs(); + TMP.deleteOnExit(); + LARGE_IMAGE_FILE = new File(AbstractBasicTest.class.getClassLoader().getResource("300k.png").toURI()); + LARGE_IMAGE_BYTES = FileUtils.readFileToByteArray(LARGE_IMAGE_FILE); + SIMPLE_TEXT_FILE = new File(AbstractBasicTest.class.getClassLoader().getResource("SimpleTextFile.txt").toURI()); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + + public static File createTempFile(byte[] pattern, int repeat) throws IOException { + File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); + tmpFile.deleteOnExit(); + FileOutputStream out = null; + try { + out = new FileOutputStream(tmpFile); + for (int i = 0; i < repeat; i++) { + out.write(pattern); + } + + long expectedFileSize = PATTERN_BYTES.length * repeat; + Assert.assertEquals(expectedFileSize, tmpFile.length(), "Invalid file length"); + + return tmpFile; + } finally { + if (out != null) { + out.close(); + } + } + } public static class EchoHandler extends AbstractHandler { - /* @Override */ - public void handle(String pathInContext, - Request request, - HttpServletRequest httpRequest, - HttpServletResponse httpResponse) throws IOException, ServletException { + @Override + public void handle(String pathInContext, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { if (httpRequest.getHeader("X-HEAD") != null) { httpResponse.setContentLength(1); @@ -68,8 +110,9 @@ public void handle(String pathInContext, } if (request.getMethod().equalsIgnoreCase("OPTIONS")) { - httpResponse.addHeader("Allow","GET,HEAD,POST,OPTIONS,TRACE"); - }; + httpResponse.addHeader("Allow", "GET,HEAD,POST,OPTIONS,TRACE"); + } + ; Enumeration e = httpRequest.getHeaderNames(); String param; @@ -110,9 +153,9 @@ public void handle(String pathInContext, httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort()); - javax.servlet.http.Cookie[] cs = httpRequest.getCookies(); + Cookie[] cs = httpRequest.getCookies(); if (cs != null) { - for (javax.servlet.http.Cookie c : cs) { + for (Cookie c : cs) { httpResponse.addCookie(c); } } @@ -142,9 +185,35 @@ public void handle(String pathInContext, } } + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { + server = new Server(); + + port1 = findFreePort(); + port2 = findFreePort(); + + Connector listener = new SelectChannelConnector(); + + listener.setHost("127.0.0.1"); + listener.setPort(port1); + + server.addConnector(listener); + + listener = new SelectChannelConnector(); + listener.setHost("127.0.0.1"); + listener.setPort(port2); + + server.addConnector(listener); + + server.setHandler(configureHandler()); + server.start(); + log.info("Local HTTP server started successfully"); + } + @AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { - server.stop(); + if (server != null) + server.stop(); } protected int findFreePort() throws IOException { @@ -154,8 +223,7 @@ protected int findFreePort() throws IOException { socket = new ServerSocket(0); return socket.getLocalPort(); - } - finally { + } finally { if (socket != null) { socket.close(); } @@ -174,31 +242,6 @@ public AbstractHandler configureHandler() throws Exception { return new EchoHandler(); } - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - server = new Server(); - - port1 = findFreePort(); - port2 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); - listener.setPort(port2); - - server.addConnector(listener); - - server.setHandler(configureHandler()); - server.start(); - log.info("Local HTTP server started successfully"); - } - public static class AsyncCompletionHandlerAdapter extends AsyncCompletionHandler { public Runnable runnable; @@ -207,7 +250,7 @@ public Response onCompleted(Response response) throws Exception { return response; } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); Assert.fail("Unexpected exception: " + t.getMessage(), t); @@ -217,35 +260,32 @@ public void onThrowable(Throwable t) { public static class AsyncHandlerAdapter implements AsyncHandler { - - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); Assert.fail("Unexpected exception", t); } - /* @Override */ + @Override public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { return STATE.CONTINUE; } - /* @Override */ + @Override public STATE onStatusReceived(final HttpResponseStatus responseStatus) throws Exception { return STATE.CONTINUE; } - /* @Override */ + @Override public STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { return STATE.CONTINUE; } - /* @Override */ + @Override public String onCompleted() throws Exception { return ""; } - } public abstract AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config); - } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 4d51edc0d9..db340b74e4 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -62,6 +62,7 @@ import org.asynchttpclient.StringPart; public abstract class AsyncProvidersBasicTest extends AbstractBasicTest { + private static final String UTF_8 = "text/html;charset=UTF-8"; @Test(groups = { "standalone", "default_provider", "async" }) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index 2277d5a7a7..9c6a4ddfed 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -38,8 +38,9 @@ import java.util.concurrent.atomic.AtomicBoolean; public abstract class AsyncStreamHandlerTest extends AbstractBasicTest { - private final static String RESPONSE = "param_1_"; - private final static String UTF8 = "text/html;charset=utf-8"; + + private static final String RESPONSE = "param_1_"; + private static final String UTF8 = "text/html;charset=utf-8"; @Test(groups = { "standalone", "default_provider" }) public void asyncStreamGETTest() throws Throwable { diff --git a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java index fb91595999..bd4491f7a6 100644 --- a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java @@ -51,9 +51,9 @@ public abstract class AuthTimeoutTest extends AbstractBasicTest { - private final static String user = "user"; + private static final String USER = "user"; - private final static String admin = "admin"; + private static final String ADMIN = "admin"; protected AsyncHttpClient client; @@ -76,7 +76,7 @@ public void setUpServer(String auth) throws Exception { Constraint constraint = new Constraint(); constraint.setName(auth); - constraint.setRoles(new String[] { user, admin }); + constraint.setRoles(new String[] { USER, ADMIN }); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); @@ -84,8 +84,8 @@ public void setUpServer(String auth) throws Exception { mapping.setPathSpec("/*"); Set knownRoles = new HashSet(); - knownRoles.add(user); - knownRoles.add(admin); + knownRoles.add(USER); + knownRoles.add(ADMIN); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); @@ -258,7 +258,7 @@ protected Future execute(boolean preemptive) throws IOException { } private Realm realm(boolean preemptive) { - return (new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setUsePreemptiveAuth(preemptive).build(); + return (new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setUsePreemptiveAuth(preemptive).build(); } @Override diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 7638571cca..9e5f8b6bdc 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -42,6 +42,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.util.security.Constraint; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -68,12 +69,12 @@ public abstract class BasicAuthTest extends AbstractBasicTest { - protected final static String MY_MESSAGE = "my message"; - protected final static String user = "user"; - protected final static String admin = "admin"; + protected static final String MY_MESSAGE = "my message"; + protected static final String USER = "user"; + protected static final String ADMIN = "admin"; private Server server2; - + public abstract String getProviderClass(); @BeforeClass(alwaysRun = true) @@ -97,7 +98,7 @@ public void setUpGlobal() throws Exception { Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); - constraint.setRoles(new String[] { user, admin }); + constraint.setRoles(new String[] { USER, ADMIN }); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); @@ -108,8 +109,8 @@ public void setUpGlobal() throws Exception { cm.add(mapping); Set knownRoles = new HashSet(); - knownRoles.add(user); - knownRoles.add(admin); + knownRoles.add(USER); + knownRoles.add(ADMIN); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setConstraintMappings(cm, knownRoles); @@ -121,33 +122,7 @@ public void setUpGlobal() throws Exception { server.setHandler(security); server.start(); log.info("Local HTTP server started successfully"); - } - - private String getFileContent(final File file) { - FileInputStream in = null; - try { - if (file.exists() && file.canRead()) { - final StringBuilder sb = new StringBuilder(128); - final byte[] b = new byte[512]; - int read; - in = new FileInputStream(file); - while ((read = in.read(b)) != -1) { - sb.append(new String(b, 0, read, "UTF-8")); - } - return sb.toString(); - } - throw new IllegalArgumentException("File does not exist or cannot be read: " + file.getCanonicalPath()); - } catch (IOException ioe) { - throw new IllegalStateException(ioe); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException ignored) { - } - } - } - + setUpSecondServer(); } private void setUpSecondServer() throws Exception { @@ -165,7 +140,7 @@ private void setUpSecondServer() throws Exception { Constraint constraint = new Constraint(); constraint.setName(Constraint.__DIGEST_AUTH); - constraint.setRoles(new String[] { user, admin }); + constraint.setRoles(new String[] { USER, ADMIN }); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); @@ -173,8 +148,8 @@ private void setUpSecondServer() throws Exception { mapping.setPathSpec("/*"); Set knownRoles = new HashSet(); - knownRoles.add(user); - knownRoles.add(admin); + knownRoles.add(USER); + knownRoles.add(ADMIN); ConstraintSecurityHandler security = new ConstraintSecurityHandler() { @@ -200,10 +175,39 @@ public void handle(String arg0, Request arg1, HttpServletRequest arg2, HttpServl server2.start(); } - private void stopSecondServer() throws Exception { + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + super.tearDownGlobal(); server2.stop(); } + private String getFileContent(final File file) { + FileInputStream in = null; + try { + if (file.exists() && file.canRead()) { + final StringBuilder sb = new StringBuilder(128); + final byte[] b = new byte[512]; + int read; + in = new FileInputStream(file); + while ((read = in.read(b)) != -1) { + sb.append(new String(b, 0, read, "UTF-8")); + } + return sb.toString(); + } + throw new IllegalArgumentException("File does not exist or cannot be read: " + file.getCanonicalPath()); + } catch (IOException ioe) { + throw new IllegalStateException(ioe); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException ignored) { + } + } + } + + } + private class RedirectHandler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { @@ -265,7 +269,7 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR public void basicAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -281,11 +285,10 @@ public void basicAuthTest() throws IOException, ExecutionException, TimeoutExcep public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = null; try { - setUpSecondServer(); client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).setMaximumNumberOfRedirects(10).build()); AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl2()) // .setHeader( "X-302", "/bla" ) - .setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -296,7 +299,6 @@ public void redirectAndBasicAuthTest() throws Exception, ExecutionException, Tim } finally { if (client != null) client.close(); - stopSecondServer(); } } @@ -313,7 +315,8 @@ protected String getTargetUrl2() { public void basic401Test() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setHeader("X-401", "401").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setHeader("X-401", "401") + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(new AsyncHandler() { @@ -356,7 +359,8 @@ public Integer onCompleted() throws Exception { public void basicAuthTestPreemtiveTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setUsePreemptiveAuth(true).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm( + (new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setUsePreemptiveAuth(true).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -372,7 +376,7 @@ public void basicAuthTestPreemtiveTest() throws IOException, ExecutionException, public void basicAuthNegativeTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -388,7 +392,8 @@ public void basicAuthInputStreamTest() throws IOException, ExecutionException, T AsyncHttpClient client = getAsyncHttpClient(null); try { ByteArrayInputStream is = new ByteArrayInputStream("test".getBytes()); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(is).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(is) + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(30, TimeUnit.SECONDS); @@ -411,7 +416,8 @@ public void basicAuthFileTest() throws Throwable { File file = new File(url.toURI()); final String fileContent = getFileContent(file); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file) + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -426,7 +432,7 @@ public void basicAuthFileTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void basicAuthAsyncConfigTest() throws Throwable { - AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()).build()); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()).build()); try { ClassLoader cl = getClass().getClassLoader(); // override system properties @@ -457,7 +463,8 @@ public void basicAuthFileNoKeepAliveTest() throws Throwable { File file = new File(url.toURI()); final String fileContent = getFileContent(file); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file) + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); @@ -478,7 +485,8 @@ public AbstractHandler configureHandler() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void stringBuilderBodyConsumerTest() throws Throwable { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setRealmPrincipal(user).setRealmPassword(admin).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setRealmPrincipal(USER).setRealmPassword(ADMIN) + .setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); @@ -498,7 +506,7 @@ public void stringBuilderBodyConsumerTest() throws Throwable { public void noneAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index 1aa8dc5581..c5f4ff36a4 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -15,34 +15,12 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig.Builder; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.ssl.SslSocketConnector; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; -import java.net.ServerSocket; import java.net.URL; import java.security.KeyStore; import java.security.SecureRandom; @@ -50,21 +28,35 @@ import java.security.cert.X509Certificate; import java.util.Enumeration; import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig.Builder; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; -public abstract class BasicHttpsTest extends AbstractBasicTest { +public abstract class BasicHttpsTest extends AbstractBasicHttpsTest { - protected final Logger log = LoggerFactory.getLogger(BasicHttpsTest.class); + protected static final Logger LOGGER = LoggerFactory.getLogger(BasicHttpsTest.class); public static class EchoHandler extends AbstractHandler { - /* @Override */ + @Override public void handle(String pathInContext, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException { httpResponse.setContentType("text/html; charset=utf-8"); @@ -133,75 +125,15 @@ public void handle(String pathInContext, Request r, HttpServletRequest httpReque httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); - } } - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws Exception { - server.stop(); - } - - @AfterMethod(alwaysRun = true) - public void tearDownProps() throws Exception { - System.clearProperty("javax.net.ssl.keyStore"); - System.clearProperty("javax.net.ssl.trustStore"); - } - - protected String getTargetUrl() { - return String.format("https://127.0.0.1:%d/foo/test", port1); - } - public AbstractHandler configureHandler() throws Exception { return new EchoHandler(); } - protected int findFreePort() throws IOException { - ServerSocket socket = null; - - try { - socket = new ServerSocket(0); - - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } - } - - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - SslSocketConnector connector = new SslSocketConnector(); - connector.setHost("127.0.0.1"); - connector.setPort(port1); - - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL cacertsUrl = cl.getResource("ssltest-cacerts.jks"); - String trustStoreFile = new File(cacertsUrl.toURI()).getAbsolutePath(); - connector.setTruststore(trustStoreFile); - connector.setTrustPassword("changeit"); - connector.setTruststoreType("JKS"); - - log.info("SSL certs path: {}", trustStoreFile); - - // override system properties - URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); - String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); - connector.setKeystore(keyStoreFile); - connector.setKeyPassword("changeit"); - connector.setKeystoreType("JKS"); - - log.info("SSL keystore path: {}", keyStoreFile); - - server.addConnector(connector); - - server.setHandler(configureHandler()); - server.start(); - log.info("Local HTTP server started successfully"); + protected String getTargetUrl() { + return String.format("https://127.0.0.1:%d/foo/test", port1); } @Test(groups = { "standalone", "default_provider" }) @@ -209,13 +141,10 @@ public void zeroCopyPostTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); + URL url = getClass().getClassLoader().getResource("SimpleTextFile.txt"); File file = new File(url.toURI()); - Future f = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute(); - Response resp = f.get(); + Response resp = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), "This is a simple test file"); @@ -263,7 +192,7 @@ public void multipleSSLWithoutCacheTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void reconnectsAfterFailedCertificationPath() throws Throwable { - AtomicBoolean trusted = new AtomicBoolean(false); + AtomicBoolean trusted = new AtomicBoolean(false); final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build()); try { final String body = "hello there"; @@ -319,20 +248,20 @@ private static SSLContext createSSLContext(AtomicBoolean trusted) { } private static final TrustManager dummyTrustManager(final AtomicBoolean trusted) { - return new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - if (!trusted.get()) { - throw new CertificateException("Server certificate not trusted."); - } - } - }; - } + return new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + if (!trusted.get()) { + throw new CertificateException("Server certificate not trusted."); + } + } + }; + } } diff --git a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java index 4498632771..46ee31059d 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java @@ -29,7 +29,7 @@ public abstract class BodyChunkTest extends AbstractBasicTest { - private final static String MY_MESSAGE = "my message"; + private static final String MY_MESSAGE = "my message"; @Test(groups = { "standalone", "default_provider" }) public void negativeContentTypeTest() throws Throwable { @@ -57,5 +57,4 @@ public void negativeContentTypeTest() throws Throwable { client.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index efffe05660..f5ebf6ac05 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -12,85 +12,52 @@ */ package org.asynchttpclient.async; +import static org.testng.Assert.assertNotNull; +import static org.testng.AssertJUnit.*; +import static org.testng.FileAssert.fail; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.generators.InputStreamBodyGenerator; import org.testng.annotations.Test; -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.net.URL; -import java.util.Random; - -import static org.testng.Assert.assertNotNull; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertTrue; -import static org.testng.FileAssert.fail; - /** * Test that the url fetcher is able to communicate via a proxy - * + * * @author dominict */ abstract public class ChunkingTest extends AbstractBasicTest { // So we can just test the returned data is the image, // and doesn't contain the chunked delimeters. - public static byte[] LARGE_IMAGE_BYTES; - - static { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - InputStream instream = null; - try { - ClassLoader cl = ChunkingTest.class.getClassLoader(); - // override system properties - URL url = cl.getResource("300k.png"); - File sourceFile = new File(url.toURI()); - instream = new FileInputStream(sourceFile); - byte[] buf = new byte[8092]; - int len = 0; - while ((len = instream.read(buf)) > 0) { - baos.write(buf, 0, len); - } - LARGE_IMAGE_BYTES = baos.toByteArray(); - } - catch (Throwable e) { - LARGE_IMAGE_BYTES = new byte[265495]; - Random x = new Random(); - x.nextBytes(LARGE_IMAGE_BYTES); - } - } /** - * Tests that the custom chunked stream result in success and - * content returned that is unchunked + * Tests that the custom chunked stream result in success and content returned that is unchunked */ @Test() public void testCustomChunking() throws Throwable { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - + AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder(); + bc.setAllowPoolingConnection(true); bc.setMaximumConnectionsPerHost(1); bc.setMaximumConnectionsTotal(1); bc.setConnectionTimeoutInMs(1000); bc.setRequestTimeoutInMs(1000); bc.setFollowRedirects(true); - - + AsyncHttpClient c = getAsyncHttpClient(bc.build()); try { RequestBuilder builder = new RequestBuilder("POST"); builder.setUrl(getTargetUrl()); // made buff in stream big enough to mark. - builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000))); + builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000))); Request r = builder.build(); Response res = null; @@ -109,57 +76,14 @@ public void testCustomChunking() throws Throwable { assertTrue("Should have failed due to chunking", res.getHeader("X-Exception").contains("invalid.chunk.length")); fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + res.getHeader("X-Exception")); } else { - assertEquals(LARGE_IMAGE_BYTES, readInputStreamToBytes(res.getResponseBodyAsStream())); + assertEquals(LARGE_IMAGE_BYTES, res.getResponseBodyAsBytes()); } - } - catch (Exception e) { + } catch (Exception e) { fail("Exception Thrown:" + e.getMessage()); } - } - finally { + } finally { c.close(); } } - - private byte[] readInputStreamToBytes(InputStream stream) { - byte[] data = new byte[0]; - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - try { - int nRead; - byte[] tmp = new byte[8192]; - - while ((nRead = stream.read(tmp, 0, tmp.length)) != -1) { - buffer.write(tmp, 0, nRead); - } - buffer.flush(); - data = buffer.toByteArray(); - } - catch (Exception e) { - - } - finally { - try { - stream.close(); - } catch (Exception e2) { - } - return data; - } - } - - private static File getTestFile() { - String testResource1 = "300k.png"; - - File testResource1File = null; - try { - ClassLoader cl = ChunkingTest.class.getClassLoader(); - URL url = cl.getResource(testResource1); - testResource1File = new File(url.toURI()); - } catch (Throwable e) { - // TODO Auto-generated catch block - fail("unable to find " + testResource1); - } - - return testResource1File; - } } diff --git a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java index ccc7d3901b..8523f82697 100644 --- a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java @@ -268,5 +268,4 @@ public Response onCompleted(Response response) throws Exception { client.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java b/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java index dbd83a4000..7d4427192b 100644 --- a/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java @@ -51,8 +51,8 @@ public abstract class DigestAuthTest extends AbstractBasicTest { - private final static String user = "user"; - private final static String admin = "admin"; + private static final String USER = "user"; + private static final String ADMIN = "admin"; @BeforeClass(alwaysRun = true) @Override @@ -75,7 +75,7 @@ public void setUpGlobal() throws Exception { Constraint constraint = new Constraint(); constraint.setName(Constraint.__BASIC_AUTH); - constraint.setRoles(new String[] { user, admin }); + constraint.setRoles(new String[] { USER, ADMIN }); constraint.setAuthenticate(true); ConstraintMapping mapping = new ConstraintMapping(); @@ -86,8 +86,8 @@ public void setUpGlobal() throws Exception { cm.add(mapping); Set knownRoles = new HashSet(); - knownRoles.add(user); - knownRoles.add(admin); + knownRoles.add(USER); + knownRoles.add(ADMIN); ConstraintSecurityHandler security = new ConstraintSecurityHandler(); security.setConstraintMappings(cm, knownRoles); @@ -115,7 +115,7 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR public void digestAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setRealmName("MyRealm").setScheme(Realm.AuthScheme.DIGEST).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").setScheme(Realm.AuthScheme.DIGEST).build()); Future f = r.execute(); Response resp = f.get(60, TimeUnit.SECONDS); @@ -131,7 +131,7 @@ public void digestAuthTest() throws IOException, ExecutionException, TimeoutExce public void digestAuthTestWithoutScheme() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(user).setPassword(admin).setRealmName("MyRealm").build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").build()); Future f = r.execute(); Response resp = f.get(60, TimeUnit.SECONDS); @@ -147,7 +147,7 @@ public void digestAuthTestWithoutScheme() throws IOException, ExecutionException public void digestAuthNegativeTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(admin).setScheme(Realm.AuthScheme.DIGEST).build()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(ADMIN).setScheme(Realm.AuthScheme.DIGEST).build()); Future f = r.execute(); Response resp = f.get(20, TimeUnit.SECONDS); diff --git a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java index d522ab05f5..a0d8a4c7ce 100644 --- a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java +++ b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java @@ -77,5 +77,4 @@ public void Expect100Continue() throws Throwable { public AbstractHandler configureHandler() throws Exception { return new ZeroCopyHandler(); } - } diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index adbe310ab3..afca1d2a79 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -12,6 +12,14 @@ */ package org.asynchttpclient.async; +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; import org.asynchttpclient.AsyncHttpClientConfig; @@ -20,34 +28,18 @@ import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; import org.testng.Assert; -import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.UUID; - -import static org.testng.FileAssert.fail; - public abstract class FilePartLargeFileTest extends AbstractBasicTest { - private File largeFile; - @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutImageFile() throws Exception { - largeFile = getTestFile(); AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build(); AsyncHttpClient client = getAsyncHttpClient(config); try { BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - rb.addBodyPart(new FilePart("test", largeFile, "application/octet-stream", "UTF-8")); + rb.addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")); Response response = rb.execute().get(); Assert.assertEquals(200, response.getStatusCode()); @@ -58,9 +50,8 @@ public void testPutImageFile() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeTextFile() throws Exception { - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 1024 / bytes.length) + 1; - largeFile = createTempFile(bytes, (int) repeats); + long repeats = (1024 * 1024 / PATTERN_BYTES.length) + 1; + File largeFile = createTempFile(PATTERN_BYTES, (int) repeats); AsyncHttpClient client = getAsyncHttpClient(null); try { @@ -75,27 +66,6 @@ public void testPutLargeTextFile() throws Exception { } } - private static File getTestFile() { - String testResource1 = "300k.png"; - - File testResource1File = null; - try { - ClassLoader cl = ChunkingTest.class.getClassLoader(); - URL url = cl.getResource(testResource1); - testResource1File = new File(url.toURI()); - } catch (Throwable e) { - // TODO Auto-generated catch block - fail("unable to find " + testResource1); - } - - return testResource1File; - } - - @AfterMethod - public void after() { - largeFile.delete(); - } - @Override public AbstractHandler configureHandler() throws Exception { return new AbstractHandler() { @@ -117,37 +87,7 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle resp.getOutputStream().close(); arg1.setHandled(true); - } }; } - - private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); - - public static File createTempFile(byte[] pattern, int repeat) throws IOException { - TMP.mkdirs(); - TMP.deleteOnExit(); - File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); - tmpFile.deleteOnExit(); - write(pattern, repeat, tmpFile); - - return tmpFile; - } - - public static void write(byte[] pattern, int repeat, File file) throws IOException { - file.deleteOnExit(); - file.getParentFile().mkdirs(); - FileOutputStream out = null; - try { - out = new FileOutputStream(file); - for (int i = 0; i < repeat; i++) { - out.write(pattern); - } - } finally { - if (out != null) { - out.close(); - } - } - } - } diff --git a/api/src/test/java/org/asynchttpclient/async/FollowingThreadTest.java b/api/src/test/java/org/asynchttpclient/async/FollowingThreadTest.java index c86ad22ae4..5ccb8ff6c8 100644 --- a/api/src/test/java/org/asynchttpclient/async/FollowingThreadTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FollowingThreadTest.java @@ -35,7 +35,7 @@ */ public abstract class FollowingThreadTest extends AbstractBasicTest { - private final static int COUNT = 10; + private static final int COUNT = 10; @Test(timeOut = 30 * 1000, groups = { "online", "default_provider", "scalability" }) public void testFollowRedirect() throws IOException, ExecutionException, TimeoutException, InterruptedException { @@ -94,5 +94,4 @@ public Integer onCompleted() throws Exception { pool.shutdown(); } } - -} \ No newline at end of file +} diff --git a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java index 1b5238bab3..989e78b280 100644 --- a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java @@ -12,30 +12,11 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig.Builder; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.ssl.SslSocketConnector; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.net.ssl.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; -import java.net.ServerSocket; -import java.net.URL; import java.security.KeyStore; import java.security.SecureRandom; import java.security.cert.CertificateException; @@ -45,11 +26,27 @@ import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig.Builder; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; -public abstract class HostnameVerifierTest extends AbstractBasicTest { +public abstract class HostnameVerifierTest extends AbstractBasicHttpsTest { protected final Logger log = LoggerFactory.getLogger(HostnameVerifierTest.class); @@ -128,17 +125,6 @@ public void handle(String pathInContext, Request r, HttpServletRequest httpReque } } - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws Exception { - server.stop(); - } - - @AfterMethod(alwaysRun = true) - public void tearDownProps() throws Exception { - System.clearProperty("javax.net.ssl.keyStore"); - System.clearProperty("javax.net.ssl.trustStore"); - } - protected String getTargetUrl() { return String.format("https://127.0.0.1:%d/foo/test", port1); } @@ -147,65 +133,12 @@ public AbstractHandler configureHandler() throws Exception { return new EchoHandler(); } - protected int findFreePort() throws IOException { - ServerSocket socket = null; - - try { - socket = new ServerSocket(0); - - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } - } - - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - SslSocketConnector connector = new SslSocketConnector(); - connector.setHost("127.0.0.1"); - connector.setPort(port1); - - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL cacertsUrl = cl.getResource("ssltest-cacerts.jks"); - String trustStoreFile = new File(cacertsUrl.toURI()).getAbsolutePath(); - connector.setTruststore(trustStoreFile); - connector.setTrustPassword("changeit"); - connector.setTruststoreType("JKS"); - - log.info("SSL certs path: {}", trustStoreFile); - - // override system properties - URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); - String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); - connector.setKeystore(keyStoreFile); - connector.setKeyPassword("changeit"); - connector.setKeystoreType("JKS"); - - log.info("SSL keystore path: {}", keyStoreFile); - - server.addConnector(connector); - - server.setHandler(configureHandler()); - server.start(); - log.info("Local HTTP server started successfully"); - } - @Test(groups = { "standalone", "default_provider" }) public void positiveHostnameVerifierTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new PositiveHostVerifier()).setSSLContext(createSSLContext()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - Future f = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute(); + Future f = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute(); Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); @@ -220,13 +153,8 @@ public void negativeHostnameVerifierTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new NegativeHostVerifier()).setSSLContext(createSSLContext()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - try { - client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -241,17 +169,10 @@ public void remoteIDHostnameVerifierTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("bouette")).setSSLContext(createSSLContext()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - try { - client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); - fail("ConnectException expected"); - } catch (ExecutionException ex) { - assertEquals(ex.getCause().getClass(), ConnectException.class); - } + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + fail("ConnectException expected"); + } catch (ExecutionException ex) { + assertEquals(ex.getCause().getClass(), ConnectException.class); } finally { client.close(); } @@ -262,17 +183,10 @@ public void remoteNegHostnameVerifierTest() throws Throwable { // request is made to 127.0.0.1, but cert presented for localhost - this should fail final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("localhost")).setSSLContext(createSSLContext()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - try { - client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); - fail("ConnectException expected"); - } catch (ExecutionException ex) { - assertEquals(ex.getCause().getClass(), ConnectException.class); - } + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + fail("ConnectException expected"); + } catch (ExecutionException ex) { + assertEquals(ex.getCause().getClass(), ConnectException.class); } finally { client.close(); } @@ -283,12 +197,7 @@ public void remotePosHostnameVerifierTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("127.0.0.1")).setSSLContext(createSSLContext()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - Response resp = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), "This is a simple test file"); @@ -320,12 +229,7 @@ public CheckHost(String hostName) { } public boolean verify(String s, SSLSession sslSession) { - - if (s != null && s.equalsIgnoreCase(hostName)) { - return true; - } - - return false; + return s != null && s.equalsIgnoreCase(hostName); } } diff --git a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java index 90b81dbd43..a0aa1eac15 100644 --- a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java @@ -15,6 +15,18 @@ */ package org.asynchttpclient.async; +import static org.testng.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; @@ -27,21 +39,9 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.Enumeration; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - public abstract class HttpToHttpsRedirectTest extends AbstractBasicTest { - private final AtomicBoolean isSet = new AtomicBoolean(false); + + private final AtomicBoolean redirectDone = new AtomicBoolean(false); private class Relative302Handler extends AbstractHandler { @@ -53,7 +53,7 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ while (e.hasMoreElements()) { param = e.nextElement().toString(); - if (param.startsWith("X-redirect") && !isSet.getAndSet(true)) { + if (param.startsWith("X-redirect") && !redirectDone.getAndSet(true)) { httpResponse.addHeader("Location", httpRequest.getHeader(param)); httpResponse.setStatus(302); httpResponse.getOutputStream().flush(); @@ -64,7 +64,7 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ if (r.getScheme().equalsIgnoreCase("https")) { httpResponse.addHeader("X-httpToHttps", "PASS"); - isSet.getAndSet(false); + redirectDone.getAndSet(false); } httpResponse.setStatus(200); @@ -116,23 +116,6 @@ public void setUpGlobal() throws Exception { log.info("Local HTTP server started successfully"); } - private String getBaseUrl(URI uri) { - String url = uri.toString(); - int port = uri.getPort(); - if (port == -1) { - port = getPort(uri); - url = url.substring(0, url.length() - 1) + ":" + port; - } - return url.substring(0, url.lastIndexOf(":") + String.valueOf(port).length() + 1); - } - - private static int getPort(URI uri) { - int port = uri.getPort(); - if (port == -1) - port = uri.getScheme().equals("http") ? 80 : 443; - return port; - } - @Test(groups = { "standalone", "default_provider" }) // FIXME find a way to make this threadsafe, other, set @Test(singleThreaded = true) public void httpToHttpsRunAllTestsSequentially() throws Exception { @@ -143,7 +126,7 @@ public void httpToHttpsRunAllTestsSequentially() throws Exception { // @Test(groups = { "standalone", "default_provider" }) public void httpToHttpsRedirect() throws Exception { - isSet.getAndSet(false); + redirectDone.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -157,13 +140,9 @@ public void httpToHttpsRedirect() throws Exception { } } - public String getTargetUrl2() { - return String.format("https://127.0.0.1:%d/foo/test", port2); - } - // @Test(groups = { "standalone", "default_provider" }) public void httpToHttpsProperConfig() throws Exception { - isSet.getAndSet(false); + redirectDone.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -185,7 +164,7 @@ public void httpToHttpsProperConfig() throws Exception { // @Test(groups = { "standalone", "default_provider" }) public void relativeLocationUrl() throws Exception { - isSet.getAndSet(false); + redirectDone.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); diff --git a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java index f42b234464..f5cc4d5b35 100644 --- a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java @@ -15,6 +15,15 @@ */ package org.asynchttpclient.async; +import static org.testng.Assert.fail; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.eclipse.jetty.server.Connector; @@ -25,29 +34,15 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.testng.Assert.fail; - public abstract class IdleStateHandlerTest extends AbstractBasicTest { - private final AtomicBoolean isSet = new AtomicBoolean(false); private class IdleStateHandler extends AbstractHandler { - public void handle(String s, - Request r, - HttpServletRequest httpRequest, - HttpServletResponse httpResponse) throws IOException, ServletException { + public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { try { Thread.sleep(20 * 1000); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { e.printStackTrace(); } httpResponse.setStatus(200); @@ -72,9 +67,8 @@ public void setUpGlobal() throws Exception { log.info("Local HTTP server started successfully"); } - @Test(groups = {"online", "default_provider"}) + @Test(groups = { "online", "default_provider" }) public void idleStateTest() throws Throwable { - isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(10 * 1000).build(); AsyncHttpClient c = getAsyncHttpClient(cg); diff --git a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java index 5ac600592d..8bcdb499f0 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java @@ -41,6 +41,7 @@ abstract public class MaxConnectionsInThreads extends AbstractBasicTest { + // FIXME weird private static URI servletEndpointUri; @Test(groups = { "online", "default_provider" }) diff --git a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java index 2b7cc355b6..891781fe19 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java @@ -12,35 +12,8 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ByteArrayPart; -import org.asynchttpclient.FilePart; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.StringPart; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.apache.commons.fileupload.FileItemIterator; -import org.apache.commons.fileupload.FileItemStream; -import org.apache.commons.fileupload.FileUploadException; -import org.apache.commons.fileupload.servlet.ServletFileUpload; -import org.apache.commons.fileupload.util.Streams; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; @@ -59,17 +32,41 @@ import java.util.UUID; import java.util.zip.GZIPInputStream; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.fileupload.FileItemIterator; +import org.apache.commons.fileupload.FileItemStream; +import org.apache.commons.fileupload.FileUploadException; +import org.apache.commons.fileupload.servlet.ServletFileUpload; +import org.apache.commons.fileupload.util.Streams; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ByteArrayPart; +import org.asynchttpclient.FilePart; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.asynchttpclient.StringPart; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; /** * @author dominict */ public abstract class MultipartUploadTest extends AbstractBasicTest { - private String servletEndpointRedirectUrl; - public static byte GZIPTEXT[] = new byte[] { 31, -117, 8, 8, 11, 43, 79, 75, 0, 3, 104, 101, 108, 108, 111, 46, 116, 120, 116, 0, -53, 72, -51, -55, -55, -25, 2, 0, 32, 48, 58, 54, 6, 0, 0, 0 }; + public static byte GZIPTEXT[] = new byte[] { 31, -117, 8, 8, 11, 43, 79, 75, 0, 3, 104, 101, 108, 108, 111, 46, 116, 120, 116, 0, -53, 72, -51, -55, -55, -25, 2, 0, 32, 48, + 58, 54, 6, 0, 0, 0 }; @BeforeClass public void setUp() throws Exception { @@ -89,23 +86,6 @@ public void setUp() throws Exception { server.setHandler(context); server.start(); - - servletEndpointRedirectUrl = "http://localhost/" + ":" + port1; - } - - @AfterClass - public void stop() { - try { - - if (server != null) { - server.stop(); - } - - } catch (Exception e) { - System.err.print("Error stopping servlet tester"); - e.printStackTrace(); - } - } private File getClasspathFile(String file) throws FileNotFoundException { @@ -215,7 +195,7 @@ public void testSendingSmallFilesAndByteArray() { try { RequestBuilder builder = new RequestBuilder("POST"); - builder.setUrl(servletEndpointRedirectUrl + "/upload/bob"); + builder.setUrl("http://localhost/" + ":" + port1 + "/upload/bob"); builder.addBodyPart(new FilePart("file1", testResource1File, "text/plain", "UTF-8")); builder.addBodyPart(new FilePart("file2", testResource2File, "application/x-gzip", null)); builder.addBodyPart(new StringPart("Name", "Dominic")); @@ -446,23 +426,27 @@ public void service(HttpServletRequest request, HttpServletResponse response) th } Writer w = response.getWriter(); - w.write(Integer.toString(getFilesProcessed())); - resetFilesProcessed(); - resetStringsProcessed(); - w.write("||"); - w.write(files.toString()); - w.close(); + try { + w.write(Integer.toString(getFilesProcessed())); + resetFilesProcessed(); + resetStringsProcessed(); + w.write("||"); + w.write(files.toString()); + } finally { + // FIXME + w.close(); + } } else { Writer w = response.getWriter(); - w.write(Integer.toString(getFilesProcessed())); - resetFilesProcessed(); - resetStringsProcessed(); - w.write("||"); - w.close(); + try { + w.write(Integer.toString(getFilesProcessed())); + resetFilesProcessed(); + resetStringsProcessed(); + w.write("||"); + } finally { + w.close(); + } } - } - } - } diff --git a/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java b/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java index 2ea4d395a2..ed6c6b413e 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java @@ -48,6 +48,49 @@ public abstract class MultipleHeaderTest extends AbstractBasicTest { private ServerSocket serverSocket; private Future voidFuture; + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { + port1 = findFreePort(); + + serverSocket = new ServerSocket(port1); + executorService = Executors.newFixedThreadPool(1); + voidFuture = executorService.submit(new Callable() { + public Void call() throws Exception { + Socket socket; + while ((socket = serverSocket.accept()) != null) { + InputStream inputStream = socket.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String req = reader.readLine().split(" ")[1]; + int i = inputStream.available(); + long l = inputStream.skip(i); + Assert.assertEquals(l, i); + socket.shutdownInput(); + if (req.endsWith("MultiEnt")) { + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); + outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 2\n" + + "Content-Length: 1\n" + "\n0\n"); + outputStreamWriter.flush(); + socket.shutdownOutput(); + } else if (req.endsWith("MultiOther")) { + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); + outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 1\n" + + "X-Forwarded-For: abc\n" + "X-Forwarded-For: def\n" + "\n0\n"); + outputStreamWriter.flush(); + socket.shutdownOutput(); + } + } + return null; + } + }); + } + + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + voidFuture.cancel(true); + executorService.shutdownNow(); + serverSocket.close(); + } + @Test(groups = { "standalone", "default_provider" }) public void testMultipleOtherHeaders() throws IOException, ExecutionException, TimeoutException, InterruptedException { final String[] xffHeaders = new String[] { null, null }; @@ -156,45 +199,4 @@ public Void onCompleted() throws Exception { ahc.close(); } } - - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - port1 = findFreePort(); - - serverSocket = new ServerSocket(port1); - executorService = Executors.newFixedThreadPool(1); - voidFuture = executorService.submit(new Callable() { - public Void call() throws Exception { - Socket socket; - while ((socket = serverSocket.accept()) != null) { - InputStream inputStream = socket.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - String req = reader.readLine().split(" ")[1]; - int i = inputStream.available(); - long l = inputStream.skip(i); - Assert.assertEquals(l, i); - socket.shutdownInput(); - if (req.endsWith("MultiEnt")) { - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); - outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 2\n" + "Content-Length: 1\n" + "\n0\n"); - outputStreamWriter.flush(); - socket.shutdownOutput(); - } else if (req.endsWith("MultiOther")) { - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); - outputStreamWriter.append("HTTP/1.0 200 OK\n" + "Connection: close\n" + "Content-Type: text/plain; charset=iso-8859-1\n" + "Content-Length: 1\n" + "X-Forwarded-For: abc\n" + "X-Forwarded-For: def\n" + "\n0\n"); - outputStreamWriter.flush(); - socket.shutdownOutput(); - } - } - return null; - } - }); - } - - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws Exception { - voidFuture.cancel(true); - executorService.shutdownNow(); - serverSocket.close(); - } } diff --git a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java index 924a9c90f8..156b177a26 100644 --- a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java @@ -20,6 +20,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import javax.servlet.ServletException; @@ -27,6 +28,7 @@ import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -35,7 +37,8 @@ public abstract class NonAsciiContentLengthTest extends AbstractBasicTest { - public void setUpServer() throws Exception { + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { server = new Server(); port1 = findFreePort(); Connector listener = new SelectChannelConnector(); @@ -75,7 +78,6 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques @Test(groups = { "standalone", "default_provider" }) public void testNonAsciiContentLength() throws Exception { - setUpServer(); execute("test"); execute("\u4E00"); // Unicode CJK ideograph for one } @@ -92,5 +94,4 @@ protected void execute(String body) throws IOException, InterruptedException, Ex client.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java index 6ca782abe6..b94d9a59a6 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java @@ -41,6 +41,7 @@ import static org.testng.Assert.assertTrue; public abstract class PerRequestRelative302Test extends AbstractBasicTest { + private final AtomicBoolean isSet = new AtomicBoolean(false); private class Relative302Handler extends AbstractHandler { @@ -86,7 +87,14 @@ public void setUpGlobal() throws Exception { } @Test(groups = { "online", "default_provider" }) - public void redirected302Test() throws Throwable { + public void runAllSequentiallyBecauseNotThreadSafe() throws Exception { + redirected302Test(); + notRedirected302Test(); + relativeLocationUrl(); + } + + // @Test(groups = { "online", "default_provider" }) + public void redirected302Test() throws Exception { isSet.getAndSet(false); AsyncHttpClient c = getAsyncHttpClient(null); try { @@ -104,8 +112,8 @@ public void redirected302Test() throws Throwable { } } - @Test(groups = { "online", "default_provider" }) - public void notRedirected302Test() throws Throwable { + // @Test(groups = { "online", "default_provider" }) + public void notRedirected302Test() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -153,8 +161,8 @@ public void redirected302InvalidTest() throws Throwable { } } - @Test(groups = { "standalone", "default_provider" }) - public void relativeLocationUrl() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void relativeLocationUrl() throws Exception { isSet.getAndSet(false); AsyncHttpClient c = getAsyncHttpClient(null); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java index 2cbb8e3677..5436cb05d8 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java @@ -16,15 +16,14 @@ package org.asynchttpclient.async; import static org.testng.Assert.*; -import static org.testng.Assert.assertEquals; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Response; import java.io.IOException; -import java.net.*; +import java.net.ConnectException; +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.SocketAddress; +import java.net.URI; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -37,6 +36,10 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; import org.testng.annotations.Test; @@ -52,7 +55,8 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR if ("GET".equalsIgnoreCase(request.getMethod())) { response.addHeader("target", r.getUri().getPath()); response.setStatus(HttpServletResponse.SC_OK); - } else { // this handler is to handle POST request + } else { + // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } r.setHandled(true); @@ -144,6 +148,15 @@ public void testNonProxyHostIssue202() throws IOException, ExecutionException, T } @Test(groups = { "standalone", "default_provider" }) + public void runSequentiallyBecauseNotThreadSafe() throws Exception { + testProxyProperties(); + testIgnoreProxyPropertiesByDefault(); + testProxyActivationProperty(); + testWildcardNonProxyHosts(); + testUseProxySelector(); + } + + // @Test(groups = { "standalone", "default_provider" }) public void testProxyProperties() throws IOException, ExecutionException, TimeoutException, InterruptedException { Properties originalProps = System.getProperties(); try { @@ -183,14 +196,14 @@ public void testProxyProperties() throws IOException, ExecutionException, Timeou } } - @Test(groups = { "standalone", "default_provider" }) + // @Test(groups = { "standalone", "default_provider" }) public void testIgnoreProxyPropertiesByDefault() throws IOException, ExecutionException, TimeoutException, InterruptedException { Properties originalProps = System.getProperties(); try { Properties props = new Properties(); props.putAll(originalProps); - // FIXME most likely non threadsafe! + // FIXME not threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -215,14 +228,14 @@ public void testIgnoreProxyPropertiesByDefault() throws IOException, ExecutionEx } } - @Test(groups = { "standalone", "default_provider" }) + // @Test(groups = { "standalone", "default_provider" }) public void testProxyActivationProperty() throws IOException, ExecutionException, TimeoutException, InterruptedException { Properties originalProps = System.getProperties(); try { Properties props = new Properties(); props.putAll(originalProps); - // FIXME most likely non threadsafe! + // FIXME not threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -255,14 +268,14 @@ public void testProxyActivationProperty() throws IOException, ExecutionException } } - @Test(groups = { "standalone", "default_provider" }) + // @Test(groups = { "standalone", "default_provider" }) public void testWildcardNonProxyHosts() throws IOException, ExecutionException, TimeoutException, InterruptedException { Properties originalProps = System.getProperties(); try { Properties props = new Properties(); props.putAll(originalProps); - // FIXME most likely non threadsafe! + // FIXME not threadsafe! System.setProperties(props); System.setProperty("http.proxyHost", "127.0.0.1"); @@ -288,7 +301,7 @@ public void testWildcardNonProxyHosts() throws IOException, ExecutionException, } } - @Test(groups = { "standalone", "default_provider" }) + // @Test(groups = { "standalone", "default_provider" }) public void testUseProxySelector() throws IOException, ExecutionException, TimeoutException, InterruptedException { ProxySelector originalProxySelector = ProxySelector.getDefault(); try { @@ -327,7 +340,7 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { client.close(); } } finally { - // FIXME is this threadsafe??? + // FIXME not threadsafe ProxySelector.setDefault(originalProxySelector); } } diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index 22e5a9764c..81b37ad077 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -91,7 +91,7 @@ public void setUpGlobal() throws Exception { @AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { - super.tearDownGlobal(); + server.stop(); server2.stop(); } diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index 2fafcdeff7..7dee570d97 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -13,10 +13,7 @@ package org.asynchttpclient.async; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.Charset; -import java.util.UUID; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -36,21 +33,11 @@ */ public abstract class PutLargeFileTest extends AbstractBasicTest { - private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); - private static final byte[] PATTERN_BYTES = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes(Charset.forName("UTF-16")); - - static { - TMP.mkdirs(); - TMP.deleteOnExit(); - } - @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeFile() throws Exception { long repeats = (1024 * 1024 * 100 / PATTERN_BYTES.length) + 1; File file = createTempFile(PATTERN_BYTES, (int) repeats); - long expectedFileSize = PATTERN_BYTES.length * repeats; - Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); int timeout = (int) (repeats / 1000); @@ -73,8 +60,6 @@ public void testPutSmallFile() throws Exception { long repeats = (1024 / PATTERN_BYTES.length) + 1; File file = createTempFile(PATTERN_BYTES, (int) repeats); - long expectedFileSize = PATTERN_BYTES.length * repeats; - Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); AsyncHttpClient client = getAsyncHttpClient(null); try { @@ -103,22 +88,4 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle } }; } - - public static File createTempFile(byte[] pattern, int repeat) throws IOException { - File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); - tmpFile.deleteOnExit(); - FileOutputStream out = null; - try { - out = new FileOutputStream(tmpFile); - for (int i = 0; i < repeat; i++) { - out.write(pattern); - } - } finally { - if (out != null) { - out.close(); - } - } - - return tmpFile; - } } diff --git a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java index 2b6437a888..a72ec9ebcc 100644 --- a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java +++ b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java @@ -125,5 +125,4 @@ public void urlWithColonTest_JDK() throws Throwable { c.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java index 2691ad3f38..4a2b749450 100644 --- a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java @@ -15,6 +15,18 @@ */ package org.asynchttpclient.async; +import static org.testng.Assert.*; +import static org.testng.FileAssert.fail; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Date; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; @@ -27,31 +39,16 @@ import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Date; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.FileAssert.fail; - /** - * Test for multithreaded url fetcher calls that use two separate - * sets of ssl certificates. This then tests that the certificate - * settings do not clash (override each other), resulting in the - * peer not authenticated exception - * + * Test for multithreaded url fetcher calls that use two separate sets of ssl certificates. This then tests that the certificate settings do not clash (override each other), + * resulting in the peer not authenticated exception + * * @author dominict */ -public abstract class RedirectConnectionUsageTest extends AbstractBasicTest{ +public abstract class RedirectConnectionUsageTest extends AbstractBasicTest { private String BASE_URL; private String servletEndpointRedirectUrl; @@ -68,7 +65,6 @@ public void setUp() throws Exception { server.addConnector(listener); - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); @@ -81,39 +77,23 @@ public void setUp() throws Exception { BASE_URL = "http://localhost/" + ":" + port1; servletEndpointRedirectUrl = BASE_URL + "/redirect"; - - } - - @AfterClass - public void tearDown() { - try { - if (server != null) { - server.stop(); - } - - } catch (Exception e) { - System.err.print("Error stopping servlet tester"); - e.printStackTrace(); - } } /** - * Tests that after a redirect the final url in the response - * reflect the redirect + * Tests that after a redirect the final url in the response reflect the redirect */ @Test public void testGetRedirectFinalUrl() { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - + AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder(); + bc.setAllowPoolingConnection(true); bc.setMaximumConnectionsPerHost(1); bc.setMaximumConnectionsTotal(1); bc.setConnectionTimeoutInMs(1000); bc.setRequestTimeoutInMs(1000); bc.setFollowRedirects(true); - + AsyncHttpClient c = getAsyncHttpClient(bc.build()); try { @@ -146,8 +126,7 @@ public void testGetRedirectFinalUrl() { @SuppressWarnings("serial") class MockRedirectHttpServlet extends HttpServlet { - public void service(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.sendRedirect("/overthere"); } } @@ -159,7 +138,7 @@ class MockFullResponseHttpServlet extends HttpServlet { private static final String xml = ""; public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - String xmlToReturn = String.format(xml, new Object[]{new Date().toString()}); + String xmlToReturn = String.format(xml, new Object[] { new Date().toString() }); res.setStatus(200, "Complete, XML Being Returned"); res.addHeader("Content-Type", contentType); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index d8b8bedcdb..73bc1ff0c9 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -307,5 +307,4 @@ public void testMultiPartPost() throws Exception { client.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 91a3a534f1..cb67385dff 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -12,17 +12,11 @@ */ package org.asynchttpclient.async; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.Charset; import java.util.Enumeration; -import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -45,14 +39,6 @@ public abstract class TransferListenerTest extends AbstractBasicTest { - private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); - private static final byte[] PATTERN_BYTES = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes(Charset.forName("UTF-16")); - - static { - TMP.mkdirs(); - TMP.deleteOnExit(); - } - private class BasicHandler extends AbstractHandler { public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { @@ -269,26 +255,4 @@ public void onThrowable(Throwable t) { client.close(); } } - - public String getTargetUrl() { - return String.format("http://127.0.0.1:%d/foo/test", port1); - } - - public static File createTempFile(byte[] pattern, int repeat) throws IOException { - File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); - tmpFile.deleteOnExit(); - FileOutputStream out = null; - try { - out = new FileOutputStream(tmpFile); - for (int i = 0; i < repeat; i++) { - out.write(pattern); - } - } finally { - if (out != null) { - out.close(); - } - } - - return tmpFile; - } } diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index 4d5374d447..dd8a80d21f 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -40,7 +40,7 @@ public abstract class WebDavBasicTest extends AbstractBasicTest { - public Embedded embedded; + protected Embedded embedded; @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { @@ -76,11 +76,17 @@ public void setUpGlobal() throws Exception { embedded.start(); } + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws InterruptedException, Exception { + embedded.stop(); + } + protected String getTargetUrl() { return String.format("http://127.0.0.1:%s/folder1", port1); } @AfterMethod(alwaysRun = true) + // FIXME not sure that's threadsafe public void clean() throws InterruptedException, Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { @@ -91,11 +97,6 @@ public void clean() throws InterruptedException, Exception { } } - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws InterruptedException, Exception { - embedded.stop(); - } - @Test(groups = { "standalone", "default_provider" }) public void mkcolWebDavTest1() throws InterruptedException, IOException, ExecutionException { @@ -192,5 +193,4 @@ public WebDavResponse onCompleted(WebDavResponse response) throws Exception { c.close(); } } - } diff --git a/api/src/test/java/org/asynchttpclient/generators/ByteArrayBodyGeneratorTest.java b/api/src/test/java/org/asynchttpclient/generators/ByteArrayBodyGeneratorTest.java index efd53a3bf6..bec6bc7975 100644 --- a/api/src/test/java/org/asynchttpclient/generators/ByteArrayBodyGeneratorTest.java +++ b/api/src/test/java/org/asynchttpclient/generators/ByteArrayBodyGeneratorTest.java @@ -74,5 +74,4 @@ public void testMultipleReads() throws IOException { assertEquals(reads, 4, "reads to drain generator"); assertEquals(bytesRead, srcArraySize, "bytes read"); } - } diff --git a/api/src/test/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcesserTest.java b/api/src/test/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcesserTest.java index ab958e529f..39d4ce09c4 100644 --- a/api/src/test/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcesserTest.java +++ b/api/src/test/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcesserTest.java @@ -36,5 +36,4 @@ public void testSaveLoad() throws Exception { assertEquals(m.get("http://localhost/test.url"), Long.valueOf(15L)); assertEquals(m.get("http://localhost/test2.url"), Long.valueOf(50L)); } - } diff --git a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java index 24f1823d97..4fc002c578 100644 --- a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java +++ b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java @@ -22,16 +22,13 @@ public class ProxyUtilsTest { @Test(groups = "fast") public void testBasics() { - ProxyServer proxyServer; - Request req; - // should avoid, there is no proxy (is null) - req = new RequestBuilder("GET").setUrl("http://somewhere.com/foo").build(); + Request req = new RequestBuilder("GET").setUrl("http://somewhere.com/foo").build(); Assert.assertTrue(ProxyUtils.avoidProxy(null, req)); // should avoid, it's in non-proxy hosts req = new RequestBuilder("GET").setUrl("http://somewhere.com/foo").build(); - proxyServer = new ProxyServer("foo", 1234); + ProxyServer proxyServer = new ProxyServer("foo", 1234); proxyServer.addNonProxyHost("somewhere.com"); Assert.assertTrue(ProxyUtils.avoidProxy(proxyServer, req)); diff --git a/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java b/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java index 21af508699..dee5562997 100644 --- a/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java +++ b/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java @@ -19,11 +19,9 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class TestUTF8UrlCodec -{ - @Test(groups="fast") - public void testBasics() - { +public class TestUTF8UrlCodec { + @Test(groups = "fast") + public void testBasics() { Assert.assertEquals(UTF8UrlEncoder.encode("foobar"), "foobar"); Assert.assertEquals(UTF8UrlEncoder.encode("a&b"), "a%26b"); Assert.assertEquals(UTF8UrlEncoder.encode("a+b"), "a%2Bb"); diff --git a/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java b/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java index bbff1213e9..c8e765c7d1 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java @@ -12,8 +12,12 @@ */ package org.asynchttpclient.websocket; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.HandlerWrapper; @@ -24,18 +28,36 @@ import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.ServerSocket; +public abstract class AbstractBasicTest extends org.asynchttpclient.async.AbstractBasicTest { -public abstract class AbstractBasicTest extends Server { + protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); + + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { + + server = new Server(); + port1 = findFreePort(); + + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setPort(port1); + server.addConnector(connector); + WebSocketHandler _wsHandler = getWebSocketHandler(); + + server.setHandler(_wsHandler); + + server.start(); + log.info("Local HTTP server started successfully"); + } + + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + server.stop(); + } public abstract class WebSocketHandler extends HandlerWrapper implements WebSocketFactory.Acceptor { private final WebSocketFactory _webSocketFactory = new WebSocketFactory(this, 32 * 1024); - public WebSocketHandler(){ + public WebSocketHandler() { _webSocketFactory.setMaxIdleTime(10000); } @@ -43,7 +65,6 @@ public WebSocketFactory getWebSocketFactory() { return _webSocketFactory; } - /* ------------------------------------------------------------ */ @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (_webSocketFactory.acceptWebSocket(request, response) || response.isCommitted()) @@ -51,57 +72,14 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques super.handle(target, baseRequest, request, response); } - /* ------------------------------------------------------------ */ public boolean checkOrigin(HttpServletRequest request, String origin) { return true; } - - } - - protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); - protected int port1; - SelectChannelConnector _connector; - - @AfterClass(alwaysRun = true) - public void tearDownGlobal() throws Exception { - stop(); - } - - protected int findFreePort() throws IOException { - ServerSocket socket = null; - - try { - socket = new ServerSocket(0); - - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } } protected String getTargetUrl() { return String.format("ws://127.0.0.1:%d/", port1); } - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - port1 = findFreePort(); - _connector = new SelectChannelConnector(); - _connector.setPort(port1); - - addConnector(_connector); - WebSocketHandler _wsHandler = getWebSocketHandler(); - - setHandler(_wsHandler); - - start(); - log.info("Local HTTP server started successfully"); - } - - public abstract WebSocketHandler getWebSocketHandler() ; - - public abstract AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config); - + public abstract WebSocketHandler getWebSocketHandler(); } diff --git a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java index 271ade7912..17beea6214 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java @@ -78,11 +78,11 @@ public Listener(CountDownLatch latch, AtomicReference text) { this.text = text; } - // @Override + @Override public void onOpen(WebSocket websocket) { } - // @Override + @Override public void onClose(WebSocket websocket) { } @@ -91,7 +91,7 @@ public void onClose(WebSocket websocket, int code, String reason) { latch.countDown(); } - // @Override + @Override public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); diff --git a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java index dda8808237..33fa8c9b5d 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java @@ -13,48 +13,44 @@ package org.asynchttpclient.websocket; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.websocket.WebSocket; -import org.asynchttpclient.websocket.WebSocketListener; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import static org.testng.Assert.assertEquals; - public abstract class RedirectTest extends AbstractBasicTest { - protected int port2; - - // ------------------------------------------ Methods from AbstractBasicTest - @BeforeClass @Override public void setUpGlobal() throws Exception { port1 = findFreePort(); + port2 = findFreePort(); - _connector = new SelectChannelConnector(); - _connector.setPort(port1); + server = new Server(); - addConnector(_connector); + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setPort(port1); + server.addConnector(connector); - port2 = findFreePort(); - final SelectChannelConnector connector2 = new SelectChannelConnector(); + SelectChannelConnector connector2 = new SelectChannelConnector(); connector2.setPort(port2); - addConnector(connector2); - WebSocketHandler _wsHandler = getWebSocketHandler(); + server.addConnector(connector2); + HandlerList list = new HandlerList(); list.addHandler(new AbstractHandler() { @Override @@ -64,10 +60,10 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ } } }); - list.addHandler(_wsHandler); - setHandler(list); + list.addHandler(getWebSocketHandler()); + server.setHandler(list); - start(); + server.start(); log.info("Local HTTP server started successfully"); } @@ -81,8 +77,6 @@ public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletReque }; } - // ------------------------------------------------------------ Test Methods - @Test(timeOut = 60000) public void testRedirectToWSResource() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); @@ -117,8 +111,6 @@ public void onError(Throwable t) { } } - // --------------------------------------------------------- Private Methods - private String getRedirectURL() { return String.format("ws://127.0.0.1:%d/", port2); } diff --git a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java index c64efe4cd7..4bce6f8860 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java @@ -76,7 +76,7 @@ public void onOpen() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - /* WebSocket websocket = */c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { + c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { @Override public void onOpen(WebSocket websocket) { @@ -402,5 +402,4 @@ public void onError(Throwable t) { c.close(); } } - } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicHttpsTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicHttpsTest.java index b8e2902466..c2cedc0eee 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicHttpsTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicHttpsTest.java @@ -23,9 +23,4 @@ public class GrizzlyBasicHttpsTest extends BasicHttpsTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } - - @Override - public void zeroCopyPostTest() throws Throwable { - super.zeroCopyPostTest(); //To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java index 314624c463..96b1288664 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java @@ -12,11 +12,11 @@ */ package org.asynchttpclient.providers.netty4; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -27,17 +27,16 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; +import org.eclipse.jetty.continuation.Continuation; +import org.eclipse.jetty.continuation.ContinuationSupport; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; public class NettyRequestThrottleTimeoutTest extends AbstractBasicTest { private static final String MSG = "Enough is enough."; @@ -80,11 +79,12 @@ public void run() { public void testRequestTimeout() throws IOException { final Semaphore requestThrottle = new Semaphore(1); - final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); + final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAllowPoolingConnection(true) + .setMaximumConnectionsTotal(1).build()); try { final CountDownLatch latch = new CountDownLatch(2); + final List tooManyConnections = Collections.synchronizedList(new ArrayList(2)); - final List tooManyConnections = new ArrayList(2); for (int i = 0; i < 2; i++) { new Thread(new Runnable() { @@ -119,7 +119,6 @@ public void onThrowable(Throwable t) { } }).start(); - } try { @@ -128,7 +127,7 @@ public void onThrowable(Throwable t) { fail("failed to wait for requests to complete"); } - assertTrue(tooManyConnections.size() == 0, "Should not have any connection errors where too many connections have been attempted"); + assertTrue(tooManyConnections.isEmpty(), "Should not have any connection errors where too many connections have been attempted"); } finally { client.close(); } From abf97e9bfd7f53330d6aabcd1b6bd136e2231411 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 23:16:13 +0200 Subject: [PATCH 0106/2389] Minor clean up --- .../java/org/asynchttpclient/FilePart.java | 2 +- .../asynchttpclient/async/BasicHttpsTest.java | 20 +++++------ .../asynchttpclient/async/ChunkingTest.java | 34 +++++++------------ .../async/FilePartLargeFileTest.java | 18 +++------- 4 files changed, 25 insertions(+), 49 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/FilePart.java b/api/src/main/java/org/asynchttpclient/FilePart.java index c5cc15860e..155d22a267 100644 --- a/api/src/main/java/org/asynchttpclient/FilePart.java +++ b/api/src/main/java/org/asynchttpclient/FilePart.java @@ -37,7 +37,7 @@ public FilePart(String name, File file, String mimeType, String charSet) { /** * {@inheritDoc} */ - /* @Override */ + @Override public String getName() { return name; } diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index c5f4ff36a4..88858870d9 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -17,11 +17,9 @@ import static org.testng.Assert.*; -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.ConnectException; -import java.net.URL; import java.security.KeyStore; import java.security.SecureRandom; import java.security.cert.CertificateException; @@ -38,6 +36,7 @@ import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import javax.servlet.ServletException; +import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -95,9 +94,9 @@ public void handle(String pathInContext, Request r, HttpServletRequest httpReque httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort()); - javax.servlet.http.Cookie[] cs = httpRequest.getCookies(); + Cookie[] cs = httpRequest.getCookies(); if (cs != null) { - for (javax.servlet.http.Cookie c : cs) { + for (Cookie c : cs) { httpResponse.addCookie(c); } } @@ -141,10 +140,7 @@ public void zeroCopyPostTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - URL url = getClass().getClassLoader().getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - Response resp = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get(); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), "This is a simple test file"); @@ -175,7 +171,7 @@ public void multipleSSLRequestsTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void multipleSSLWithoutCacheTest() throws Throwable { - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build()); + AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build()); try { String body = "hello there"; c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute(); @@ -193,9 +189,9 @@ public void multipleSSLWithoutCacheTest() throws Throwable { @Test(groups = { "standalone", "default_provider" }) public void reconnectsAfterFailedCertificationPath() throws Throwable { AtomicBoolean trusted = new AtomicBoolean(false); - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build()); + AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build()); try { - final String body = "hello there"; + String body = "hello there"; // first request fails because server certificate is rejected try { @@ -213,7 +209,7 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable { trusted.set(true); // second request should succeed - final Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS); assertEquals(response.getResponseBody(), body); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index f5ebf6ac05..52f8d00722 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -12,7 +12,6 @@ */ package org.asynchttpclient.async; -import static org.testng.Assert.assertNotNull; import static org.testng.AssertJUnit.*; import static org.testng.FileAssert.fail; @@ -21,7 +20,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; @@ -60,27 +58,19 @@ public void testCustomChunking() throws Throwable { builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000))); Request r = builder.build(); - Response res = null; - try { - ListenableFuture response = c.executeRequest(r); - res = response.get(); - assertNotNull(res.getResponseBodyAsStream()); - if (500 == res.getStatusCode()) { - System.out.println("=============="); - System.out.println("500 response from call"); - System.out.println("Headers:" + res.getHeaders()); - System.out.println("=============="); - System.out.flush(); - assertEquals("Should have 500 status code", 500, res.getStatusCode()); - assertTrue("Should have failed due to chunking", res.getHeader("X-Exception").contains("invalid.chunk.length")); - fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + res.getHeader("X-Exception")); - } else { - assertEquals(LARGE_IMAGE_BYTES, res.getResponseBodyAsBytes()); - } - } catch (Exception e) { - - fail("Exception Thrown:" + e.getMessage()); + Response response = c.executeRequest(r).get(); + if (500 == response.getStatusCode()) { + System.out.println("=============="); + System.out.println("500 response from call"); + System.out.println("Headers:" + response.getHeaders()); + System.out.println("=============="); + System.out.flush(); + assertEquals("Should have 500 status code", 500, response.getStatusCode()); + assertTrue("Should have failed due to chunking", response.getHeader("X-Exception").contains("invalid.chunk.length")); + fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception")); + } else { + assertEquals(LARGE_IMAGE_BYTES, response.getResponseBodyAsBytes()); } } finally { c.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index afca1d2a79..dd87e925d5 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletResponse; import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.FilePart; import org.asynchttpclient.Response; @@ -34,14 +33,9 @@ public abstract class FilePartLargeFileTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutImageFile() throws Exception { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build(); - AsyncHttpClient client = getAsyncHttpClient(config); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build()); try { - BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - - rb.addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")); - - Response response = rb.execute().get(); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(); Assert.assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -51,15 +45,11 @@ public void testPutImageFile() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeTextFile() throws Exception { long repeats = (1024 * 1024 / PATTERN_BYTES.length) + 1; - File largeFile = createTempFile(PATTERN_BYTES, (int) repeats); + File file = createTempFile(PATTERN_BYTES, (int) repeats); AsyncHttpClient client = getAsyncHttpClient(null); try { - BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - - rb.addBodyPart(new FilePart("test", largeFile, "application/octet-stream", "UTF-8")); - - Response response = rb.execute().get(); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(); Assert.assertEquals(200, response.getStatusCode()); } finally { client.close(); From 3923fce3df0ad2b046d8546e300f6ec58c021872 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 5 Sep 2013 23:50:54 +0200 Subject: [PATCH 0107/2389] Minor clean up --- .../async/AsyncProvidersBasicTest.java | 342 +++++++++--------- .../async/BodyDeferringAsyncHandlerTest.java | 2 - .../async/PutLargeFileTest.java | 16 +- .../async/ZeroCopyFileTest.java | 90 ++--- 4 files changed, 202 insertions(+), 248 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index db340b74e4..09ea80bd7d 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -67,94 +67,92 @@ public abstract class AsyncProvidersBasicTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider", "async" }) public void asyncProviderEncodingTest() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "?q=+%20x").build(); String requestUrl = request.getUrl(); Assert.assertEquals(requestUrl, getTargetUrl() + "?q=%20%20x"); - Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { + + String url = client.executeRequest(request, new AsyncCompletionHandler() { @Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); Assert.fail("Unexpected exception: " + t.getMessage(), t); } - }); - String url = responseFuture.get(); + }).get(); Assert.assertEquals(url, getTargetUrl() + "?q=%20%20x"); } finally { - p.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncProviderEncodingTest2() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "").addQueryParameter("q", "a b").build(); - Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { + String url = client.executeRequest(request, new AsyncCompletionHandler() { @Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); Assert.fail("Unexpected exception: " + t.getMessage(), t); } - }); - String url = responseFuture.get(); + }).get(); Assert.assertEquals(url, getTargetUrl() + "?q=a%20b"); } finally { - p.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void emptyRequestURI() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); - Future responseFuture = p.executeRequest(request, new AsyncCompletionHandler() { + String url = client.executeRequest(request, new AsyncCompletionHandler() { @Override public String onCompleted(Response response) throws Exception { return response.getUri().toString(); } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); Assert.fail("Unexpected exception: " + t.getMessage(), t); } - }); - String url = responseFuture.get(); + }).get(); Assert.assertEquals(url, getTargetUrl()); } finally { - p.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncProviderContentLenghtGETTest() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); + final HttpURLConnection connection = (HttpURLConnection) new URL(getTargetUrl()).openConnection(); + connection.connect(); + final int ct = connection.getContentLength(); try { final CountDownLatch l = new CountDownLatch(1); - URL url = new URL(getTargetUrl()); - final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.connect(); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); - p.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -164,7 +162,6 @@ public Response onCompleted(Response response) throws Exception { if (response.getHeader("content-length") != null) { contentLenght = Integer.valueOf(response.getHeader("content-length")); } - int ct = connection.getContentLength(); assertEquals(contentLenght, ct); } finally { l.countDown(); @@ -187,17 +184,17 @@ public void onThrowable(Throwable t) { Assert.fail("Timeout out"); } } finally { - p.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncContentTypeGETTest() throws Throwable { - AsyncHttpClient p = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); - p.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -214,17 +211,17 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - p.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncHeaderGETTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); - n.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -242,13 +239,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - n.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncHeaderPOSTTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -259,7 +256,7 @@ public void asyncHeaderPOSTTest() throws Throwable { h.add("Test5", "Test5"); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).setHeaders(h).build(); - n.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -280,13 +277,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - n.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncParamPOSTTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -297,14 +294,13 @@ public void asyncParamPOSTTest() throws Throwable { m.put("param_" + i, Arrays.asList("value_" + i)); } Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setParameters(m).build(); - n.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { try { assertEquals(response.getStatusCode(), 200); for (int i = 1; i < 5; i++) { - System.out.println(">>>>> " + response.getHeader("X-param_" + i)); assertEquals(response.getHeader("X-param_" + i), "value_" + i); } @@ -319,17 +315,17 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - n.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncStatusHEADTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("HEAD").setUrl(getTargetUrl()).build(); - Response response = n.executeRequest(request, new AsyncCompletionHandlerAdapter() { + Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -353,19 +349,19 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - n.close(); + client.close(); } } // TODO: fix test @Test(groups = { "standalone", "default_provider", "async" }, enabled = false) public void asyncStatusHEADContentLenghtTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(120 * 1000).build()); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(120 * 1000).build()); try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("HEAD").setUrl(getTargetUrl()).build(); - n.executeRequest(request, new AsyncCompletionHandlerAdapter() { + client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { Assert.fail(); @@ -388,31 +384,31 @@ public void onThrowable(Throwable t) { Assert.fail("Timeout out"); } } finally { - n.close(); + client.close(); } } @Test(groups = { "online", "default_provider", "async" }) public void asyncNullSchemeTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - c.prepareGet("www.sun.com").execute(); + client.prepareGet("www.sun.com").execute(); Assert.fail(); } catch (IllegalArgumentException ex) { Assert.assertTrue(true); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoGetTransferEncodingTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); - c.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { + client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -430,13 +426,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoGetHeadersTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -445,7 +441,7 @@ public void asyncDoGetHeadersTest() throws Throwable { h.add("Test3", "Test3"); h.add("Test4", "Test4"); h.add("Test5", "Test5"); - c.prepareGet(getTargetUrl()).setHeaders(h).execute(new AsyncCompletionHandlerAdapter() { + client.prepareGet(getTargetUrl()).setHeaders(h).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -464,13 +460,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoGetCookieTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -481,7 +477,7 @@ public void asyncDoGetCookieTest() throws Throwable { h.add("Test5", "Test5"); final Cookie coo = new Cookie("/", "foo", "value", "/", -1, false); - c.prepareGet(getTargetUrl()).setHeaders(h).addCookie(coo).execute(new AsyncCompletionHandlerAdapter() { + client.prepareGet(getTargetUrl()).setHeaders(h).addCookie(coo).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -501,16 +497,16 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostDefaultContentType() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); - c.preparePost(getTargetUrl()).addParameter("foo", "bar").execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).addParameter("foo", "bar").execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -529,24 +525,24 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostBodyIsoTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = c.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(); - assertEquals(r.getResponseBody().getBytes("ISO-8859-1"), "\u017D\u017D\u017D\u017D\u017D\u017D".getBytes("ISO-8859-1")); + Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(); + assertEquals(response.getResponseBody().getBytes("ISO-8859-1"), "\u017D\u017D\u017D\u017D\u017D\u017D".getBytes("ISO-8859-1")); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostBytesTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -561,7 +557,7 @@ public void asyncDoPostBytesTest() throws Throwable { } sb.setLength(sb.length() - 1); - c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -583,13 +579,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostInputStreamTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -605,7 +601,7 @@ public void asyncDoPostInputStreamTest() throws Throwable { sb.setLength(sb.length() - 1); ByteArrayInputStream is = new ByteArrayInputStream(sb.toString().getBytes()); - c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -626,13 +622,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPutInputStreamTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -648,7 +644,7 @@ public void asyncDoPutInputStreamTest() throws Throwable { sb.setLength(sb.length() - 1); ByteArrayInputStream is = new ByteArrayInputStream(sb.toString().getBytes()); - c.preparePut(getTargetUrl()).setHeaders(h).setBody(is).execute(new AsyncCompletionHandlerAdapter() { + client.preparePut(getTargetUrl()).setHeaders(h).setBody(is).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -669,19 +665,19 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostMultiPartTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); Part p = new StringPart("foo", "bar"); - c.preparePost(getTargetUrl()).addBodyPart(p).execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).addBodyPart(p).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -701,14 +697,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostBasicGZIPTest() throws Throwable { - AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build(); - AsyncHttpClient c = getAsyncHttpClient(cf); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build()); try { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -723,7 +718,7 @@ public void asyncDoPostBasicGZIPTest() throws Throwable { } sb.setLength(sb.length() - 1); - c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { @@ -740,14 +735,13 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Timeout out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostProxyTest() throws Throwable { - AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port2)).build(); - AsyncHttpClient c = getAsyncHttpClient(cf); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port2)).build()); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -761,7 +755,7 @@ public void asyncDoPostProxyTest() throws Throwable { } sb.setLength(sb.length() - 1); - Response response = c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandler() { + Response response = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandler() { @Override public Response onCompleted(Response response) throws Exception { return response; @@ -775,13 +769,13 @@ public void onThrowable(Throwable t) { assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-Proxy-Connection"), "keep-alive"); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncRequestVirtualServerPOSTTest() throws Throwable { - AsyncHttpClient n = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -792,7 +786,7 @@ public void asyncRequestVirtualServerPOSTTest() throws Throwable { } Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setParameters(m).setVirtualHost("localhost:" + port1).build(); - Response response = n.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(); + Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(); assertEquals(response.getStatusCode(), 200); if (response.getHeader("X-Host").startsWith("localhost")) { @@ -801,13 +795,13 @@ public void asyncRequestVirtualServerPOSTTest() throws Throwable { assertEquals(response.getHeader("X-Host"), "127.0.0.1:" + port1); } } finally { - n.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPutTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -821,11 +815,11 @@ public void asyncDoPutTest() throws Throwable { } sb.setLength(sb.length() - 1); - Response response = c.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(); + Response response = client.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(); assertEquals(response.getStatusCode(), 200); } finally { - c.close(); + client.close(); } } @@ -874,7 +868,7 @@ public Response onCompleted(Response response) throws Exception { @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostDelayCancelTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -882,7 +876,7 @@ public void asyncDoPostDelayCancelTest() throws Throwable { StringBuilder sb = new StringBuilder(); sb.append("LockThread=true"); - Future future = c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { } @@ -891,13 +885,13 @@ public void onThrowable(Throwable t) { Response response = future.get(TIMEOUT, TimeUnit.SECONDS); Assert.assertNull(response); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostDelayBytesTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -906,7 +900,7 @@ public void asyncDoPostDelayBytesTest() throws Throwable { sb.append("LockThread=true"); try { - Future future = c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { t.printStackTrace(); @@ -924,14 +918,14 @@ public void onThrowable(Throwable t) { Assert.assertTrue(false); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostNullBytesTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -945,19 +939,19 @@ public void asyncDoPostNullBytesTest() throws Throwable { } sb.setLength(sb.length() - 1); - Future future = c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()); + Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()); Response response = future.get(); Assert.assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostListenerBytesTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -973,7 +967,7 @@ public void asyncDoPostListenerBytesTest() throws Throwable { final CountDownLatch l = new CountDownLatch(1); - c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { try { @@ -989,20 +983,20 @@ public Response onCompleted(Response response) throws Exception { Assert.fail("Latch time out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncConnectInvalidFuture() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { int dummyPort = findFreePort(); final AtomicInteger count = new AtomicInteger(); for (int i = 0; i < 20; i++) { try { - Response response = c.preparePost(String.format("http://127.0.0.1:%d/", dummyPort)).execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + Response response = client.preparePost(String.format("http://127.0.0.1:%d/", dummyPort)).execute(new AsyncCompletionHandlerAdapter() { + @Override public void onThrowable(Throwable t) { count.incrementAndGet(); } @@ -1017,18 +1011,18 @@ public void onThrowable(Throwable t) { } assertEquals(count.get(), 20); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncConnectInvalidPortFuture() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { int dummyPort = findFreePort(); try { - Response response = c.preparePost(String.format("http://127.0.0.1:%d/", dummyPort)).execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + Response response = client.preparePost(String.format("http://127.0.0.1:%d/", dummyPort)).execute(new AsyncCompletionHandlerAdapter() { + @Override public void onThrowable(Throwable t) { t.printStackTrace(); } @@ -1041,20 +1035,20 @@ public void onThrowable(Throwable t) { } } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncConnectInvalidPort() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { // pick a random unused local port int port = findFreePort(); try { - Response response = c.preparePost(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + Response response = client.preparePost(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { + @Override public void onThrowable(Throwable t) { t.printStackTrace(); } @@ -1064,19 +1058,19 @@ public void onThrowable(Throwable t) { assertEquals(ex.getCause().getClass(), ConnectException.class); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncConnectInvalidHandlerPort() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); int port = findFreePort(); - c.prepareGet(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + client.prepareGet(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { + @Override public void onThrowable(Throwable t) { try { assertEquals(t.getClass(), ConnectException.class); @@ -1090,18 +1084,18 @@ public void onThrowable(Throwable t) { Assert.fail("Timed out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "online", "default_provider", "async" }) public void asyncConnectInvalidHandlerHost() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); - c.prepareGet("http://null.apache.org:9999/").execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + client.prepareGet("http://null.apache.org:9999/").execute(new AsyncCompletionHandlerAdapter() { + @Override public void onThrowable(Throwable t) { if (t != null) { if (t.getClass().equals(ConnectException.class)) { @@ -1117,13 +1111,13 @@ public void onThrowable(Throwable t) { Assert.fail("Timed out"); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncConnectInvalidFuturePort() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicBoolean called = new AtomicBoolean(false); final AtomicBoolean rightCause = new AtomicBoolean(false); @@ -1131,7 +1125,7 @@ public void asyncConnectInvalidFuturePort() throws Throwable { int port = findFreePort(); try { - Response response = c.prepareGet(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { + Response response = client.prepareGet(String.format("http://127.0.0.1:%d/", port)).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { called.set(true); @@ -1147,15 +1141,15 @@ public void onThrowable(Throwable t) { assertTrue(called.get(), "onThrowable should get called."); assertTrue(rightCause.get(), "onThrowable should get called with ConnectionException"); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncContentLenghtGETTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = c.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { + Response response = client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { @@ -1166,15 +1160,15 @@ public void onThrowable(Throwable t) { Assert.assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncResponseBodyTooLarge() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = c.preparePost(getTargetUrl()).setBody("0123456789").execute(new AsyncCompletionHandlerAdapter() { + Response response = client.preparePost(getTargetUrl()).setBody("0123456789").execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { @@ -1184,15 +1178,15 @@ public void onThrowable(Throwable t) { Assert.assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE)); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncResponseEmptyBody() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = c.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { + Response response = client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { @@ -1202,7 +1196,7 @@ public void onThrowable(Throwable t) { assertEquals(response.getResponseBody(), ""); } finally { - c.close(); + client.close(); } } @@ -1467,10 +1461,8 @@ public void onThrowable(Throwable t) { public void asyncDoGetStreamAndBodyTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareGet("http://www.google.com/").execute().get(); - - r.getResponseBody(); - r.getResponseBodyAsStream(); + Response response = client.prepareGet("http://www.google.com/").execute().get(); + assertEquals(response.getStatusCode(), 200); } finally { client.close(); } @@ -1480,10 +1472,8 @@ public void asyncDoGetStreamAndBodyTest() throws Throwable { public void asyncUrlWithoutPathTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareGet("http://www.google.com/").execute().get(); - - r.getResponseBody(); - r.getResponseBodyAsStream(); + Response response = client.prepareGet("http://www.google.com/").execute().get(); + assertEquals(response.getStatusCode(), 200); } finally { client.close(); } @@ -1493,10 +1483,10 @@ public void asyncUrlWithoutPathTest() throws Throwable { public void optionsTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareOptions(getTargetUrl()).execute().get(); + Response response = client.prepareOptions(getTargetUrl()).execute().get(); - assertEquals(r.getStatusCode(), 200); - assertEquals(r.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE"); + assertEquals(response.getStatusCode(), 200); + assertEquals(response.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE"); } finally { client.close(); } @@ -1504,38 +1494,38 @@ public void optionsTest() throws Throwable { @Test(groups = { "online", "default_provider" }) public void testAwsS3() throws Exception { - final AsyncHttpClient c = getAsyncHttpClient(null); + final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = c.prepareGet("http://test.s3.amazonaws.com/").execute().get(); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { assertEquals(response.getStatusCode(), 403); } } finally { - c.close(); + client.close(); } } @Test(groups = { "online", "default_provider" }) public void testAsyncHttpProviderConfig() throws Exception { - final AsyncHttpClient c = getAsyncHttpClient(new Builder().setAsyncHttpClientProviderConfig(getProviderConfig()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setAsyncHttpClientProviderConfig(getProviderConfig()).build()); try { - Response response = c.prepareGet("http://test.s3.amazonaws.com/").execute().get(); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { assertEquals(response.getStatusCode(), 403); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider" }) public void idleRequestTimeoutTest() throws Exception { - AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(5000).setRequestTimeoutInMs(10000).build()); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(5000).setRequestTimeoutInMs(10000).build()); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -1543,7 +1533,7 @@ public void idleRequestTimeoutTest() throws Exception { long t1 = millisTime(); try { - c.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); + client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); Assert.fail(); } catch (Throwable ex) { final long elapsedTime = millisTime() - t1; @@ -1552,14 +1542,14 @@ public void idleRequestTimeoutTest() throws Exception { Assert.assertTrue(elapsedTime >= 10000 && elapsedTime <= 25000); } } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) public void asyncDoPostCancelTest() throws Throwable { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -1570,7 +1560,7 @@ public void asyncDoPostCancelTest() throws Throwable { final AtomicReference ex = new AtomicReference(); ex.set(null); try { - Future future = c.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { + Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { @@ -1588,27 +1578,27 @@ public void onThrowable(Throwable t) { } Assert.assertNotNull(ex.get()); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider" }) public void getShouldAllowBody() throws IllegalArgumentException, IOException { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - c.prepareGet(getTargetUrl()).setBody("Boo!").execute(); + client.prepareGet(getTargetUrl()).setBody("Boo!").execute(); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider" }, expectedExceptions = IllegalArgumentException.class) public void headShouldNotAllowBody() throws IllegalArgumentException, IOException { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - c.prepareHead(getTargetUrl()).setBody("Boo!").execute(); + client.prepareHead(getTargetUrl()).setBody("Boo!").execute(); } finally { - c.close(); + client.close(); } } @@ -1618,23 +1608,23 @@ protected String getBrokenTargetUrl() { @Test(groups = { "standalone", "default_provider" }) public void invalidUri() throws Exception { - AsyncHttpClient c = getAsyncHttpClient(null); + AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = c.executeRequest(c.prepareGet(getBrokenTargetUrl()).build()).get(); - assertEquals(200, r.getStatusCode()); + Response response = client.executeRequest(client.prepareGet(getBrokenTargetUrl()).build()).get(); + assertEquals(200, response.getStatusCode()); } finally { - c.close(); + client.close(); } } @Test(groups = { "standalone", "default_provider" }) public void asyncHttpClientConfigBeanTest() throws Exception { - AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test")); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test")); try { - Response r = c.executeRequest(c.prepareGet(getTargetUrl()).build()).get(); - assertEquals(200, r.getStatusCode()); + Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(); + assertEquals(200, response.getStatusCode()); } finally { - c.close(); + client.close(); } } @@ -1642,9 +1632,9 @@ public void asyncHttpClientConfigBeanTest() throws Exception { public void bodyAsByteTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareGet(getTargetUrl()).execute().get(); - assertEquals(r.getStatusCode(), 200); - assertEquals(r.getResponseBodyAsBytes(), new byte[] {}); + Response response = client.prepareGet(getTargetUrl()).execute().get(); + assertEquals(response.getStatusCode(), 200); + assertEquals(response.getResponseBodyAsBytes(), new byte[] {}); } finally { client.close(); } @@ -1654,9 +1644,9 @@ public void bodyAsByteTest() throws Throwable { public void mirrorByteTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); - assertEquals(r.getStatusCode(), 200); - assertEquals(new String(r.getResponseBodyAsBytes(), "UTF-8"), "MIRROR"); + Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); + assertEquals(response.getStatusCode(), 200); + assertEquals(new String(response.getResponseBodyAsBytes(), "UTF-8"), "MIRROR"); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java index cf8a8c9934..64dda4e63f 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java @@ -46,8 +46,6 @@ public static class SlowAndBigHandler extends AbstractHandler { public void handle(String pathInContext, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { - // 512MB large download - // 512 * 1024 * 1024 = 536870912 httpResponse.setStatus(200); httpResponse.setContentLength(HALF_GIG); httpResponse.setContentType("application/octet-stream"); diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index 7dee570d97..88af885b2d 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -20,7 +20,6 @@ import javax.servlet.http.HttpServletResponse; import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; @@ -41,14 +40,9 @@ public void testPutLargeFile() throws Exception { int timeout = (int) (repeats / 1000); - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build(); - AsyncHttpClient client = getAsyncHttpClient(config); + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); try { - BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - - rb.setBody(file); - - Response response = rb.execute().get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); Assert.assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -63,11 +57,7 @@ public void testPutSmallFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - BoundRequestBuilder rb = client.preparePut(getTargetUrl()); - - rb.setBody(file); - - Response response = rb.execute().get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); Assert.assertEquals(200, response.getStatusCode()); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java index c11a3ea5dc..1394542177 100644 --- a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java @@ -12,34 +12,31 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncCompletionHandler; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URISyntaxException; -import java.net.URL; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncCompletionHandler; +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; /** * Zero copy test which use FileChannel.transfer under the hood . The same SSL test is also covered in {@link BasicHttpsTest} @@ -68,14 +65,10 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ public void zeroCopyPostTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException { AsyncHttpClient client = getAsyncHttpClient(null); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); final AtomicBoolean headerSent = new AtomicBoolean(false); final AtomicBoolean operationCompleted = new AtomicBoolean(false); - Future f = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(file).execute(new AsyncCompletionHandler() { + Response resp = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncCompletionHandler() { public STATE onHeaderWriteCompleted() { headerSent.set(true); @@ -91,8 +84,7 @@ public STATE onContentWriteCompleted() { public Response onCompleted(Response response) throws Exception { return response; } - }); - Response resp = f.get(); + }).get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), "This is a simple test file"); @@ -107,12 +99,7 @@ public Response onCompleted(Response response) throws Exception { public void zeroCopyPutTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException { AsyncHttpClient client = getAsyncHttpClient(null); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setBody(file).execute(); + Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(); Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); @@ -130,16 +117,11 @@ public AbstractHandler configureHandler() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void zeroCopyFileTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException { AsyncHttpClient client = getAsyncHttpClient(null); + File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt"); + tmp.deleteOnExit(); + final FileOutputStream stream = new FileOutputStream(tmp); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt"); - tmp.deleteOnExit(); - final FileOutputStream stream = new FileOutputStream(tmp); - Future f = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(file).execute(new AsyncHandler() { + Response resp = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler() { public void onThrowable(Throwable t) { } @@ -159,12 +141,11 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }); - Response resp = f.get(); - stream.close(); + }).get(); assertNull(resp); - assertEquals(file.length(), tmp.length()); + assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { + stream.close(); client.close(); } } @@ -172,16 +153,12 @@ public Response onCompleted() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void zeroCopyFileWithBodyManipulationTest() throws IOException, ExecutionException, TimeoutException, InterruptedException, URISyntaxException { AsyncHttpClient client = getAsyncHttpClient(null); + File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt"); + tmp.deleteOnExit(); + final FileOutputStream stream = new FileOutputStream(tmp); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - File tmp = new File(System.getProperty("java.io.tmpdir") + File.separator + "zeroCopy.txt"); - tmp.deleteOnExit(); - final FileOutputStream stream = new FileOutputStream(tmp); - Future f = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(file).execute(new AsyncHandler() { + + Response resp = client.preparePost("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(new AsyncHandler() { public void onThrowable(Throwable t) { } @@ -206,12 +183,11 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }); - Response resp = f.get(); - stream.close(); + }).get(); assertNull(resp); - assertEquals(file.length(), tmp.length()); + assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { + stream.close(); client.close(); } } From c822f15a9162e873c119ad5ebd23a187bc52923b Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 10:22:52 +0200 Subject: [PATCH 0108/2389] Properly handle response once we've receive LastHttpContent --- .../async/AsyncProvidersBasicTest.java | 6 +- .../providers/netty4/NettyChannelHandler.java | 310 +++++++++--------- .../providers/netty4/NettyResponseFuture.java | 19 +- 3 files changed, 166 insertions(+), 169 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 09ea80bd7d..67c3dfab58 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1602,15 +1602,11 @@ public void headShouldNotAllowBody() throws IllegalArgumentException, IOExceptio } } - protected String getBrokenTargetUrl() { - return String.format("http:127.0.0.1:%d/foo/test", port1); - } - @Test(groups = { "standalone", "default_provider" }) public void invalidUri() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.executeRequest(client.prepareGet(getBrokenTargetUrl()).build()).get(); + Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(); assertEquals(200, response.getStatusCode()); } finally { client.close(); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index c78e3aef06..1e59dc2aab 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHandler.STATE; @@ -91,9 +92,7 @@ public void channelRead(final ChannelHandlerContext ctx, Object e) throws Except Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); NettyResponseFuture future = (NettyResponseFuture) attribute; - if (!(future.isIgnoreNextContents() && e instanceof HttpContent)) { - p.handle(ctx, future, e); - } + p.handle(ctx, future, e); } else if (attribute != DiscardEvent.INSTANCE) { try { @@ -490,12 +489,140 @@ private boolean applyResponseFiltersAndReplayRequest(ChannelHandlerContext ctx, // The request has changed if (fc.replayRequest()) { requestSender.replayRequest(future, fc, ctx); - future.setIgnoreNextContents(true); replayed = true; } return replayed; } + private boolean handleResponseAndExit(final ChannelHandlerContext ctx, final NettyResponseFuture future, AsyncHandler handler, HttpRequest nettyRequest, + ProxyServer proxyServer, HttpResponse response) throws Exception { + Request request = future.getRequest(); + int statusCode = response.getStatus().code(); + HttpResponseStatus status = new ResponseStatus(future.getURI(), response); + HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); + final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); + final RequestBuilder builder = new RequestBuilder(future.getRequest()); + Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); + + // store the original headers so we can re-send all them to + // the handler in case of trailing headers + future.setHttpResponse(response); + + future.setKeepAlive(!HttpHeaders.Values.CLOSE.equalsIgnoreCase(response.headers().get(HttpHeaders.Names.CONNECTION))); + + if (!config.getResponseFilters().isEmpty() && applyResponseFiltersAndReplayRequest(ctx, future, status, responseHeaders)) { + return true; + } + + // FIXME handle without returns + if (statusCode == UNAUTHORIZED.code() && realm != null) { + List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); + if (!wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + // NTLM + boolean negociate = wwwAuth.contains("Negotiate"); + if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || negociate)) { + newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + return true; + } + } else { + newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()).setMethodName(request.getMethod()) + .setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); + } + + final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); + + LOGGER.debug("Sending authentication to {}", request.getUrl()); + Callback callback = new Callback(future) { + public void call() throws Exception { + channels.drainChannel(ctx, future); + requestSender.execute(builder.setHeaders(headers).setRealm(nr).build(), future); + } + }; + + if (future.isKeepAlive() && HttpHeaders.isTransferEncodingChunked(response)) { + // We must make sure there is no bytes left + // before executing the next request. + Channels.setDefaultAttribute(ctx, callback); + } else { + callback.call(); + } + + return true; + } + + } else if (statusCode == CONTINUE.code()) { + future.getAndSetWriteHeaders(false); + future.getAndSetWriteBody(true); + // FIXME is this necessary + requestSender.writeRequest(ctx.channel(), config, future); + return true; + + } else if (statusCode == PROXY_AUTHENTICATION_REQUIRED.code()) { + List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); + if (realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { + LOGGER.debug("Sending proxy authentication to {}", request.getUrl()); + + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + + boolean negociate = proxyAuth.contains("Negotiate"); + if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || negociate)) { + newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + return true; + } + } else { + newRealm = future.getRequest().getRealm(); + } + + future.setReuseChannel(true); + future.setConnectAllowed(true); + requestSender.execute(builder.setHeaders(headers).setRealm(newRealm).build(), future); + return true; + } + + } else if (statusCode == OK.code() && nettyRequest.getMethod() == HttpMethod.CONNECT) { + + LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); + + if (future.isKeepAlive()) { + future.attachChannel(ctx.channel(), true); + } + + try { + LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); + channels.upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); + } catch (Throwable ex) { + channels.abort(future, ex); + } + future.setReuseChannel(true); + future.setConnectAllowed(false); + requestSender.execute(builder.build(), future); + return true; + + } + + if (redirect(request, future, response, ctx)) { + return true; + } + + if (!future.getAndSetStatusReceived(true) && (handler.onStatusReceived(status) != STATE.CONTINUE || handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE)) { + finishUpdate(future, ctx, HttpHeaders.isTransferEncodingChunked(response)); + return true; + } + + return false; + } + @Override public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture future, final Object e) throws Exception { future.touch(); @@ -513,169 +640,46 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu try { if (e instanceof HttpResponse) { HttpResponse response = (HttpResponse) e; - LOGGER.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); + future.getPendingResponse().set(response); + return; + } - int statusCode = response.getStatus().code(); - HttpResponseStatus status = new ResponseStatus(future.getURI(), response); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); - final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); - final RequestBuilder builder = new RequestBuilder(future.getRequest()); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - // store the original headers so we can re-send all them to - // the handler in case of trailing headers - future.setHttpResponse(response); - future.setIgnoreNextContents(false); - - future.setKeepAlive(!HttpHeaders.Values.CLOSE.equalsIgnoreCase(response.headers().get(HttpHeaders.Names.CONNECTION))); - - if (!config.getResponseFilters().isEmpty() && applyResponseFiltersAndReplayRequest(ctx, future, status, responseHeaders)) { - return; - } - - // FIXME handle without returns - if (statusCode == UNAUTHORIZED.code() && realm != null) { - List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); - if (!wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { - future.setState(NettyResponseFuture.STATE.NEW); - Realm newRealm = null; - // NTLM - boolean negociate = wwwAuth.contains("Negotiate"); - if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || negociate)) { - newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (negociate) { - newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) { - future.setIgnoreNextContents(true); - return; - } - } else { - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()) - .setMethodName(request.getMethod()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); - } - - final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); - - LOGGER.debug("Sending authentication to {}", request.getUrl()); - Callback callback = new Callback(future) { - public void call() throws Exception { - channels.drainChannel(ctx, future); - requestSender.execute(builder.setHeaders(headers).setRealm(nr).build(), future); - } - }; - - if (future.isKeepAlive() && HttpHeaders.isTransferEncodingChunked(response)) { - // We must make sure there is no bytes left - // before executing the next request. - Channels.setDefaultAttribute(ctx, callback); - } else { - callback.call(); - } - - future.setIgnoreNextContents(true); - return; - } - - } else if (statusCode == CONTINUE.code()) { - future.getAndSetWriteHeaders(false); - future.getAndSetWriteBody(true); - // FIXME is this necessary - future.setIgnoreNextContents(true); - requestSender.writeRequest(ctx.channel(), config, future); - return; - - } else if (statusCode == PROXY_AUTHENTICATION_REQUIRED.code()) { - List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); - if (realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { - LOGGER.debug("Sending proxy authentication to {}", request.getUrl()); - - future.setState(NettyResponseFuture.STATE.NEW); - Realm newRealm = null; - - boolean negociate = proxyAuth.contains("Negotiate"); - if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || negociate)) { - newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (negociate) { - newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) { - future.setIgnoreNextContents(true); - return; - } - } else { - newRealm = future.getRequest().getRealm(); - } + if (e instanceof HttpContent) { - future.setReuseChannel(true); - future.setConnectAllowed(true); - future.setIgnoreNextContents(true); - requestSender.execute(builder.setHeaders(headers).setRealm(newRealm).build(), future); + AtomicReference responseRef = future.getPendingResponse(); + HttpResponse response = responseRef.getAndSet(null); + if (handler != null) { + if (response != null && handleResponseAndExit(ctx, future, handler, nettyRequest, proxyServer, response)) { return; } - } else if (statusCode == OK.code() && nettyRequest.getMethod() == HttpMethod.CONNECT) { + HttpContent chunk = (HttpContent) e; - LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); + boolean interrupt = false; + boolean last = chunk instanceof LastHttpContent; - if (future.isKeepAlive()) { - future.attachChannel(ctx.channel(), true); + // FIXME + // Netty 3 provider is broken: in case of trailing headers, + // onHeadersReceived should be called before + // updateBodyAndInterrupt + if (last) { + LastHttpContent lastChunk = (LastHttpContent) chunk; + HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); + if (!trailingHeaders.isEmpty()) { + interrupt = handler.onHeadersReceived(new ResponseHeaders(future.getURI(), future.getHttpResponse().headers(), trailingHeaders)) != STATE.CONTINUE; + } } - try { - LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); - channels.upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); - } catch (Throwable ex) { - channels.abort(future, ex); + if (!interrupt && chunk.content().readableBytes() > 0) { + // FIXME why + interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); } - future.setReuseChannel(true); - future.setConnectAllowed(false); - future.setIgnoreNextContents(true); - requestSender.execute(builder.build(), future); - return; - - } - - if (redirect(request, future, response, ctx)) { - future.setIgnoreNextContents(true); - return; - } - - if (!future.getAndSetStatusReceived(true) - && (handler.onStatusReceived(status) != STATE.CONTINUE || handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE)) { - finishUpdate(future, ctx, HttpHeaders.isTransferEncodingChunked(response)); - return; - } - } - - if (handler != null && e instanceof HttpContent) { - HttpContent chunk = (HttpContent) e; - - boolean interrupt = false; - boolean last = chunk instanceof LastHttpContent; - - // FIXME - // Netty 3 provider is broken: in case of trailing headers, - // onHeadersReceived should be called before - // updateBodyAndInterrupt - if (last) { - LastHttpContent lastChunk = (LastHttpContent) chunk; - HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); - if (!trailingHeaders.isEmpty()) { - interrupt = handler.onHeadersReceived(new ResponseHeaders(future.getURI(), future.getHttpResponse().headers(), trailingHeaders)) != STATE.CONTINUE; + if (interrupt || last) { + finishUpdate(future, ctx, !last); } } - - if (!interrupt && chunk.content().readableBytes() > 0) { - // FIXME why - interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); - } - - if (interrupt || last) { - finishUpdate(future, ctx, !last); - } } } catch (Exception t) { if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, IOException.class.cast(t))) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java index ba49de0338..f428295a3c 100755 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java @@ -54,7 +54,7 @@ public final class NettyResponseFuture extends AbstractListenableFuture { public enum STATE { NEW, POOLED, RECONNECTED, CLOSED, } - + private final CountDownLatch latch = new CountDownLatch(1); private final AtomicBoolean isDone = new AtomicBoolean(false); private final AtomicBoolean isCancelled = new AtomicBoolean(false); @@ -86,7 +86,7 @@ public enum STATE { private boolean allowConnect = false; private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy; private final ProxyServer proxyServer; - private final AtomicBoolean ignoreNextContents = new AtomicBoolean(false); + private final AtomicReference pendingResponse = new AtomicReference(); private final AtomicBoolean streamWasAlreadyConsumed = new AtomicBoolean(false); public NettyResponseFuture(URI uri,// @@ -288,8 +288,8 @@ public final void done() { } catch (ExecutionException t) { return; } catch (RuntimeException t) { - Throwable exception = t.getCause() != null ? t.getCause() : t; - exEx.compareAndSet(null, new ExecutionException(exception)); + Throwable exception = t.getCause() != null ? t.getCause() : t; + exEx.compareAndSet(null, new ExecutionException(exception)); } finally { latch.countDown(); @@ -383,14 +383,10 @@ public boolean getAndSetStatusReceived(boolean sr) { return statusReceived.getAndSet(sr); } - public void setIgnoreNextContents(boolean b) { - ignoreNextContents.set(b); + public AtomicReference getPendingResponse() { + return pendingResponse; } - public boolean isIgnoreNextContents() { - return ignoreNextContents.get(); - } - public boolean getAndSetStreamWasAlreadyConsumed() { return streamWasAlreadyConsumed.getAndSet(true); } @@ -455,7 +451,8 @@ public void setRequest(Request request) { } /** - * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can recover from that exception. + * Return true if the {@link Future} can be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can + * recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ From 91f3bfc8513fb75a4002a920d8f06995a5ebe086 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 10:34:01 +0200 Subject: [PATCH 0109/2389] As a French, I get redirected to google.fr, hence a 302 causing test to fail. French FTW! --- .../asynchttpclient/async/AsyncProvidersBasicTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 67c3dfab58..e450adf7f5 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1405,7 +1405,7 @@ public void onThrowable(Throwable t) { } }; - client.prepareGet("http://google.com/").execute(handler); + client.prepareGet("http://www.lemonde.fr/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { Assert.fail("Timed out"); @@ -1433,7 +1433,7 @@ public Response onCompleted(Response response) throws Exception { try { if (nestedCount.getAndIncrement() < MAX_NESTED) { System.out.println("Executing a nested request: " + nestedCount); - client.prepareGet("http://google.com/").execute(this); + client.prepareGet("http://www.lemonde.fr/").execute(this); } } finally { l.countDown(); @@ -1447,7 +1447,7 @@ public void onThrowable(Throwable t) { } }; - client.prepareGet("http://www.google.com/").execute(handler); + client.prepareGet("http://www.lemonde.fr/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { Assert.fail("Timed out"); @@ -1461,7 +1461,7 @@ public void onThrowable(Throwable t) { public void asyncDoGetStreamAndBodyTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.google.com/").execute().get(); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1472,7 +1472,7 @@ public void asyncDoGetStreamAndBodyTest() throws Throwable { public void asyncUrlWithoutPathTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.google.com/").execute().get(); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); From 79b80282137c9374c487b7769a3704c6d0881438 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 10:47:54 +0200 Subject: [PATCH 0110/2389] Upgrade Netty 3.7.0 --- providers/netty/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 0fcfd6850e..1e1cf573c8 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -17,7 +17,7 @@ io.netty netty - 3.6.6.Final + 3.7.0.Final From 25d59dcae58fa78e0c5a17881278e1ac470a85fd Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 11:59:19 +0200 Subject: [PATCH 0111/2389] Clean tests --- .../async/AbstractBasicTest.java | 2 +- .../asynchttpclient/async/BasicHttpsTest.java | 4 +- .../netty/RetryNonBlockingIssue.java | 242 +++++++---------- .../netty4/RetryNonBlockingIssue.java | 243 +++++++----------- 4 files changed, 193 insertions(+), 298 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java index 73a1d4c6d6..5ed7497bd8 100644 --- a/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AbstractBasicTest.java @@ -216,7 +216,7 @@ public void tearDownGlobal() throws Exception { server.stop(); } - protected int findFreePort() throws IOException { + protected synchronized int findFreePort() throws IOException { ServerSocket socket = null; try { diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index 88858870d9..cd7cdcb447 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -200,9 +200,9 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable { Throwable cause = e.getCause(); if (cause instanceof ConnectException) { assertNotNull(cause.getCause()); - assertTrue(cause.getCause() instanceof SSLHandshakeException); + assertTrue(cause.getCause() instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause.getCause()); } else { - assertTrue(cause instanceof SSLHandshakeException); + assertTrue(cause.getCause() instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause); } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java index f99aeade68..2cf3b30b15 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java @@ -12,29 +12,9 @@ */ package org.asynchttpclient.providers.netty; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; -import org.asynchttpclient.Request; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import static org.testng.Assert.assertTrue; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.net.ServerSocket; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -42,117 +22,98 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import static org.testng.Assert.assertTrue; - - -public class RetryNonBlockingIssue { - - private URI servletEndpointUri; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; - private Server server; +import junit.framework.Assert; - private int port1; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.asynchttpclient.async.AbstractBasicTest; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; - public static int findFreePort() throws IOException { - ServerSocket socket = null; +// FIXME there's no retry actually +public class RetryNonBlockingIssue extends AbstractBasicTest { - try { - // 0 is open a socket on any free port - socket = new ServerSocket(0); - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return NettyProviderUtil.nettyProvider(config); } - - @BeforeMethod - public void setUp() throws Exception { + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { server = new Server(); port1 = findFreePort(); Connector listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); + listener.setHost("localhost"); listener.setPort(port1); server.addConnector(listener); - - ServletContextHandler context = new - ServletContextHandler(ServletContextHandler.SESSIONS); - + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); - server.setHandler(context); - context.addServlet(new ServletHolder(new - MockExceptionServlet()), "/*"); + context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*"); + server.setHandler(context); server.start(); - - servletEndpointUri = new URI("http://127.0.0.1/" + port1 + "/"); } - @AfterMethod - public void stop() { - - try { - if (server != null) server.stop(); - } catch (Exception e) { - } - - + protected String getTargetUrl() { + return String.format("http://127.0.0.1:%d/", port1); } - private ListenableFuture testMethodRequest(AsyncHttpClient - fetcher, int requests, String action, String id) throws IOException { - RequestBuilder builder = new RequestBuilder("GET"); - builder.addQueryParameter(action, "1"); - - builder.addQueryParameter("maxRequests", "" + requests); - builder.addQueryParameter("id", id); - builder.setUrl(servletEndpointUri.toString()); - Request r = builder.build(); - return fetcher.executeRequest(r); - + private ListenableFuture testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException { + Request r = new RequestBuilder("GET")/**/ + .setUrl(getTargetUrl())/**/ + .addQueryParameter(action, "1")/**/ + .addQueryParameter("maxRequests", "" + requests)/**/ + .addQueryParameter("id", id)/**/ + .build(); + return client.executeRequest(r); } /** * Tests that a head request can be made - * + * * @throws IOException * @throws ExecutionException * @throws InterruptedException */ @Test - public void testRetryNonBlocking() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(60000); - bc.setRequestTimeoutInMs(30000); - - NettyAsyncHttpProviderConfig config = new - NettyAsyncHttpProviderConfig(); + public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException { - bc.setAsyncHttpClientProviderConfig(config); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .build(); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -163,37 +124,34 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @Test - public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); + public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException { - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(60000); - bc.setRequestTimeoutInMs(30000); - bc.setAsyncConnectMode(true); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .setAsyncConnectMode(true) /**/ + .build(); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -204,41 +162,37 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @Test - public void testRetryBlocking() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); + public void testRetryBlocking() throws IOException, InterruptedException, ExecutionException { - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(30000); - bc.setRequestTimeoutInMs(30000); + NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); + nettyConfig.setUseBlockingIO(true); - NettyAsyncHttpProviderConfig config = new - NettyAsyncHttpProviderConfig(); - config.setUseBlockingIO(true); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .setAsyncHttpClientProviderConfig(nettyConfig)/**/ + .build(); - bc.setAsyncHttpClientProviderConfig(config); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -250,17 +204,15 @@ public void testRetryBlocking() throws IOException, InterruptedException, System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @SuppressWarnings("serial") public class MockExceptionServlet extends HttpServlet { - private Map requests = new - ConcurrentHashMap(); + private Map requests = new ConcurrentHashMap(); private synchronized int increment(String id) { int val = 0; @@ -276,14 +228,12 @@ private synchronized int increment(String id) { return val; } - public void service(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String maxRequests = req.getParameter("maxRequests"); int max = 0; try { max = Integer.parseInt(maxRequests); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { max = 3; } String id = req.getParameter("id"); @@ -292,7 +242,6 @@ public void service(HttpServletRequest req, HttpServletResponse res) String io = req.getParameter("io"); String error = req.getParameter("500"); - if (requestNo >= max) { res.setHeader("Success-On-Attempt", "" + requestNo); res.setHeader("id", id); @@ -304,26 +253,25 @@ public void service(HttpServletRequest req, HttpServletResponse res) res.setHeader("type", "io"); res.setStatus(200); res.setContentLength(0); + res.flushBuffer(); return; } - res.setStatus(200); res.setContentLength(100); res.setContentType("application/octet-stream"); - res.flushBuffer(); + // error after flushing the status if (servlet != null && servlet.trim().length() > 0) throw new ServletException("Servlet Exception"); if (io != null && io.trim().length() > 0) throw new IOException("IO Exception"); - if (error != null && error.trim().length() > 0) + if (error != null && error.trim().length() > 0) { res.sendError(500, "servlet process was 500"); + } } - } } - diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java index 8b1aad25de..b964da6f38 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java @@ -12,30 +12,9 @@ */ package org.asynchttpclient.providers.netty4; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; -import org.asynchttpclient.Request; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import static org.testng.Assert.assertTrue; import java.io.IOException; -import java.net.ServerSocket; -import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -43,117 +22,98 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutionException; -import static org.testng.Assert.assertTrue; - - -public class RetryNonBlockingIssue { - - private URI servletEndpointUri; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; - private Server server; +import junit.framework.Assert; - private int port1; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.asynchttpclient.async.AbstractBasicTest; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; - public static int findFreePort() throws IOException { - ServerSocket socket = null; +//FIXME there's no retry actually +public class RetryNonBlockingIssue extends AbstractBasicTest { - try { - // 0 is open a socket on any free port - socket = new ServerSocket(0); - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return NettyProviderUtil.nettyProvider(config); } - - @BeforeMethod - public void setUp() throws Exception { + @BeforeClass(alwaysRun = true) + public void setUpGlobal() throws Exception { server = new Server(); port1 = findFreePort(); Connector listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); + listener.setHost("localhost"); listener.setPort(port1); server.addConnector(listener); - - ServletContextHandler context = new - ServletContextHandler(ServletContextHandler.SESSIONS); - + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); - server.setHandler(context); - context.addServlet(new ServletHolder(new - MockExceptionServlet()), "/*"); + context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*"); + server.setHandler(context); server.start(); - - servletEndpointUri = new URI("http://127.0.0.1/" + port1 + "/"); } - @AfterMethod - public void stop() { - - try { - if (server != null) server.stop(); - } catch (Exception e) { - } - - + protected String getTargetUrl() { + return String.format("http://127.0.0.1:%d/", port1); } - private ListenableFuture testMethodRequest(AsyncHttpClient - fetcher, int requests, String action, String id) throws IOException { - RequestBuilder builder = new RequestBuilder("GET"); - builder.addQueryParameter(action, "1"); - - builder.addQueryParameter("maxRequests", "" + requests); - builder.addQueryParameter("id", id); - builder.setUrl(servletEndpointUri.toString()); - Request r = builder.build(); - return fetcher.executeRequest(r); - + private ListenableFuture testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException { + Request r = new RequestBuilder("GET")/**/ + .setUrl(getTargetUrl())/**/ + .addQueryParameter(action, "1")/**/ + .addQueryParameter("maxRequests", "" + requests)/**/ + .addQueryParameter("id", id)/**/ + .build(); + return client.executeRequest(r); } /** * Tests that a head request can be made - * + * * @throws IOException * @throws ExecutionException * @throws InterruptedException */ @Test - public void testRetryNonBlocking() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); - - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(60000); - bc.setRequestTimeoutInMs(30000); + public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException { - NettyAsyncHttpProviderConfig config = new - NettyAsyncHttpProviderConfig(); - - bc.setAsyncHttpClientProviderConfig(config); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .build(); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -164,37 +124,34 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @Test - public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); + public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException { - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(60000); - bc.setRequestTimeoutInMs(30000); - bc.setAsyncConnectMode(true); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .setAsyncConnectMode(true) /**/ + .build(); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -205,41 +162,37 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @Test - public void testRetryBlocking() throws IOException, InterruptedException, - ExecutionException { - AsyncHttpClient c = null; - List> res = new - ArrayList>(); - try { - AsyncHttpClientConfig.Builder bc = - new AsyncHttpClientConfig.Builder(); + public void testRetryBlocking() throws IOException, InterruptedException, ExecutionException { - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsTotal(100); - bc.setConnectionTimeoutInMs(30000); - bc.setRequestTimeoutInMs(30000); + NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); + nettyConfig.setUseBlockingIO(true); - NettyAsyncHttpProviderConfig config = new - NettyAsyncHttpProviderConfig(); - config.setUseBlockingIO(true); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ + .setAllowPoolingConnection(true)/**/ + .setMaximumConnectionsTotal(100)/**/ + .setConnectionTimeoutInMs(60000)/**/ + .setRequestTimeoutInMs(30000)/**/ + .setAsyncHttpClientProviderConfig(nettyConfig)/**/ + .build(); - bc.setAsyncHttpClientProviderConfig(config); - c = new AsyncHttpClient(bc.build()); + AsyncHttpClient client = getAsyncHttpClient(config); + try { + List> res = new ArrayList>(); for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(c, 3, "servlet", UUID.randomUUID().toString())); + res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); } StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); + Assert.assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -251,17 +204,15 @@ public void testRetryBlocking() throws IOException, InterruptedException, System.out.println(b.toString()); System.out.flush(); - } - finally { - if (c != null) c.close(); + } finally { + client.close(); } } @SuppressWarnings("serial") public class MockExceptionServlet extends HttpServlet { - private Map requests = new - ConcurrentHashMap(); + private Map requests = new ConcurrentHashMap(); private synchronized int increment(String id) { int val = 0; @@ -277,14 +228,12 @@ private synchronized int increment(String id) { return val; } - public void service(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { + public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String maxRequests = req.getParameter("maxRequests"); int max = 0; try { max = Integer.parseInt(maxRequests); - } - catch (NumberFormatException e) { + } catch (NumberFormatException e) { max = 3; } String id = req.getParameter("id"); @@ -293,7 +242,6 @@ public void service(HttpServletRequest req, HttpServletResponse res) String io = req.getParameter("io"); String error = req.getParameter("500"); - if (requestNo >= max) { res.setHeader("Success-On-Attempt", "" + requestNo); res.setHeader("id", id); @@ -305,26 +253,25 @@ public void service(HttpServletRequest req, HttpServletResponse res) res.setHeader("type", "io"); res.setStatus(200); res.setContentLength(0); + res.flushBuffer(); return; } - res.setStatus(200); res.setContentLength(100); res.setContentType("application/octet-stream"); - res.flushBuffer(); + // error after flushing the status if (servlet != null && servlet.trim().length() > 0) throw new ServletException("Servlet Exception"); if (io != null && io.trim().length() > 0) throw new IOException("IO Exception"); - if (error != null && error.trim().length() > 0) + if (error != null && error.trim().length() > 0) { res.sendError(500, "servlet process was 500"); + } } - } } - From 0faeb285906702178caf52d67f018d639b8e36ae Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 12:04:50 +0200 Subject: [PATCH 0112/2389] Disable modules that don't pass tests --- providers/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/pom.xml b/providers/pom.xml index 9a7178b576..6892660321 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -44,9 +44,9 @@ - grizzly + netty - netty4 + From 0fba1a8bddc4e4b04b0094fb97f7fecba59814d0 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 12:47:29 +0200 Subject: [PATCH 0113/2389] Fix test --- .../org/asynchttpclient/async/AsyncProvidersBasicTest.java | 3 ++- providers/pom.xml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index e450adf7f5..029eeba72e 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1405,7 +1405,7 @@ public void onThrowable(Throwable t) { } }; - client.prepareGet("http://www.lemonde.fr/").execute(handler); + client.prepareGet("http://www.google.com/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { Assert.fail("Timed out"); @@ -1419,6 +1419,7 @@ public void onThrowable(Throwable t) { public void asyncDoGetNestedTest() throws Throwable { final AsyncHttpClient client = getAsyncHttpClient(null); try { + // FIXME find a proper website that redirects the same number of times whatever the language // Use a l in case the assert fail final CountDownLatch l = new CountDownLatch(2); diff --git a/providers/pom.xml b/providers/pom.xml index 6892660321..1d46aa0a76 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -44,7 +44,7 @@ - + grizzly netty From fd5f02c2bb64d0d83b32464276562cb7e50d2fc6 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 13:11:48 +0200 Subject: [PATCH 0114/2389] Upgrade Netty 4.0.9 --- providers/netty4/pom.xml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/providers/netty4/pom.xml b/providers/netty4/pom.xml index 551ae89a35..90a29ea432 100644 --- a/providers/netty4/pom.xml +++ b/providers/netty4/pom.xml @@ -13,6 +13,16 @@ + + sonatype-releases + https://oss.sonatype.org/content/repositories/releases + + true + + + false + + sonatype-snapshots https://oss.sonatype.org/content/repositories/snapshots @@ -29,7 +39,7 @@ io.netty netty-all - 4.0.9.Final-SNAPSHOT + 4.0.9.Final org.javassist From 48b67af016a4aa1395d5eb3a147bdc7cefb61e8d Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 18:14:29 +0200 Subject: [PATCH 0115/2389] Minor comment --- .../java/org/asynchttpclient/providers/netty4/Channels.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index 7f866c7924..b3f5cf2d86 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -257,6 +257,7 @@ protected void initChannel(Channel ch) throws Exception { try { pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); } catch (Throwable ex) { + LOGGER.error("Channel {} could not add SslHandler {}", ch, ex); abort(future, ex); } @@ -283,6 +284,7 @@ protected void initChannel(Channel ch) throws Exception { try { pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); } catch (Throwable ex) { + LOGGER.error("Channel {} could not add SslHandler {}", ch, ex); abort(future, ex); } @@ -305,6 +307,7 @@ private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException return sslEngine; } + // FIXME what for? public Channel verifyChannelPipeline(Channel channel, String scheme) throws IOException, GeneralSecurityException { if (channel.pipeline().get(SSL_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { From 8c2caa21db843ec7e1515714be885b89fa6e043e Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 18:17:48 +0200 Subject: [PATCH 0116/2389] Remove check about being in an IO thread --- .../org/asynchttpclient/providers/netty4/Constants.java | 3 --- .../providers/netty4/NettyChannelHandler.java | 2 -- .../providers/netty4/NettyRequestSender.java | 7 +------ 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java index 9fae1fbd2b..1565673ff1 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java @@ -4,9 +4,6 @@ public class Constants { - // FIXME move into a state class along with closed - public static final ThreadLocal IN_IO_THREAD = new ThreadLocalBoolean(); - // FIXME what to do with this??? public final static int MAX_BUFFERED_BYTES = 8192; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index 1e59dc2aab..95a3b5a834 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -77,8 +77,6 @@ public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requ @Override public void channelRead(final ChannelHandlerContext ctx, Object e) throws Exception { - Constants.IN_IO_THREAD.set(Boolean.TRUE); - Object attribute = Channels.getDefaultAttribute(ctx); if (attribute instanceof Callback) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java index cb0810143b..2f0ce718c1 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java @@ -218,13 +218,8 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl return cl.future(); } - // FIXME when can we have a direct invokation??? - // boolean directInvokation = !(IN_IO_THREAD.get() && - // DefaultChannelFuture.isUseDeadLockChecker()); - boolean directInvokation = !Constants.IN_IO_THREAD.get(); - // FIXME what does it have to do with the presence of a file? - if (directInvokation && !asyncConnect && request.getFile() == null) { + if (!asyncConnect && request.getFile() == null) { int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; if (!channelFuture.awaitUninterruptibly(timeOut, TimeUnit.MILLISECONDS)) { if (acquiredConnection) { From 898c4a4a52911624dbcc02f438770d3c77e19a27 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 20:52:47 +0200 Subject: [PATCH 0117/2389] Handshake is done automatically --- .../netty4/NettyConnectListener.java | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java index 57c54cdeef..052cf816a3 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java @@ -16,29 +16,26 @@ */ package org.asynchttpclient.providers.netty4; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.ssl.SslHandler; + import java.io.IOException; import java.net.ConnectException; import java.net.URI; import java.nio.channels.ClosedChannelException; -import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HostnameVerifier; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.ssl.SslHandler; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; import org.asynchttpclient.util.ProxyUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Non Blocking connect. @@ -50,7 +47,6 @@ final class NettyConnectListener implements ChannelFutureListener { private final AsyncHttpClientConfig config; private final NettyRequestSender requestSender; private final NettyResponseFuture future; - private final AtomicBoolean handshakeDone = new AtomicBoolean(false); private NettyConnectListener(AsyncHttpClientConfig config, NettyRequestSender requestSender, NettyResponseFuture future) { this.requestSender = requestSender; @@ -67,19 +63,7 @@ private void onFutureSuccess(final Channel channel) throws Exception { SslHandler sslHandler = Channels.getSslHandler(channel); if (sslHandler != null) { - if (!handshakeDone.getAndSet(true)) { - sslHandler.handshakeFuture().addListener(new GenericFutureListener>() { - public void operationComplete(Future f) throws Exception { - if (f.isSuccess()) { - onFutureSuccess(channel); - } else { - onFutureFailure(channel, f.cause()); - } - } - }); - return; - } - + // FIXME done on connect or on every request? HostnameVerifier v = config.getHostnameVerifier(); if (!v.verify(future.getURI().getHost(), sslHandler.engine().getSession())) { ConnectException exception = new ConnectException("HostnameVerifier exception."); From c86c289f5f23fc1f8eec07c296650126631e85ac Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 6 Sep 2013 22:16:24 +0200 Subject: [PATCH 0118/2389] Minor clean up --- .../java/org/asynchttpclient/async/AbstractBasicHttpsTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java index 3210dc9916..469f83f8c3 100644 --- a/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AbstractBasicHttpsTest.java @@ -27,9 +27,6 @@ public abstract class AbstractBasicHttpsTest extends AbstractBasicTest { protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractBasicHttpsTest.class); - protected Server server; - protected int port1; - protected int port2; @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { From 311aafafee4746afb770ffc54a6b318adcae2739 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sat, 7 Sep 2013 23:08:59 +0200 Subject: [PATCH 0119/2389] Close stream --- .../test/java/org/asynchttpclient/async/BasicHttpsTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index cd7cdcb447..18b35ae05d 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -40,6 +40,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.io.IOUtils; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig.Builder; import org.asynchttpclient.Response; @@ -218,8 +219,8 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable { } private static SSLContext createSSLContext(AtomicBoolean trusted) { + InputStream keyStoreStream = BasicHttpsTest.class.getResourceAsStream("ssltest-cacerts.jks"); try { - InputStream keyStoreStream = BasicHttpsTest.class.getResourceAsStream("ssltest-cacerts.jks"); char[] keyStorePassword = "changeit".toCharArray(); KeyStore ks = KeyStore.getInstance("JKS"); ks.load(keyStoreStream, keyStorePassword); @@ -240,6 +241,8 @@ private static SSLContext createSSLContext(AtomicBoolean trusted) { return sslContext; } catch (Exception e) { throw new Error("Failed to initialize the server-side SSLContext", e); + } finally { + IOUtils.closeQuietly(keyStoreStream); } } From 6c6ba66a3fb4f6af4fd536f2faa6d295ed013b36 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 16 Sep 2013 13:31:45 -0700 Subject: [PATCH 0120/2389] Ensure ordered logging of requests. --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index c91c1af7a6..6d9d684821 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -527,12 +527,18 @@ public boolean sendRequest(final FilterChainContext ctx, handler = new ExpectHandler(handler); } context.setBodyHandler(handler); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("REQUEST: {}", requestPacket); + } isWriteComplete = handler.doHandle(ctx, request, requestPacket); } else { HttpContent content = HttpContent.builder(requestPacket).last(true).build(); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("REQUEST: {}", requestPacket); + } ctx.write(content, ctx.getTransportContext().getCompletionHandler()); } - LOGGER.debug("REQUEST: {}", requestPacket); + return isWriteComplete; } From 6a7dec84477ac2714e0b75a2dfeba4e6bfce6606 Mon Sep 17 00:00:00 2001 From: oleksiys Date: Tue, 17 Sep 2013 16:47:30 -0700 Subject: [PATCH 0121/2389] + don't forget to shutdown the idlechecker thread --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 6d9d684821..c14e2309c4 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -192,6 +192,10 @@ public void close() { } if (timeoutExecutor != null) { timeoutExecutor.stop(); + final ExecutorService threadPool = timeoutExecutor.getThreadPool(); + if (threadPool != null) { + threadPool.shutdownNow(); + } } } catch (IOException ignored) { } From 3af32faec00daba80b325553ace77998ee10c458 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Sun, 15 Sep 2013 02:29:58 +0200 Subject: [PATCH 0122/2389] Upgrade Jetty 9 and clean tests --- .../util/AsyncHttpProviderUtils.java | 2 + .../java/org/asynchttpclient/RealmTest.java | 128 +++---- .../async/AbstractBasicHttpsTest.java | 32 +- .../async/AbstractBasicTest.java | 195 +---------- .../async/AsyncProvidersBasicTest.java | 315 ++++++++---------- .../async/AsyncStreamHandlerTest.java | 159 +++++---- .../async/AsyncStreamLifecycleTest.java | 44 ++- .../async/AuthTimeoutTest.java | 161 ++++----- .../asynchttpclient/async/BasicAuthTest.java | 305 +++++------------ .../asynchttpclient/async/BasicHttpsTest.java | 159 +-------- .../asynchttpclient/async/BodyChunkTest.java | 2 +- .../async/BodyDeferringAsyncHandlerTest.java | 94 +++--- .../async/ByteBufferCapacityTest.java | 57 +--- .../asynchttpclient/async/ChunkingTest.java | 22 +- .../async/ComplexClientTest.java | 12 +- .../async/ConnectionPoolTest.java | 36 +- .../asynchttpclient/async/DigestAuthTest.java | 117 ++----- .../asynchttpclient/async/EmptyBodyTest.java | 6 +- .../async/ErrorResponseTest.java | 3 +- .../async/Expect100ContinueTest.java | 43 ++- .../async/FilePartLargeFileTest.java | 53 +-- .../org/asynchttpclient/async/FilterTest.java | 24 +- .../FluentCaseInsensitiveStringsMapTest.java | 3 +- .../async/FluentStringsMapTest.java | 3 +- .../asynchttpclient/async/Head302Test.java | 41 +-- .../async/HostnameVerifierTest.java | 79 +---- .../async/HttpToHttpsRedirectTest.java | 48 +-- .../async/IdleStateHandlerTest.java | 17 +- .../async/InputStreamTest.java | 12 +- .../async/ListenableFutureTest.java | 2 +- .../async/MaxConnectionsInThreads.java | 67 ++-- .../async/MaxTotalConnectionTest.java | 16 +- .../async/MultipartUploadTest.java | 91 ++--- .../async/MultipleHeaderTest.java | 54 +-- .../async/NoNullResponseTest.java | 8 +- .../async/NonAsciiContentLengthTest.java | 35 +- .../async/PerRequestRelative302Test.java | 48 ++- .../async/PerRequestTimeoutTest.java | 10 +- .../async/PostRedirectGetTest.java | 26 +- .../async/ProxyTunnellingTest.java | 85 ++--- .../async/PutLargeFileTest.java | 16 +- .../async/QueryParametersTest.java | 4 +- .../org/asynchttpclient/async/RC10KTest.java | 41 +-- .../async/RedirectConnectionUsageTest.java | 73 ++-- .../async/Relative302Test.java | 103 +++--- .../asynchttpclient/async/RemoteSiteTest.java | 67 ++-- .../async/RetryRequestTest.java | 2 +- .../SimpleAsyncClientErrorBehaviourTest.java | 4 +- .../async/SimpleAsyncHttpClientTest.java | 30 +- .../async/TransferListenerTest.java | 28 +- .../async/WebDavBasicTest.java | 27 +- .../async/ZeroCopyFileTest.java | 5 +- .../async/util/EchoHandler.java | 103 ++++++ .../asynchttpclient/async/util/TestUtils.java | 253 ++++++++++++++ .../oauth/TestSignatureCalculator.java | 19 +- .../handler/codec/http/CookieDecoderTest.java | 28 +- .../util/AsyncHttpProviderUtilsTest.java | 10 +- .../asynchttpclient/util/ProxyUtilsTest.java | 12 +- .../util/TestUTF8UrlCodec.java | 10 +- .../websocket/AbstractBasicTest.java | 51 +-- .../websocket/ByteMessageTest.java | 67 +--- .../websocket/CloseCodeReasonMessageTest.java | 38 ++- .../asynchttpclient/websocket/EchoSocket.java | 52 +++ .../websocket/RedirectTest.java | 23 +- .../websocket/TextMessageTest.java | 69 +--- .../asynchttpclient/extra/AsyncHttpTest.java | 170 +++++----- pom.xml | 70 ++-- .../GrizzlyAsyncProviderBasicTest.java | 13 +- .../grizzly/GrizzlyBasicAuthTest.java | 15 +- .../GrizzlyByteBufferCapacityTest.java | 2 +- .../grizzly/GrizzlyConnectionPoolTest.java | 2 +- .../grizzly/GrizzlyPerRequestTimeoutTest.java | 2 +- .../GrizzlyRedirectConnectionUsageTest.java | 23 -- .../GrizzlyUnexpectingTimeoutTest.java | 30 +- .../websocket/GrizzlyByteMessageTest.java | 1 - .../GrizzlyCloseCodeReasonMsgTest.java | 7 - .../websocket/GrizzlyTextMessageTest.java | 9 - .../netty/NettyAsyncHttpProvider.java | 1 + .../providers/netty/NettyWebSocket.java | 6 + .../netty/NettyAsyncHttpProviderTest.java | 12 +- .../netty/NettyAsyncProviderPipelineTest.java | 21 +- .../providers/netty/NettyBasicAuthTest.java | 5 + .../netty/NettyMultipartUploadTest.java | 2 + .../NettyRedirectConnectionUsageTest.java | 11 - .../NettyRequestThrottleTimeoutTest.java | 4 +- .../netty/RetryNonBlockingIssue.java | 80 ++--- .../NettyCloseCodeReasonMsgTest.java | 1 - .../netty/websocket/NettyTextMessageTest.java | 2 + .../providers/netty4/Channels.java | 16 +- .../providers/netty4/NettyChannelHandler.java | 51 ++- .../providers/netty4/NettyWebSocket.java | 8 +- .../netty4/NettyAsyncHttpProviderTest.java | 19 -- .../NettyAsyncProviderPipelineTest.java | 7 +- .../netty4/NettyAuthTimeoutTest.java | 3 +- .../NettyRedirectConnectionUsageTest.java | 10 - .../NettyRequestThrottleTimeoutTest.java | 4 +- .../netty4/RetryNonBlockingIssue.java | 75 ++--- .../NettyCloseCodeReasonMsgTest.java | 1 - .../netty4/websocket/NettyRedirectTest.java | 1 - providers/pom.xml | 2 +- 100 files changed, 1864 insertions(+), 2571 deletions(-) create mode 100644 api/src/test/java/org/asynchttpclient/async/util/EchoHandler.java create mode 100644 api/src/test/java/org/asynchttpclient/async/util/TestUtils.java create mode 100644 api/src/test/java/org/asynchttpclient/websocket/EchoSocket.java diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index 06a29c0bce..a98cd8a33b 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -379,6 +379,8 @@ public final static MultipartRequestEntity createMultipartRequestEntity(List e = httpRequest.getHeaderNames(); - String param; - while (e.hasMoreElements()) { - param = e.nextElement().toString(); - - if (param.startsWith("LockThread")) { - try { - Thread.sleep(40 * 1000); - } catch (InterruptedException ex) { - } - } - - if (param.startsWith("X-redirect")) { - httpResponse.sendRedirect(httpRequest.getHeader("X-redirect")); - return; - } - httpResponse.addHeader("X-" + param, httpRequest.getHeader(param)); - } - - Enumeration i = httpRequest.getParameterNames(); - - StringBuilder requestBody = new StringBuilder(); - while (i.hasMoreElements()) { - param = i.nextElement().toString(); - httpResponse.addHeader("X-" + param, httpRequest.getParameter(param)); - requestBody.append(param); - requestBody.append("_"); - } - String pathInfo = httpRequest.getPathInfo(); - if (pathInfo != null) - httpResponse.addHeader("X-pathInfo", pathInfo); + protected final static int TIMEOUT = 30; - String queryString = httpRequest.getQueryString(); - if (queryString != null) - httpResponse.addHeader("X-queryString", queryString); + protected final Logger logger = LoggerFactory.getLogger(getClass()); - httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort()); - - Cookie[] cs = httpRequest.getCookies(); - if (cs != null) { - for (Cookie c : cs) { - httpResponse.addCookie(c); - } - } - - if (requestBody.length() > 0) { - httpResponse.getOutputStream().write(requestBody.toString().getBytes()); - } - - int size = 16384; - if (httpRequest.getContentLength() > 0) { - size = httpRequest.getContentLength(); - } - byte[] bytes = new byte[size]; - if (bytes.length > 0) { - int read = 0; - while (read > -1) { - read = httpRequest.getInputStream().read(bytes); - if (read > 0) { - httpResponse.getOutputStream().write(bytes, 0, read); - } - } - } - - httpResponse.setStatus(200); - httpResponse.getOutputStream().flush(); - httpResponse.getOutputStream().close(); - } - } + protected Server server; + protected int port1; + protected int port2; @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); port1 = findFreePort(); port2 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); - listener.setPort(port2); - - server.addConnector(listener); - + server = newJettyHttpServer(port1); server.setHandler(configureHandler()); + addHttpConnector(server, port2); server.start(); - log.info("Local HTTP server started successfully"); + + logger.info("Local HTTP server started successfully"); } @AfterClass(alwaysRun = true) @@ -216,20 +64,6 @@ public void tearDownGlobal() throws Exception { server.stop(); } - protected synchronized int findFreePort() throws IOException { - ServerSocket socket = null; - - try { - socket = new ServerSocket(0); - - return socket.getLocalPort(); - } finally { - if (socket != null) { - socket.close(); - } - } - } - protected String getTargetUrl() { return String.format("http://127.0.0.1:%d/foo/test", port1); } @@ -253,9 +87,8 @@ public Response onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } - } public static class AsyncHandlerAdapter implements AsyncHandler { @@ -263,7 +96,7 @@ public static class AsyncHandlerAdapter implements AsyncHandler { @Override public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } @Override diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 029eeba72e..9146be53aa 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -15,11 +15,9 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.asynchttpclient.util.DateUtil.millisTime; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -42,9 +40,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.testng.Assert; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -60,18 +55,16 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.StringPart; +import org.testng.annotations.Test; public abstract class AsyncProvidersBasicTest extends AbstractBasicTest { - private static final String UTF_8 = "text/html;charset=UTF-8"; - @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncProviderEncodingTest() throws Throwable { + public void asyncProviderEncodingTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "?q=+%20x").build(); - String requestUrl = request.getUrl(); - Assert.assertEquals(requestUrl, getTargetUrl() + "?q=%20%20x"); + assertEquals(request.getUrl(), getTargetUrl() + "?q=%20%20x"); String url = client.executeRequest(request, new AsyncCompletionHandler() { @Override @@ -82,18 +75,18 @@ public String onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } }).get(); - Assert.assertEquals(url, getTargetUrl() + "?q=%20%20x"); + assertEquals(url, getTargetUrl() + "?q=%20%20x"); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncProviderEncodingTest2() throws Throwable { + public void asyncProviderEncodingTest2() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "").addQueryParameter("q", "a b").build(); @@ -107,18 +100,18 @@ public String onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } }).get(); - Assert.assertEquals(url, getTargetUrl() + "?q=a%20b"); + assertEquals(url, getTargetUrl() + "?q=a%20b"); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void emptyRequestURI() throws Throwable { + public void emptyRequestURI() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); @@ -132,22 +125,23 @@ public String onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } }).get(); - Assert.assertEquals(url, getTargetUrl()); + assertEquals(url, getTargetUrl()); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncProviderContentLenghtGETTest() throws Throwable { + public void asyncProviderContentLenghtGETTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); final HttpURLConnection connection = (HttpURLConnection) new URL(getTargetUrl()).openConnection(); connection.connect(); final int ct = connection.getContentLength(); + connection.disconnect(); try { final CountDownLatch l = new CountDownLatch(1); @@ -172,7 +166,7 @@ public Response onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { try { - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } finally { l.countDown(); } @@ -181,7 +175,7 @@ public void onThrowable(Throwable t) { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -189,7 +183,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncContentTypeGETTest() throws Throwable { + public void asyncContentTypeGETTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -200,7 +194,7 @@ public void asyncContentTypeGETTest() throws Throwable { public Response onCompleted(Response response) throws Exception { try { assertEquals(response.getStatusCode(), 200); - assertEquals(response.getContentType(), UTF_8); + assertEquals(response.getContentType(), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); } finally { l.countDown(); } @@ -208,7 +202,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -216,7 +210,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncHeaderGETTest() throws Throwable { + public void asyncHeaderGETTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -227,7 +221,7 @@ public void asyncHeaderGETTest() throws Throwable { public Response onCompleted(Response response) throws Exception { try { assertEquals(response.getStatusCode(), 200); - assertEquals(response.getContentType(), UTF_8); + assertEquals(response.getContentType(), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); } finally { l.countDown(); } @@ -236,7 +230,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -244,7 +238,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncHeaderPOSTTest() throws Throwable { + public void asyncHeaderPOSTTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -261,7 +255,6 @@ public void asyncHeaderPOSTTest() throws Throwable { @Override public Response onCompleted(Response response) throws Exception { try { - System.out.println(">>>>> " + response.getStatusText()); assertEquals(response.getStatusCode(), 200); for (int i = 1; i < 5; i++) { assertEquals(response.getHeader("X-Test" + i), "Test" + i); @@ -274,7 +267,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -282,7 +275,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncParamPOSTTest() throws Throwable { + public void asyncParamPOSTTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -303,7 +296,6 @@ public Response onCompleted(Response response) throws Exception { for (int i = 1; i < 5; i++) { assertEquals(response.getHeader("X-param_" + i), "value_" + i); } - } finally { l.countDown(); } @@ -312,7 +304,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -320,7 +312,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncStatusHEADTest() throws Throwable { + public void asyncStatusHEADTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -340,13 +332,13 @@ public Response onCompleted(Response response) throws Exception { try { String s = response.getResponseBody(); - Assert.assertEquals("", s); + assertEquals("", s); } catch (IllegalStateException ex) { fail(); } if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -355,7 +347,7 @@ public Response onCompleted(Response response) throws Exception { // TODO: fix test @Test(groups = { "standalone", "default_provider", "async" }, enabled = false) - public void asyncStatusHEADContentLenghtTest() throws Throwable { + public void asyncStatusHEADContentLenghtTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(120 * 1000).build()); try { final CountDownLatch l = new CountDownLatch(1); @@ -364,7 +356,7 @@ public void asyncStatusHEADContentLenghtTest() throws Throwable { client.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { - Assert.fail(); + fail(); return response; } @@ -381,7 +373,7 @@ public void onThrowable(Throwable t) { }).get(); if (!l.await(10 * 5 * 1000, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -389,21 +381,21 @@ public void onThrowable(Throwable t) { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncNullSchemeTest() throws Throwable { + public void asyncNullSchemeTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { client.prepareGet("www.sun.com").execute(); - Assert.fail(); + fail(); } catch (IllegalArgumentException ex) { - Assert.assertTrue(true); + assertTrue(true); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetTransferEncodingTest() throws Throwable { + public void asyncDoGetTransferEncodingTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -423,7 +415,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -431,7 +423,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetHeadersTest() throws Throwable { + public void asyncDoGetHeadersTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -457,7 +449,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -465,7 +457,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetCookieTest() throws Throwable { + public void asyncDoGetCookieTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -494,7 +486,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -502,7 +494,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostDefaultContentType() throws Throwable { + public void asyncDoPostDefaultContentType() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -522,7 +514,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -530,7 +522,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostBodyIsoTest() throws Throwable { + public void asyncDoPostBodyIsoTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(); @@ -541,7 +533,7 @@ public void asyncDoPostBodyIsoTest() throws Throwable { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostBytesTest() throws Throwable { + public void asyncDoPostBytesTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -549,11 +541,7 @@ public void asyncDoPostBytesTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -576,7 +564,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -584,7 +572,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostInputStreamTest() throws Throwable { + public void asyncDoPostInputStreamTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -592,11 +580,7 @@ public void asyncDoPostInputStreamTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); ByteArrayInputStream is = new ByteArrayInputStream(sb.toString().getBytes()); @@ -619,7 +603,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -627,7 +611,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPutInputStreamTest() throws Throwable { + public void asyncDoPutInputStreamTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -635,11 +619,7 @@ public void asyncDoPutInputStreamTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); ByteArrayInputStream is = new ByteArrayInputStream(sb.toString().getBytes()); @@ -651,9 +631,7 @@ public Response onCompleted(Response response) throws Exception { try { assertEquals(response.getStatusCode(), 200); for (int i = 1; i < 5; i++) { - System.out.println(">>>>> " + response.getHeader("X-param_" + i)); assertEquals(response.getHeader("X-param_" + i), "value_" + i); - } } finally { l.countDown(); @@ -662,7 +640,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -670,7 +648,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostMultiPartTest() throws Throwable { + public void asyncDoPostMultiPartTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -694,7 +672,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -702,7 +680,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostBasicGZIPTest() throws Throwable { + public void asyncDoPostBasicGZIPTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build()); try { final CountDownLatch l = new CountDownLatch(1); @@ -710,11 +688,7 @@ public void asyncDoPostBasicGZIPTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -732,7 +706,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); @@ -740,18 +714,14 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostProxyTest() throws Throwable { + public void asyncDoPostProxyTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setProxyServer(new ProxyServer("127.0.0.1", port2)).build()); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -774,7 +744,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncRequestVirtualServerPOSTTest() throws Throwable { + public void asyncRequestVirtualServerPOSTTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -800,18 +770,14 @@ public void asyncRequestVirtualServerPOSTTest() throws Throwable { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPutTest() throws Throwable { + public void asyncDoPutTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -824,7 +790,7 @@ public void asyncDoPutTest() throws Throwable { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostLatchBytesTest() throws Throwable { + public void asyncDoPostLatchBytesTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -832,11 +798,7 @@ public void asyncDoPostLatchBytesTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -847,9 +809,7 @@ public Response onCompleted(Response response) throws Exception { try { assertEquals(response.getStatusCode(), 200); for (int i = 1; i < 5; i++) { - System.out.println(">>>>> " + response.getHeader("X-param_" + i)); assertEquals(response.getHeader("X-param_" + i), "value_" + i); - } return response; } finally { @@ -859,7 +819,7 @@ public Response onCompleted(Response response) throws Exception { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -867,7 +827,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostDelayCancelTest() throws Throwable { + public void asyncDoPostDelayCancelTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -883,14 +843,14 @@ public void onThrowable(Throwable t) { }); future.cancel(true); Response response = future.get(TIMEOUT, TimeUnit.SECONDS); - Assert.assertNull(response); + assertNull(response); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostDelayBytesTest() throws Throwable { + public void asyncDoPostDelayBytesTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -910,12 +870,12 @@ public void onThrowable(Throwable t) { future.get(10, TimeUnit.SECONDS); } catch (ExecutionException ex) { if (ex.getCause() instanceof TimeoutException) { - Assert.assertTrue(true); + assertTrue(true); } } catch (TimeoutException te) { - Assert.assertTrue(true); + assertTrue(true); } catch (IllegalStateException ex) { - Assert.assertTrue(false); + assertTrue(false); } } finally { client.close(); @@ -923,7 +883,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostNullBytesTest() throws Throwable { + public void asyncDoPostNullBytesTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { @@ -931,18 +891,14 @@ public void asyncDoPostNullBytesTest() throws Throwable { h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()); Response response = future.get(); - Assert.assertNotNull(response); + assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -950,18 +906,14 @@ public void asyncDoPostNullBytesTest() throws Throwable { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostListenerBytesTest() throws Throwable { + public void asyncDoPostListenerBytesTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5; i++) { - sb.append("param_"); - sb.append(i); - sb.append("=value_"); - sb.append(i); - sb.append("&"); + sb.append("param_").append(i).append("=value_").append(i).append("&"); } sb.setLength(sb.length() - 1); @@ -980,7 +932,7 @@ public Response onCompleted(Response response) throws Exception { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Latch time out"); + fail("Latch time out"); } } finally { client.close(); @@ -988,7 +940,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncConnectInvalidFuture() throws Throwable { + public void asyncConnectInvalidFuture() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { int dummyPort = findFreePort(); @@ -1016,7 +968,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncConnectInvalidPortFuture() throws Throwable { + public void asyncConnectInvalidPortFuture() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { int dummyPort = findFreePort(); @@ -1040,7 +992,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncConnectInvalidPort() throws Throwable { + public void asyncConnectInvalidPort() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // pick a random unused local port @@ -1063,7 +1015,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncConnectInvalidHandlerPort() throws Throwable { + public void asyncConnectInvalidHandlerPort() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -1081,7 +1033,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1089,7 +1041,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncConnectInvalidHandlerHost() throws Throwable { + public void asyncConnectInvalidHandlerHost() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final CountDownLatch l = new CountDownLatch(1); @@ -1108,7 +1060,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1116,7 +1068,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncConnectInvalidFuturePort() throws Throwable { + public void asyncConnectInvalidFuturePort() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicBoolean called = new AtomicBoolean(false); @@ -1146,18 +1098,18 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncContentLenghtGETTest() throws Throwable { + public void asyncContentLenghtGETTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } }).get(); - Assert.assertNotNull(response); + assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1165,32 +1117,32 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncResponseBodyTooLarge() throws Throwable { + public void asyncResponseBodyTooLarge() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.preparePost(getTargetUrl()).setBody("0123456789").execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } }).get(); - Assert.assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE)); + assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE)); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncResponseEmptyBody() throws Throwable { + public void asyncResponseEmptyBody() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerAdapter() { @Override public void onThrowable(Throwable t) { - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } }).get(); @@ -1201,7 +1153,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "asyncAPI" }) - public void asyncAPIContentLenghtGETTest() throws Throwable { + public void asyncAPIContentLenghtGETTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // Use a l in case the assert fail @@ -1225,7 +1177,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1233,7 +1185,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "asyncAPI" }) - public void asyncAPIHandlerExceptionTest() throws Throwable { + public void asyncAPIHandlerExceptionTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // Use a l in case the assert fail @@ -1258,7 +1210,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1266,7 +1218,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetDelayHandlerTest() throws Throwable { + public void asyncDoGetDelayHandlerTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(5 * 1000).build()); try { FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); @@ -1280,7 +1232,7 @@ public void asyncDoGetDelayHandlerTest() throws Throwable { @Override public Response onCompleted(Response response) throws Exception { try { - Assert.fail("Must not receive a response"); + fail("Must not receive a response"); } finally { l.countDown(); } @@ -1291,9 +1243,9 @@ public Response onCompleted(Response response) throws Exception { public void onThrowable(Throwable t) { try { if (t instanceof TimeoutException) { - Assert.assertTrue(true); + assertTrue(true); } else { - Assert.fail("Unexpected exception", t); + fail("Unexpected exception", t); } } finally { l.countDown(); @@ -1302,7 +1254,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1310,7 +1262,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetQueryStringTest() throws Throwable { + public void asyncDoGetQueryStringTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // Use a l in case the assert fail @@ -1321,8 +1273,8 @@ public void asyncDoGetQueryStringTest() throws Throwable { @Override public Response onCompleted(Response response) throws Exception { try { - Assert.assertTrue(response.getHeader("X-pathInfo") != null); - Assert.assertTrue(response.getHeader("X-queryString") != null); + assertTrue(response.getHeader("X-pathInfo") != null); + assertTrue(response.getHeader("X-queryString") != null); } finally { l.countDown(); } @@ -1335,7 +1287,7 @@ public Response onCompleted(Response response) throws Exception { client.executeRequest(req, handler).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1343,7 +1295,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoGetKeepAliveHandlerTest() throws Throwable { + public void asyncDoGetKeepAliveHandlerTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // Use a l in case the assert fail @@ -1355,15 +1307,16 @@ public void asyncDoGetKeepAliveHandlerTest() throws Throwable { @Override public Response onCompleted(Response response) throws Exception { - assertEquals(response.getStatusCode(), 200); - if (remoteAddr == null) { - remoteAddr = response.getHeader("X-KEEP-ALIVE"); - l.countDown(); - } else { - assertEquals(response.getHeader("X-KEEP-ALIVE"), remoteAddr); + try { + assertEquals(response.getStatusCode(), 200); + if (remoteAddr == null) { + remoteAddr = response.getHeader("X-KEEP-ALIVE"); + } else { + assertEquals(response.getHeader("X-KEEP-ALIVE"), remoteAddr); + } + } finally { l.countDown(); } - return response; } }; @@ -1372,7 +1325,7 @@ public Response onCompleted(Response response) throws Exception { client.prepareGet(getTargetUrl()).execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1380,7 +1333,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncDoGetMaxRedirectTest() throws Throwable { + public void asyncDoGetMaxRedirectTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new Builder().setMaximumNumberOfRedirects(0).setFollowRedirects(true).build()); try { // Use a l in case the assert fail @@ -1390,7 +1343,7 @@ public void asyncDoGetMaxRedirectTest() throws Throwable { @Override public Response onCompleted(Response response) throws Exception { - Assert.fail("Should not be here"); + fail("Should not be here"); return response; } @@ -1408,7 +1361,7 @@ public void onThrowable(Throwable t) { client.prepareGet("http://www.google.com/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1416,7 +1369,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncDoGetNestedTest() throws Throwable { + public void asyncDoGetNestedTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { // FIXME find a proper website that redirects the same number of times whatever the language @@ -1451,7 +1404,7 @@ public void onThrowable(Throwable t) { client.prepareGet("http://www.lemonde.fr/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { client.close(); @@ -1459,7 +1412,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncDoGetStreamAndBodyTest() throws Throwable { + public void asyncDoGetStreamAndBodyTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); @@ -1470,7 +1423,7 @@ public void asyncDoGetStreamAndBodyTest() throws Throwable { } @Test(groups = { "online", "default_provider", "async" }) - public void asyncUrlWithoutPathTest() throws Throwable { + public void asyncUrlWithoutPathTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); @@ -1481,7 +1434,7 @@ public void asyncUrlWithoutPathTest() throws Throwable { } @Test(groups = { "default_provider", "async" }) - public void optionsTest() throws Throwable { + public void optionsTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareOptions(getTargetUrl()).execute().get(); @@ -1535,12 +1488,12 @@ public void idleRequestTimeoutTest() throws Exception { long t1 = millisTime(); try { client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); - Assert.fail(); + fail(); } catch (Throwable ex) { final long elapsedTime = millisTime() - t1; System.out.println("EXPIRED: " + (elapsedTime)); - Assert.assertNotNull(ex.getCause()); - Assert.assertTrue(elapsedTime >= 10000 && elapsedTime <= 25000); + assertNotNull(ex.getCause()); + assertTrue(elapsedTime >= 10000 && elapsedTime <= 25000); } } finally { client.close(); @@ -1548,7 +1501,7 @@ public void idleRequestTimeoutTest() throws Exception { } @Test(groups = { "standalone", "default_provider", "async" }) - public void asyncDoPostCancelTest() throws Throwable { + public void asyncDoPostCancelTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { @@ -1577,7 +1530,7 @@ public void onThrowable(Throwable t) { } catch (IllegalStateException ise) { fail(); } - Assert.assertNotNull(ex.get()); + assertNotNull(ex.get()); } finally { client.close(); } @@ -1626,7 +1579,7 @@ public void asyncHttpClientConfigBeanTest() throws Exception { } @Test(groups = { "default_provider", "async" }) - public void bodyAsByteTest() throws Throwable { + public void bodyAsByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet(getTargetUrl()).execute().get(); @@ -1638,7 +1591,7 @@ public void bodyAsByteTest() throws Throwable { } @Test(groups = { "default_provider", "async" }) - public void mirrorByteTest() throws Throwable { + public void mirrorByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); @@ -1649,5 +1602,5 @@ public void mirrorByteTest() throws Throwable { } } - protected abstract AsyncHttpProviderConfig getProviderConfig(); + protected abstract AsyncHttpProviderConfig getProviderConfig(); } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index 9c6a4ddfed..1d31d21ac7 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -15,16 +15,8 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.Response; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET; +import static org.testng.Assert.*; import java.util.Arrays; import java.util.Collection; @@ -37,13 +29,22 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Response; +import org.testng.annotations.Test; + public abstract class AsyncStreamHandlerTest extends AbstractBasicTest { - + private static final String RESPONSE = "param_1_"; - private static final String UTF8 = "text/html;charset=utf-8"; @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamGETTest() throws Throwable { + public void asyncStreamGETTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); AsyncHttpClient c = getAsyncHttpClient(null); try { @@ -53,8 +54,8 @@ public void asyncStreamGETTest() throws Throwable { public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { try { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.ABORT; } finally { l.countDown(); @@ -64,7 +65,7 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { @Override public void onThrowable(Throwable t) { try { - Assert.fail("", t); + fail("", t); } finally { l.countDown(); } @@ -72,7 +73,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(5, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -80,7 +81,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamPOSTTest() throws Throwable { + public void asyncStreamPOSTTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -95,8 +96,8 @@ public void asyncStreamPOSTTest() throws Throwable { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.CONTINUE; } @@ -110,7 +111,7 @@ public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { public String onCompleted() throws Exception { try { String r = builder.toString().trim(); - Assert.assertEquals(r, RESPONSE); + assertEquals(r, RESPONSE); return r; } finally { l.countDown(); @@ -119,7 +120,7 @@ public String onCompleted() throws Exception { }); if (!l.await(10, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -127,7 +128,7 @@ public String onCompleted() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamInterruptTest() throws Throwable { + public void asyncStreamInterruptTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -143,22 +144,22 @@ public void asyncStreamInterruptTest() throws Throwable { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.ABORT; } @Override public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { a.set(false); - Assert.fail("Interrupted not working"); + fail("Interrupted not working"); return STATE.ABORT; } @Override public void onThrowable(Throwable t) { try { - Assert.fail("", t); + fail("", t); } finally { l.countDown(); } @@ -166,14 +167,14 @@ public void onThrowable(Throwable t) { }); l.await(5, TimeUnit.SECONDS); - Assert.assertTrue(a.get()); + assertTrue(a.get()); } finally { c.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamFutureTest() throws Throwable { + public void asyncStreamFutureTest() throws Exception { Map> m = new HashMap>(); m.put("param_1", Arrays.asList("value_1")); AsyncHttpClient c = getAsyncHttpClient(null); @@ -184,8 +185,8 @@ public void asyncStreamFutureTest() throws Throwable { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.CONTINUE; } @@ -198,22 +199,22 @@ public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { @Override public String onCompleted() throws Exception { String r = builder.toString().trim(); - Assert.assertEquals(r, RESPONSE); + assertEquals(r, RESPONSE); return r; } @Override public void onThrowable(Throwable t) { - Assert.fail("", t); + fail("", t); } }); try { String r = f.get(5, TimeUnit.SECONDS); - Assert.assertNotNull(r); - Assert.assertEquals(r.trim(), RESPONSE); + assertNotNull(r); + assertEquals(r.trim(), RESPONSE); } catch (TimeoutException ex) { - Assert.fail(); + fail(); } } finally { c.close(); @@ -221,7 +222,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamThrowableRefusedTest() throws Throwable { + public void asyncStreamThrowableRefusedTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); AsyncHttpClient c = getAsyncHttpClient(null); @@ -237,7 +238,7 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { public void onThrowable(Throwable t) { try { if (t.getMessage() != null) { - Assert.assertEquals(t.getMessage(), "FOO"); + assertEquals(t.getMessage(), "FOO"); } } finally { l.countDown(); @@ -246,7 +247,7 @@ public void onThrowable(Throwable t) { }); if (!l.await(10, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } } finally { c.close(); @@ -254,7 +255,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void asyncStreamReusePOSTTest() throws Throwable { + public void asyncStreamReusePOSTTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); h.add("Content-Type", "application/x-www-form-urlencoded"); @@ -269,8 +270,8 @@ public void asyncStreamReusePOSTTest() throws Throwable { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.CONTINUE; } @@ -284,7 +285,7 @@ public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { public String onCompleted() throws Exception { try { String r = builder.toString().trim(); - Assert.assertEquals(r, RESPONSE); + assertEquals(r, RESPONSE); return r; } finally { l.countDown(); @@ -294,7 +295,7 @@ public String onCompleted() throws Exception { }); if (!l.await(20, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } // Let do the same again @@ -304,8 +305,8 @@ public String onCompleted() throws Exception { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), UTF8); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); return STATE.CONTINUE; } @@ -319,7 +320,7 @@ public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { public String onCompleted() throws Exception { try { String r = builder.toString().trim(); - Assert.assertEquals(r, RESPONSE); + assertEquals(r, RESPONSE); return r; } finally { l.countDown(); @@ -328,7 +329,7 @@ public String onCompleted() throws Exception { }); if (!l.await(20, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -336,22 +337,22 @@ public String onCompleted() throws Exception { } @Test(groups = { "online", "default_provider" }) - public void asyncStream301WithBody() throws Throwable { + public void asyncStream301WithBody() throws Exception { final CountDownLatch l = new CountDownLatch(1); AsyncHttpClient c = getAsyncHttpClient(null); try { c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() { public STATE onStatusReceived(HttpResponseStatus status) throws Exception { - Assert.assertEquals(301, status.getStatusCode()); - return STATE.CONTINUE; + assertEquals(301, status.getStatusCode()); + return STATE.CONTINUE; } @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), "text/html; charset=utf-8"); + assertNotNull(h); + assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET.toLowerCase(Locale.ENGLISH)); return STATE.CONTINUE; } @@ -368,7 +369,7 @@ public String onCompleted() throws Exception { }); if (!l.await(20, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -376,22 +377,22 @@ public String onCompleted() throws Exception { } @Test(groups = { "online", "default_provider" }) - public void asyncStream301RedirectWithBody() throws Throwable { + public void asyncStream301RedirectWithBody() throws Exception { final CountDownLatch l = new CountDownLatch(1); AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); try { c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() { public STATE onStatusReceived(HttpResponseStatus status) throws Exception { - Assert.assertTrue(status.getStatusCode() != 301); - return STATE.CONTINUE; + assertTrue(status.getStatusCode() != 301); + return STATE.CONTINUE; } @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); - Assert.assertEquals(h.getFirstValue("server"), "gws"); + assertNotNull(h); + assertEquals(h.getFirstValue("server"), "gws"); // This assertion below is not an invariant, since implicitly contains locale-dependant settings // and fails when run in country having own localized Google site and it's locale relies on something // other than ISO-8859-1. @@ -399,7 +400,7 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { // Google site, that uses ISO-8892-2 encoding (default for HU). Similar is true for other // non-ISO-8859-1 using countries that have "localized" google, like google.hr, google.rs, google.cz, google.sk etc. // - // Assert.assertEquals(h.getJoinedValue("content-type", ", "), "text/html; charset=ISO-8859-1"); + // assertEquals(h.getJoinedValue("content-type", ", "), "text/html; charset=ISO-8859-1"); return STATE.CONTINUE; } @@ -411,7 +412,7 @@ public String onCompleted() throws Exception { }); if (!l.await(20, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -419,7 +420,7 @@ public String onCompleted() throws Exception { } @Test(groups = { "standalone", "default_provider" }, timeOut = 3000, description = "Test behavior of 'read only status line' scenario.") - public void asyncStreamJustStatusLine() throws Throwable { + public void asyncStreamJustStatusLine() throws Exception { final int STATUS = 0; final int COMPLETED = 1; final int OTHER = 2; @@ -446,7 +447,6 @@ public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception /* @Override */ public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception { whatCalled[STATUS] = true; - System.out.println(responseStatus); status = responseStatus.getStatusCode(); latch.countDown(); return STATE.ABORT; @@ -468,20 +468,20 @@ public Integer onCompleted() throws Exception { }); if (!latch.await(2, TimeUnit.SECONDS)) { - Assert.fail("Timeout"); + fail("Timeout"); return; } Integer status = statusCode.get(TIMEOUT, TimeUnit.SECONDS); - Assert.assertEquals((int) status, 200, "Expected status code failed."); + assertEquals((int) status, 200, "Expected status code failed."); if (!whatCalled[STATUS]) { - Assert.fail("onStatusReceived not called."); + fail("onStatusReceived not called."); } if (!whatCalled[COMPLETED]) { - Assert.fail("onCompleted not called."); + fail("onCompleted not called."); } if (whatCalled[OTHER]) { - Assert.fail("Other method of AsyncHandler got called."); + fail("Other method of AsyncHandler got called."); } } finally { client.close(); @@ -489,7 +489,7 @@ public Integer onCompleted() throws Exception { } @Test(groups = { "online", "default_provider" }) - public void asyncOptionsTest() throws Throwable { + public void asyncOptionsTest() throws Exception { final CountDownLatch l = new CountDownLatch(1); AsyncHttpClient c = getAsyncHttpClient(null); try { @@ -499,20 +499,15 @@ public void asyncOptionsTest() throws Throwable { @Override public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception { FluentCaseInsensitiveStringsMap h = content.getHeaders(); - Assert.assertNotNull(h); + assertNotNull(h); String[] values = h.get("Allow").get(0).split(",|, "); - Assert.assertNotNull(values); - Assert.assertEquals(values.length, expected.length); + assertNotNull(values); + assertEquals(values.length, expected.length); Arrays.sort(values); - Assert.assertEquals(values, expected); + assertEquals(values, expected); return STATE.ABORT; } - @Override - public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { - return STATE.CONTINUE; - } - @Override public String onCompleted() throws Exception { try { @@ -524,7 +519,7 @@ public String onCompleted() throws Exception { }); if (!l.await(20, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { c.close(); @@ -532,7 +527,7 @@ public String onCompleted() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void closeConnectionTest() throws Throwable { + public void closeConnectionTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { Response r = c.prepareGet(getTargetUrl()).execute(new AsyncHandler() { @@ -567,8 +562,8 @@ public Response onCompleted() throws Exception { } }).get(); - Assert.assertNotNull(r); - Assert.assertEquals(r.getStatusCode(), 200); + assertNotNull(r); + assertEquals(r.getStatusCode(), 200); } finally { c.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java index 1666fc77d4..0c49fca3b8 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamLifecycleTest.java @@ -15,21 +15,8 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.concurrent.CountDownLatch; @@ -40,10 +27,21 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.eclipse.jetty.continuation.Continuation; +import org.eclipse.jetty.continuation.ContinuationSupport; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; /** * Tests default asynchronous life cycle. @@ -74,9 +72,9 @@ public void run() { try { Thread.sleep(100); } catch (InterruptedException e) { - log.error("Failed to sleep for 100 ms.", e); + logger.error("Failed to sleep for 100 ms.", e); } - log.info("Delivering part1."); + logger.info("Delivering part1."); writer.write("part1"); writer.flush(); } @@ -86,9 +84,9 @@ public void run() { try { Thread.sleep(200); } catch (InterruptedException e) { - log.error("Failed to sleep for 200 ms.", e); + logger.error("Failed to sleep for 200 ms.", e); } - log.info("Delivering part2."); + logger.info("Delivering part2."); writer.write("part2"); writer.flush(); continuation.complete(); @@ -118,7 +116,7 @@ public void onThrowable(Throwable t) { public STATE onBodyPartReceived(HttpResponseBodyPart e) throws Exception { String s = new String(e.getBodyPartBytes()); - log.info("got part: {}", s); + logger.info("got part: {}", s); queue.put(s); return STATE.CONTINUE; } diff --git a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java index bd4491f7a6..962e996cd2 100644 --- a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java @@ -12,100 +12,59 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Realm; import org.asynchttpclient.Response; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.security.authentication.BasicAuthenticator; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.util.security.Constraint; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; - public abstract class AuthTimeoutTest extends AbstractBasicTest { - private static final String USER = "user"; - - private static final String ADMIN = "admin"; - - protected AsyncHttpClient client; - - public void setUpServer(String auth) throws Exception { - server = new Server(); - Logger root = Logger.getRootLogger(); - root.setLevel(Level.DEBUG); - root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN))); + private Server server2; + @BeforeClass(alwaysRun = true) + @Override + public void setUpGlobal() throws Exception { port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); - server.addBean(loginService); - - Constraint constraint = new Constraint(); - constraint.setName(auth); - constraint.setRoles(new String[] { USER, ADMIN }); - constraint.setAuthenticate(true); - - ConstraintMapping mapping = new ConstraintMapping(); - mapping.setConstraint(constraint); - mapping.setPathSpec("/*"); + port2 = findFreePort(); - Set knownRoles = new HashSet(); - knownRoles.add(USER); - knownRoles.add(ADMIN); - - ConstraintSecurityHandler security = new ConstraintSecurityHandler(); + server = newJettyHttpServer(port1); + addBasicAuthHandler(server, false, configureHandler()); + server.start(); - List cm = new ArrayList(); - cm.add(mapping); + server2 = newJettyHttpServer(port2); + addDigestAuthHandler(server2, true, configureHandler()); + server2.start(); - security.setConstraintMappings(cm, knownRoles); - security.setAuthenticator(new BasicAuthenticator()); - security.setLoginService(loginService); - security.setStrict(false); - security.setHandler(configureHandler()); + logger.info("Local HTTP server started successfully"); + } - server.setHandler(security); - server.start(); - log.info("Local HTTP server started successfully"); + @AfterClass(alwaysRun = true) + public void tearDownGlobal() throws Exception { + super.tearDownGlobal(); + server2.stop(); } - private class SimpleHandler extends AbstractHandler { - public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + private class IncompleteResponseHandler extends AbstractHandler { + public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // NOTE: handler sends less bytes than are given in Content-Length, which should lead to timeout OutputStream out = response.getOutputStream(); @@ -113,12 +72,9 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR String content = request.getHeader("X-Content"); response.setHeader("Content-Length", String.valueOf(content.getBytes("UTF-8").length)); out.write(content.substring(1).getBytes("UTF-8")); - out.flush(); - out.close(); - return; + } else { + response.setStatus(200); } - - response.setStatus(200); out.flush(); out.close(); } @@ -126,9 +82,9 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR @Test(groups = { "standalone", "default_provider" }, enabled = false) public void basicAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__BASIC_AUTH); + AsyncHttpClient client = newClient(); try { - Future f = execute(false); + Future f = execute(client, server, false); f.get(); fail("expected timeout"); } catch (Exception e) { @@ -140,9 +96,9 @@ public void basicAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void basicPreemptiveAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__BASIC_AUTH); + AsyncHttpClient client = newClient(); try { - Future f = execute(true); + Future f = execute(client, server, true); f.get(); fail("expected timeout"); } catch (Exception e) { @@ -154,10 +110,9 @@ public void basicPreemptiveAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void digestAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__DIGEST_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(false); + Future f = execute(client, server2, false); f.get(); fail("expected timeout"); } catch (Exception e) { @@ -169,10 +124,9 @@ public void digestAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void digestPreemptiveAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__DIGEST_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(true); + Future f = execute(client, server2, true); f.get(); fail("expected timeout"); } catch (Exception e) { @@ -184,10 +138,9 @@ public void digestPreemptiveAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void basicFutureAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__BASIC_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(false); + Future f = execute(client, server, false); f.get(1, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { @@ -199,10 +152,9 @@ public void basicFutureAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void basicFuturePreemptiveAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__BASIC_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(true); + Future f = execute(client, server, true); f.get(1, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { @@ -214,10 +166,9 @@ public void basicFuturePreemptiveAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void digestFutureAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__DIGEST_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(false); + Future f = execute(client, server2, false); f.get(1, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { @@ -229,10 +180,9 @@ public void digestFutureAuthTimeoutTest() throws Exception { @Test(groups = { "standalone", "default_provider" }, enabled = false) public void digestFuturePreemptiveAuthTimeoutTest() throws Exception { - setUpServer(Constraint.__DIGEST_AUTH); - + AsyncHttpClient client = newClient(); try { - Future f = execute(true); + Future f = execute(client, server2, true); f.get(1, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { @@ -250,8 +200,11 @@ protected void inspectException(Throwable t) { } } - protected Future execute(boolean preemptive) throws IOException { - client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(2000).setConnectionTimeoutInMs(20000).setRequestTimeoutInMs(2000).build()); + private AsyncHttpClient newClient() { + return getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(2000).setConnectionTimeoutInMs(20000).setRequestTimeoutInMs(2000).build()); + } + + protected Future execute(AsyncHttpClient client, Server server, boolean preemptive) throws IOException { AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm(realm(preemptive)).setHeader("X-Content", "Test"); Future f = r.execute(); return f; @@ -268,6 +221,6 @@ protected String getTargetUrl() { @Override public AbstractHandler configureHandler() throws Exception { - return new SimpleHandler(); + return new IncompleteResponseHandler(); } } diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 9e5f8b6bdc..0fecd118d7 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -15,6 +15,20 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -26,52 +40,18 @@ import org.asynchttpclient.SimpleAsyncHttpClient; import org.asynchttpclient.consumers.AppendableBodyConsumer; import org.asynchttpclient.generators.InputStreamBodyGenerator; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.security.authentication.BasicAuthenticator; -import org.eclipse.jetty.security.authentication.DigestAuthenticator; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.util.security.Constraint; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - public abstract class BasicAuthTest extends AbstractBasicTest { protected static final String MY_MESSAGE = "my message"; - protected static final String USER = "user"; - protected static final String ADMIN = "admin"; private Server server2; @@ -80,99 +60,18 @@ public abstract class BasicAuthTest extends AbstractBasicTest { @BeforeClass(alwaysRun = true) @Override public void setUpGlobal() throws Exception { - server = new Server(); - Logger root = Logger.getRootLogger(); - root.setLevel(Level.DEBUG); - root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN))); - port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); - server.addBean(loginService); - - Constraint constraint = new Constraint(); - constraint.setName(Constraint.__BASIC_AUTH); - constraint.setRoles(new String[] { USER, ADMIN }); - constraint.setAuthenticate(true); - - ConstraintMapping mapping = new ConstraintMapping(); - mapping.setConstraint(constraint); - mapping.setPathSpec("/*"); - - List cm = new ArrayList(); - cm.add(mapping); - - Set knownRoles = new HashSet(); - knownRoles.add(USER); - knownRoles.add(ADMIN); - - ConstraintSecurityHandler security = new ConstraintSecurityHandler(); - security.setConstraintMappings(cm, knownRoles); - security.setAuthenticator(new BasicAuthenticator()); - security.setLoginService(loginService); - security.setStrict(false); - security.setHandler(configureHandler()); - - server.setHandler(security); - server.start(); - log.info("Local HTTP server started successfully"); - setUpSecondServer(); - } - - private void setUpSecondServer() throws Exception { - server2 = new Server(); port2 = findFreePort(); - SelectChannelConnector connector = new SelectChannelConnector(); - connector.setHost("127.0.0.1"); - connector.setPort(port2); - - server2.addConnector(connector); - - LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); - server2.addBean(loginService); - - Constraint constraint = new Constraint(); - constraint.setName(Constraint.__DIGEST_AUTH); - constraint.setRoles(new String[] { USER, ADMIN }); - constraint.setAuthenticate(true); - - ConstraintMapping mapping = new ConstraintMapping(); - mapping.setConstraint(constraint); - mapping.setPathSpec("/*"); - - Set knownRoles = new HashSet(); - knownRoles.add(USER); - knownRoles.add(ADMIN); - - ConstraintSecurityHandler security = new ConstraintSecurityHandler() { - - @Override - public void handle(String arg0, Request arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws IOException, ServletException { - System.err.println("request in security handler"); - System.err.println("Authorization: " + arg2.getHeader("Authorization")); - System.err.println("RequestUri: " + arg2.getRequestURI()); - super.handle(arg0, arg1, arg2, arg3); - } - }; - - List cm = new ArrayList(); - cm.add(mapping); - - security.setConstraintMappings(cm, knownRoles); - security.setAuthenticator(new DigestAuthenticator()); - security.setLoginService(loginService); - security.setStrict(true); - security.setHandler(new RedirectHandler()); + server = newJettyHttpServer(port1); + addBasicAuthHandler(server, false, configureHandler()); + server.start(); - server2.setHandler(security); + server2 = newJettyHttpServer(port2); + addDigestAuthHandler(server2, true, new RedirectHandler()); server2.start(); + + logger.info("Local HTTP server started successfully"); } @AfterClass(alwaysRun = true) @@ -181,41 +80,31 @@ public void tearDownGlobal() throws Exception { server2.stop(); } - private String getFileContent(final File file) { - FileInputStream in = null; - try { - if (file.exists() && file.canRead()) { - final StringBuilder sb = new StringBuilder(128); - final byte[] b = new byte[512]; - int read; - in = new FileInputStream(file); - while ((read = in.read(b)) != -1) { - sb.append(new String(b, 0, read, "UTF-8")); - } - return sb.toString(); - } - throw new IllegalArgumentException("File does not exist or cannot be read: " + file.getCanonicalPath()); - } catch (IOException ioe) { - throw new IllegalStateException(ioe); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException ignored) { - } - } - } + @Override + protected String getTargetUrl() { + return "http://127.0.0.1/" + port1 + "/"; + } + + @Override + protected String getTargetUrl2() { + return "http://127.0.0.1/" + port2 + "/uff"; + } + @Override + public AbstractHandler configureHandler() throws Exception { + return new SimpleHandler(); } - private class RedirectHandler extends AbstractHandler { + private static class RedirectHandler extends AbstractHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(RedirectHandler.class); + public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - System.err.println("redirecthandler"); - System.err.println("request: " + request.getRequestURI()); + LOGGER.info("request: " + request.getRequestURI()); if ("/uff".equals(request.getRequestURI())) { - System.err.println("redirect to /bla"); + LOGGER.info("redirect to /bla"); response.setStatus(302); response.setHeader("Location", "/bla"); response.getOutputStream().flush(); @@ -224,7 +113,7 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR return; } else { - System.err.println("got redirected" + request.getRequestURI()); + LOGGER.info("got redirected" + request.getRequestURI()); response.addHeader("X-Auth", request.getHeader("Authorization")); response.addHeader("X-Content-Length", String.valueOf(request.getContentLength())); response.setStatus(200); @@ -235,7 +124,8 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR } } - private class SimpleHandler extends AbstractHandler { + private static class SimpleHandler extends AbstractHandler { + public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getHeader("X-401") != null) { @@ -269,9 +159,9 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR public void basicAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); - - Future f = r.execute(); + Future f = client.prepareGet(getTargetUrl())// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())// + .execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); @@ -283,39 +173,27 @@ public void basicAuthTest() throws IOException, ExecutionException, TimeoutExcep @Test(groups = { "standalone", "default_provider" }) public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException { - AsyncHttpClient client = null; + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).setMaximumNumberOfRedirects(10).build()); try { - client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).setMaximumNumberOfRedirects(10).build()); - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl2()) - // .setHeader( "X-302", "/bla" ) - .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); - - Future f = r.execute(); + Future f = client.prepareGet(getTargetUrl2())// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())// + .execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); } finally { - if (client != null) - client.close(); + client.close(); } } - @Override - protected String getTargetUrl() { - return "http://127.0.0.1/" + port1 + "/"; - } - - protected String getTargetUrl2() { - return "http://127.0.0.1/" + port2 + "/uff"; - } - @Test(groups = { "standalone", "default_provider" }) public void basic401Test() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setHeader("X-401", "401") + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl())// + .setHeader("X-401", "401")// .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); Future f = r.execute(new AsyncHandler() { @@ -359,10 +237,10 @@ public Integer onCompleted() throws Exception { public void basicAuthTestPreemtiveTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm( - (new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setUsePreemptiveAuth(true).build()); + Future f = client.prepareGet(getTargetUrl())// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setUsePreemptiveAuth(true).build())// + .execute(); - Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); @@ -376,9 +254,10 @@ public void basicAuthTestPreemtiveTest() throws IOException, ExecutionException, public void basicAuthNegativeTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet(getTargetUrl()).setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(ADMIN).build()); + Future f = client.prepareGet(getTargetUrl())// + .setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(ADMIN).build())// + .execute(); - Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), 401); @@ -391,11 +270,11 @@ public void basicAuthNegativeTest() throws IOException, ExecutionException, Time public void basicAuthInputStreamTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - ByteArrayInputStream is = new ByteArrayInputStream("test".getBytes()); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(is) - .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); + Future f = client.preparePost(getTargetUrl())// + .setBody(new ByteArrayInputStream("test".getBytes()))// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())// + .execute(); - Future f = r.execute(); Response resp = f.get(30, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); @@ -407,83 +286,64 @@ public void basicAuthInputStreamTest() throws IOException, ExecutionException, T } @Test(groups = { "standalone", "default_provider" }) - public void basicAuthFileTest() throws Throwable { + public void basicAuthFileTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - final String fileContent = getFileContent(file); + Future f = client.preparePost(getTargetUrl())// + .setBody(SIMPLE_TEXT_FILE)// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())// + .execute(); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file) - .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); - - Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), fileContent); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void basicAuthAsyncConfigTest() throws Throwable { + public void basicAuthAsyncConfigTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - final String fileContent = getFileContent(file); + Future f = client.preparePost(getTargetUrl())// + .setBody(SIMPLE_TEXT_FILE_STRING)// + .execute(); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file); - - Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), fileContent); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void basicAuthFileNoKeepAliveTest() throws Throwable { + public void basicAuthFileNoKeepAliveTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(false).build()); try { - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - final String fileContent = getFileContent(file); - AsyncHttpClient.BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(file) - .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build()); + Future f = client.preparePost(getTargetUrl())// + .setBody(SIMPLE_TEXT_FILE)// + .setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).build())// + .execute(); - Future f = r.execute(); Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertNotNull(resp.getHeader("X-Auth")); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), fileContent); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } - @Override - public AbstractHandler configureHandler() throws Exception { - return new SimpleHandler(); - } - @Test(groups = { "standalone", "default_provider" }) - public void stringBuilderBodyConsumerTest() throws Throwable { + public void stringBuilderBodyConsumerTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setRealmPrincipal(USER).setRealmPassword(ADMIN) .setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); @@ -491,7 +351,6 @@ public void stringBuilderBodyConsumerTest() throws Throwable { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); - System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index 18b35ae05d..1efde2f983 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -15,143 +15,44 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; -import java.io.IOException; -import java.io.InputStream; import java.net.ConnectException; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Enumeration; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; -import javax.servlet.ServletException; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.io.IOUtils; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig.Builder; import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.testng.annotations.Test; public abstract class BasicHttpsTest extends AbstractBasicHttpsTest { - protected static final Logger LOGGER = LoggerFactory.getLogger(BasicHttpsTest.class); - - public static class EchoHandler extends AbstractHandler { - - @Override - public void handle(String pathInContext, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException { - - httpResponse.setContentType("text/html; charset=utf-8"); - Enumeration e = httpRequest.getHeaderNames(); - String param; - while (e.hasMoreElements()) { - param = e.nextElement().toString(); - - if (param.startsWith("LockThread")) { - try { - Thread.sleep(40 * 1000); - } catch (InterruptedException ex) { // nothing to do here - } - } - - httpResponse.addHeader("X-" + param, httpRequest.getHeader(param)); - } - - Enumeration i = httpRequest.getParameterNames(); - - StringBuilder requestBody = new StringBuilder(); - while (i.hasMoreElements()) { - param = i.nextElement().toString(); - httpResponse.addHeader("X-" + param, httpRequest.getParameter(param)); - requestBody.append(param); - requestBody.append("_"); - } - - String pathInfo = httpRequest.getPathInfo(); - if (pathInfo != null) - httpResponse.addHeader("X-pathInfo", pathInfo); - - String queryString = httpRequest.getQueryString(); - if (queryString != null) - httpResponse.addHeader("X-queryString", queryString); - - httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort()); - - Cookie[] cs = httpRequest.getCookies(); - if (cs != null) { - for (Cookie c : cs) { - httpResponse.addCookie(c); - } - } - - if (requestBody.length() > 0) { - httpResponse.getOutputStream().write(requestBody.toString().getBytes()); - } - - int size = 10 * 1024; - if (httpRequest.getContentLength() > 0) { - size = httpRequest.getContentLength(); - } - byte[] bytes = new byte[size]; - int pos = 0; - if (bytes.length > 0) { - int read = 0; - while (read != -1) { - read = httpRequest.getInputStream().read(bytes, pos, bytes.length - pos); - pos += read; - } - - httpResponse.getOutputStream().write(bytes); - } - - httpResponse.setStatus(200); - httpResponse.getOutputStream().flush(); - httpResponse.getOutputStream().close(); - } - } - - public AbstractHandler configureHandler() throws Exception { - return new EchoHandler(); - } - protected String getTargetUrl() { return String.format("https://127.0.0.1:%d/foo/test", port1); } @Test(groups = { "standalone", "default_provider" }) - public void zeroCopyPostTest() throws Throwable { + public void zeroCopyPostTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void multipleSSLRequestsTest() throws Throwable { + public void multipleSSLRequestsTest() throws Exception { final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { String body = "hello there"; @@ -171,7 +72,7 @@ public void multipleSSLRequestsTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void multipleSSLWithoutCacheTest() throws Throwable { + public void multipleSSLWithoutCacheTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build()); try { String body = "hello there"; @@ -188,7 +89,7 @@ public void multipleSSLWithoutCacheTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void reconnectsAfterFailedCertificationPath() throws Throwable { + public void reconnectsAfterFailedCertificationPath() throws Exception { AtomicBoolean trusted = new AtomicBoolean(false); AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build()); try { @@ -203,7 +104,7 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable { assertNotNull(cause.getCause()); assertTrue(cause.getCause() instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause.getCause()); } else { - assertTrue(cause.getCause() instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause); + assertTrue(cause instanceof SSLHandshakeException, "Expected an SSLHandshakeException, got a " + cause); } } @@ -217,50 +118,4 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable { c.close(); } } - - private static SSLContext createSSLContext(AtomicBoolean trusted) { - InputStream keyStoreStream = BasicHttpsTest.class.getResourceAsStream("ssltest-cacerts.jks"); - try { - char[] keyStorePassword = "changeit".toCharArray(); - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(keyStoreStream, keyStorePassword); - - // Set up key manager factory to use our key store - char[] certificatePassword = "changeit".toCharArray(); - KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); - kmf.init(ks, certificatePassword); - - // Initialize the SSLContext to work with our key managers. - KeyManager[] keyManagers = kmf.getKeyManagers(); - TrustManager[] trustManagers = new TrustManager[] { dummyTrustManager(trusted) }; - SecureRandom secureRandom = new SecureRandom(); - - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(keyManagers, trustManagers, secureRandom); - - return sslContext; - } catch (Exception e) { - throw new Error("Failed to initialize the server-side SSLContext", e); - } finally { - IOUtils.closeQuietly(keyStoreStream); - } - } - - private static final TrustManager dummyTrustManager(final AtomicBoolean trusted) { - return new X509TrustManager() { - - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - if (!trusted.get()) { - throw new CertificateException("Server certificate not trusted."); - } - } - }; - } } diff --git a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java index 46ee31059d..e6d19b6401 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java @@ -32,7 +32,7 @@ public abstract class BodyChunkTest extends AbstractBasicTest { private static final String MY_MESSAGE = "my message"; @Test(groups = { "standalone", "default_provider" }) - public void negativeContentTypeTest() throws Throwable { + public void negativeContentTypeTest() throws Exception { AsyncHttpClientConfig.Builder confbuilder = new AsyncHttpClientConfig.Builder(); confbuilder = confbuilder.setConnectionTimeoutInMs(100); diff --git a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java index 64dda4e63f..09e16e9763 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java @@ -12,21 +12,11 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.BodyDeferringAsyncHandler; -import org.asynchttpclient.BodyDeferringAsyncHandler.BodyDeferringInputStream; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.apache.commons.io.IOUtils.copy; +import static org.asynchttpclient.async.util.TestUtils.findFreePort; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; @@ -34,8 +24,18 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeoutException; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.BodyDeferringAsyncHandler; +import org.asynchttpclient.BodyDeferringAsyncHandler.BodyDeferringInputStream; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; public abstract class BodyDeferringAsyncHandlerTest extends AbstractBasicTest { @@ -98,18 +98,6 @@ public int getByteCount() { } } - // simple stream copy just to "consume". It closes streams. - public static void copy(InputStream in, OutputStream out) throws IOException { - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - out.flush(); - out.close(); - in.close(); - } - public AbstractHandler configureHandler() throws Exception { return new SlowAndBigHandler(); } @@ -131,16 +119,16 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce Response resp = bdah.getResponse(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); + assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG)); // we got headers only, it's probably not all yet here (we have BIG file // downloading) - assertEquals(true, HALF_GIG >= cos.getByteCount()); + assertTrue(cos.getByteCount() <= HALF_GIG); // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) f.get(); // it all should be here now - assertEquals(true, HALF_GIG == cos.getByteCount()); + assertEquals(cos.getByteCount(), HALF_GIG); } finally { client.close(); } @@ -150,7 +138,8 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce public void deferredSimpleWithFailure() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(getAsyncHttpClientConfig()); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredSimpleWithFailure").addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredSimpleWithFailure").addHeader("X-FAIL-TRANSFER", + Boolean.TRUE.toString()); CountingOutputStream cos = new CountingOutputStream(); BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(cos); @@ -158,21 +147,21 @@ public void deferredSimpleWithFailure() throws IOException, ExecutionException, Response resp = bdah.getResponse(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); + assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG)); // we got headers only, it's probably not all yet here (we have BIG file // downloading) - assertEquals(true, HALF_GIG >= cos.getByteCount()); + assertTrue(cos.getByteCount() <= HALF_GIG); // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) try { f.get(); - Assert.fail("get() should fail with IOException!"); + fail("get() should fail with IOException!"); } catch (Exception e) { // good } // it's incomplete, there was an error - assertEquals(false, HALF_GIG == cos.getByteCount()); + assertNotEquals(cos.getByteCount(), HALF_GIG); } finally { client.close(); } @@ -195,15 +184,20 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T Response resp = is.getAsapResponse(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); + assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG)); // "consume" the body, but our code needs input stream CountingOutputStream cos = new CountingOutputStream(); - copy(is, cos); + try { + copy(is, cos); + } finally { + is.close(); + cos.close(); + } // now we don't need to be polite, since consuming and closing // BodyDeferringInputStream does all. // it all should be here now - assertEquals(true, HALF_GIG == cos.getByteCount()); + assertEquals(cos.getByteCount(), HALF_GIG); } finally { client.close(); } @@ -212,26 +206,32 @@ public void deferredInputStreamTrick() throws IOException, ExecutionException, T @Test(groups = { "standalone", "default_provider" }) public void deferredInputStreamTrickWithFailure() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(getAsyncHttpClientConfig()); - + try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER", Boolean.TRUE.toString()); + AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/deferredInputStreamTrickWithFailure").addHeader("X-FAIL-TRANSFER", + Boolean.TRUE.toString()); PipedOutputStream pos = new PipedOutputStream(); PipedInputStream pis = new PipedInputStream(pos); BodyDeferringAsyncHandler bdah = new BodyDeferringAsyncHandler(pos); - + Future f = r.execute(bdah); - + BodyDeferringInputStream is = new BodyDeferringInputStream(f, bdah, pis); - + Response resp = is.getAsapResponse(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(true, resp.getHeader("content-length").equals(String.valueOf(HALF_GIG))); + assertEquals(resp.getHeader("content-length"), String.valueOf(HALF_GIG)); // "consume" the body, but our code needs input stream CountingOutputStream cos = new CountingOutputStream(); try { - copy(is, cos); - Assert.fail("InputStream consumption should fail with IOException!"); + try { + copy(is, cos); + } finally { + is.close(); + cos.close(); + } + fail("InputStream consumption should fail with IOException!"); } catch (IOException e) { // good! } @@ -252,7 +252,7 @@ public void testConnectionRefused() throws IOException, ExecutionException, Time r.execute(bdah); try { bdah.getResponse(); - Assert.fail("IOException should be thrown here!"); + fail("IOException should be thrown here!"); } catch (IOException e) { // good } diff --git a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java index 1a6763a43f..47c453e886 100644 --- a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java @@ -12,32 +12,32 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.createTempFile; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; -import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; -import static org.testng.Assert.*; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; public abstract class ByteBufferCapacityTest extends AbstractBasicTest { - private static final File TMP = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); private class BasicHandler extends AbstractHandler { - public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { + public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { Enumeration e = httpRequest.getHeaderNames(); String param; @@ -72,12 +72,10 @@ public AbstractHandler configureHandler() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void basicByteBufferTest() throws Throwable { + public void basicByteBufferTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { - byte[] bytes = "RatherLargeFileRatherLargeFileRatherLargeFileRatherLargeFile".getBytes("UTF-16"); - long repeats = (1024 * 100 * 10 / bytes.length) + 1; - File largeFile = createTempFile(bytes, (int) repeats); + File largeFile = createTempFile(1024 * 100 * 10); final AtomicInteger byteReceived = new AtomicInteger(); try { @@ -106,29 +104,4 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep public String getTargetUrl() { return String.format("http://127.0.0.1:%d/foo/test", port1); } - - public static File createTempFile(byte[] pattern, int repeat) throws IOException { - TMP.mkdirs(); - TMP.deleteOnExit(); - File tmpFile = File.createTempFile("tmpfile-", ".data", TMP); - write(pattern, repeat, tmpFile); - - return tmpFile; - } - - public static void write(byte[] pattern, int repeat, File file) throws IOException { - file.deleteOnExit(); - file.getParentFile().mkdirs(); - FileOutputStream out = null; - try { - out = new FileOutputStream(file); - for (int i = 0; i < repeat; i++) { - out.write(pattern); - } - } finally { - if (out != null) { - out.close(); - } - } - } } diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index 52f8d00722..66e9ef3692 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -12,7 +12,8 @@ */ package org.asynchttpclient.async; -import static org.testng.AssertJUnit.*; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; import static org.testng.FileAssert.fail; import java.io.BufferedInputStream; @@ -39,7 +40,7 @@ abstract public class ChunkingTest extends AbstractBasicTest { * Tests that the custom chunked stream result in success and content returned that is unchunked */ @Test() - public void testCustomChunking() throws Throwable { + public void testCustomChunking() throws Exception { AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder(); bc.setAllowPoolingConnection(true); @@ -61,16 +62,17 @@ public void testCustomChunking() throws Throwable { Response response = c.executeRequest(r).get(); if (500 == response.getStatusCode()) { - System.out.println("=============="); - System.out.println("500 response from call"); - System.out.println("Headers:" + response.getHeaders()); - System.out.println("=============="); - System.out.flush(); - assertEquals("Should have 500 status code", 500, response.getStatusCode()); - assertTrue("Should have failed due to chunking", response.getHeader("X-Exception").contains("invalid.chunk.length")); + StringBuilder sb = new StringBuilder(); + sb.append("==============\n"); + sb.append("500 response from call\n"); + sb.append("Headers:" + response.getHeaders() + "\n"); + sb.append("==============\n"); + logger.debug(sb.toString()); + assertEquals(response.getStatusCode(), 500, "Should have 500 status code"); + assertTrue(response.getHeader("X-Exception").contains("invalid.chunk.length"), "Should have failed due to chunking"); fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception")); } else { - assertEquals(LARGE_IMAGE_BYTES, response.getResponseBodyAsBytes()); + assertEquals(response.getResponseBodyAsBytes(), LARGE_IMAGE_BYTES); } } finally { c.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/ComplexClientTest.java b/api/src/test/java/org/asynchttpclient/async/ComplexClientTest.java index 8bf0bc6e6e..39194b33d6 100644 --- a/api/src/test/java/org/asynchttpclient/async/ComplexClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ComplexClientTest.java @@ -15,18 +15,18 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Response; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import java.util.concurrent.TimeUnit; -import static org.testng.Assert.assertEquals; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Response; +import org.testng.annotations.Test; public abstract class ComplexClientTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }) - public void multipleRequestsTest() throws Throwable { + public void multipleRequestsTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { String body = "hello there"; @@ -46,7 +46,7 @@ public void multipleRequestsTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void urlWithoutSlashTest() throws Throwable { + public void urlWithoutSlashTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { String body = "hello there"; diff --git a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java index 8523f82697..8bce85b03f 100644 --- a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java @@ -15,15 +15,7 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncCompletionHandler; -import org.asynchttpclient.AsyncCompletionHandlerBase; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.testng.Assert.*; import java.io.IOException; import java.util.Map; @@ -33,10 +25,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; +import org.asynchttpclient.AsyncCompletionHandler; +import org.asynchttpclient.AsyncCompletionHandlerBase; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Response; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.Test; public abstract class ConnectionPoolTest extends AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); @@ -93,7 +89,7 @@ public void testMaxTotalConnectionsException() { } @Test(groups = { "standalone", "default_provider", "async" }, enabled = true, invocationCount = 10, alwaysRun = true) - public void asyncDoGetKeepAliveHandlerTest_channelClosedDoesNotFail() throws Throwable { + public void asyncDoGetKeepAliveHandlerTest_channelClosedDoesNotFail() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { // Use a l in case the assert fail @@ -122,7 +118,7 @@ public Response onCompleted(Response response) throws Exception { client.prepareGet(getTargetUrl()).execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timed out"); + fail("Timed out"); } assertEquals(remoteAddresses.size(), 2); @@ -138,7 +134,7 @@ public Response onCompleted(Response response) throws Exception { public abstract void testValidConnectionsPool(); @Test(groups = { "standalone", "default_provider" }) - public void multipleMaxConnectionOpenTest() throws Throwable { + public void multipleMaxConnectionOpenTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setConnectionTimeoutInMs(5000).setMaximumConnectionsTotal(1).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { @@ -166,7 +162,7 @@ public void multipleMaxConnectionOpenTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void multipleMaxConnectionOpenTestWithQuery() throws Throwable { + public void multipleMaxConnectionOpenTestWithQuery() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setConnectionTimeoutInMs(5000).setMaximumConnectionsTotal(1).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { @@ -196,11 +192,11 @@ public void multipleMaxConnectionOpenTestWithQuery() throws Throwable { /** * This test just make sure the hack used to catch disconnected channel under win7 doesn't throw any exception. The onComplete method must be only called once. * - * @throws Throwable + * @throws Exception * if something wrong happens. */ @Test(groups = { "standalone", "default_provider" }) - public void win7DisconnectTest() throws Throwable { + public void win7DisconnectTest() throws Exception { final AtomicInteger count = new AtomicInteger(0); AsyncHttpClient client = getAsyncHttpClient(null); @@ -233,7 +229,7 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void asyncHandlerOnThrowableTest() throws Throwable { + public void asyncHandlerOnThrowableTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicInteger count = new AtomicInteger(); diff --git a/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java b/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java index 7d4427192b..52c3789e89 100644 --- a/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/DigestAuthTest.java @@ -12,96 +12,41 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Realm; -import org.asynchttpclient.Response; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.LoginService; -import org.eclipse.jetty.security.authentication.DigestAuthenticator; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.util.security.Constraint; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; public abstract class DigestAuthTest extends AbstractBasicTest { - private static final String USER = "user"; - private static final String ADMIN = "admin"; - @BeforeClass(alwaysRun = true) @Override public void setUpGlobal() throws Exception { - server = new Server(); - Logger root = Logger.getRootLogger(); - root.setLevel(Level.DEBUG); - root.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN))); - port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - LoginService loginService = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); - server.addBean(loginService); - - Constraint constraint = new Constraint(); - constraint.setName(Constraint.__BASIC_AUTH); - constraint.setRoles(new String[] { USER, ADMIN }); - constraint.setAuthenticate(true); - - ConstraintMapping mapping = new ConstraintMapping(); - mapping.setConstraint(constraint); - mapping.setPathSpec("/*"); - List cm = new ArrayList(); - cm.add(mapping); - - Set knownRoles = new HashSet(); - knownRoles.add(USER); - knownRoles.add(ADMIN); - - ConstraintSecurityHandler security = new ConstraintSecurityHandler(); - security.setConstraintMappings(cm, knownRoles); - security.setAuthenticator(new DigestAuthenticator()); - security.setLoginService(loginService); - security.setStrict(false); - - security.setHandler(configureHandler()); - server.setHandler(security); + server = newJettyHttpServer(port1); + addDigestAuthHandler(server, false, configureHandler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } - private class SimpleHandler extends AbstractHandler { + private static class SimpleHandler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.addHeader("X-Auth", request.getHeader("Authorization")); @@ -111,13 +56,18 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR } } + @Override + public AbstractHandler configureHandler() throws Exception { + return new SimpleHandler(); + } + @Test(groups = { "standalone", "default_provider" }) public void digestAuthTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").setScheme(Realm.AuthScheme.DIGEST).build()); - - Future f = r.execute(); + Future f = client.prepareGet("http://127.0.0.1/" + port1 + "/")// + .setRealm(new Realm.RealmBuilder().setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").setScheme(Realm.AuthScheme.DIGEST).build())// + .execute(); Response resp = f.get(60, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); @@ -131,9 +81,9 @@ public void digestAuthTest() throws IOException, ExecutionException, TimeoutExce public void digestAuthTestWithoutScheme() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").build()); - - Future f = r.execute(); + Future f = client.prepareGet("http://127.0.0.1/" + port1 + "/")// + .setRealm(new Realm.RealmBuilder().setPrincipal(USER).setPassword(ADMIN).setRealmName("MyRealm").build())// + .execute(); Response resp = f.get(60, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); @@ -147,9 +97,9 @@ public void digestAuthTestWithoutScheme() throws IOException, ExecutionException public void digestAuthNegativeTest() throws IOException, ExecutionException, TimeoutException, InterruptedException { AsyncHttpClient client = getAsyncHttpClient(null); try { - AsyncHttpClient.BoundRequestBuilder r = client.prepareGet("http://127.0.0.1/" + port1 + "/").setRealm((new Realm.RealmBuilder()).setPrincipal("fake").setPassword(ADMIN).setScheme(Realm.AuthScheme.DIGEST).build()); - - Future f = r.execute(); + Future f = client.prepareGet("http://127.0.0.1/" + port1 + "/")// + .setRealm(new Realm.RealmBuilder().setPrincipal("fake").setPassword(ADMIN).setScheme(Realm.AuthScheme.DIGEST).build())// + .execute(); Response resp = f.get(20, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), 401); @@ -157,9 +107,4 @@ public void digestAuthNegativeTest() throws IOException, ExecutionException, Tim client.close(); } } - - @Override - public AbstractHandler configureHandler() throws Exception { - return new SimpleHandler(); - } } diff --git a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java index aa5fdfbed5..044915333d 100644 --- a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java @@ -83,10 +83,10 @@ public void onThrowable(Throwable t) { public STATE onBodyPartReceived(HttpResponseBodyPart e) throws Exception { String s = new String(e.getBodyPartBytes()); - log.info("got part: {}", s); + logger.info("got part: {}", s); if (s.equals("")) { // noinspection ThrowableInstanceNeverThrown - log.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body.")); + logger.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body.")); } queue.put(s); return STATE.CONTINUE; @@ -124,7 +124,7 @@ public Object onCompleted() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void testPutEmptyBody() throws Throwable { + public void testPutEmptyBody() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(null); try { Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get(); diff --git a/api/src/test/java/org/asynchttpclient/async/ErrorResponseTest.java b/api/src/test/java/org/asynchttpclient/async/ErrorResponseTest.java index 97d038f59a..c8d3cd30d3 100644 --- a/api/src/test/java/org/asynchttpclient/async/ErrorResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ErrorResponseTest.java @@ -68,8 +68,7 @@ public void testQueryParameters() throws Exception { Response resp = f.get(3, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), 400); - String respStr = resp.getResponseBody(); - assertEquals(BAD_REQUEST_STR, respStr); + assertEquals(resp.getResponseBody(), BAD_REQUEST_STR); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java index a0d8a4c7ce..a1de248e24 100644 --- a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java +++ b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java @@ -15,29 +15,28 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; + +import java.io.IOException; +import java.util.concurrent.Future; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.concurrent.Future; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; /** * Test the Expect: 100-Continue. */ public abstract class Expect100ContinueTest extends AbstractBasicTest { - private class ZeroCopyHandler extends AbstractHandler { + private static class ZeroCopyHandler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { int size = 10 * 1024; @@ -55,26 +54,22 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ } } + @Override + public AbstractHandler configureHandler() throws Exception { + return new ZeroCopyHandler(); + } + @Test(groups = { "standalone", "default_provider" }) - public void Expect100Continue() throws Throwable { + public void Expect100Continue() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - ClassLoader cl = getClass().getClassLoader(); - URL url = cl.getResource("SimpleTextFile.txt"); - File file = new File(url.toURI()); - - Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setHeader("Expect", "100-continue").setBody(file).execute(); + Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setHeader("Expect", "100-continue").setBody(SIMPLE_TEXT_FILE).execute(); Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } - - @Override - public AbstractHandler configureHandler() throws Exception { - return new ZeroCopyHandler(); - } } diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index dd87e925d5..b6a14f2d39 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -12,6 +12,9 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.assertEquals; + import java.io.File; import java.io.IOException; @@ -26,36 +29,10 @@ import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; import org.testng.annotations.Test; public abstract class FilePartLargeFileTest extends AbstractBasicTest { - @Test(groups = { "standalone", "default_provider" }, enabled = true) - public void testPutImageFile() throws Exception { - AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build()); - try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(); - Assert.assertEquals(200, response.getStatusCode()); - } finally { - client.close(); - } - } - - @Test(groups = { "standalone", "default_provider" }, enabled = true) - public void testPutLargeTextFile() throws Exception { - long repeats = (1024 * 1024 / PATTERN_BYTES.length) + 1; - File file = createTempFile(PATTERN_BYTES, (int) repeats); - - AsyncHttpClient client = getAsyncHttpClient(null); - try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(); - Assert.assertEquals(200, response.getStatusCode()); - } finally { - client.close(); - } - } - @Override public AbstractHandler configureHandler() throws Exception { return new AbstractHandler() { @@ -80,4 +57,28 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle } }; } + + @Test(groups = { "standalone", "default_provider" }, enabled = true) + public void testPutImageFile() throws Exception { + AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build()); + try { + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(); + assertEquals(response.getStatusCode(), 200); + } finally { + client.close(); + } + } + + @Test(groups = { "standalone", "default_provider" }, enabled = true) + public void testPutLargeTextFile() throws Exception { + File file = createTempFile(1024 * 1024); + + AsyncHttpClient client = getAsyncHttpClient(null); + try { + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(); + assertEquals(response.getStatusCode(), 200); + } finally { + client.close(); + } + } } diff --git a/api/src/test/java/org/asynchttpclient/async/FilterTest.java b/api/src/test/java/org/asynchttpclient/async/FilterTest.java index 6f843e5c44..8f4c90725e 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilterTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilterTest.java @@ -40,7 +40,7 @@ public abstract class FilterTest extends AbstractBasicTest { - private class BasicHandler extends AbstractHandler { + private static class BasicHandler extends AbstractHandler { public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { @@ -62,8 +62,12 @@ public AbstractHandler configureHandler() throws Exception { return new BasicHandler(); } + public String getTargetUrl() { + return String.format("http://127.0.0.1:%d/foo/test", port1); + } + @Test(groups = { "standalone", "default_provider" }) - public void basicTest() throws Throwable { + public void basicTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); b.addRequestFilter(new ThrottleRequestFilter(100)); @@ -78,7 +82,7 @@ public void basicTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void loadThrottleTest() throws Throwable { + public void loadThrottleTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); b.addRequestFilter(new ThrottleRequestFilter(10)); @@ -100,7 +104,7 @@ public void loadThrottleTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void maxConnectionsText() throws Throwable { + public void maxConnectionsText() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); b.addRequestFilter(new ThrottleRequestFilter(0, 1000)); AsyncHttpClient c = getAsyncHttpClient(b.build()); @@ -116,12 +120,8 @@ public void maxConnectionsText() throws Throwable { } } - public String getTargetUrl() { - return String.format("http://127.0.0.1:%d/foo/test", port1); - } - @Test(groups = { "standalone", "default_provider" }) - public void basicResponseFilterTest() throws Throwable { + public void basicResponseFilterTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); b.addResponseFilter(new ResponseFilter() { @@ -146,7 +146,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException } @Test(groups = { "standalone", "default_provider" }) - public void replayResponseFilterTest() throws Throwable { + public void replayResponseFilterTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); final AtomicBoolean replay = new AtomicBoolean(true); @@ -178,7 +178,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException } @Test(groups = { "standalone", "default_provider" }) - public void replayStatusCodeResponseFilterTest() throws Throwable { + public void replayStatusCodeResponseFilterTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); final AtomicBoolean replay = new AtomicBoolean(true); @@ -210,7 +210,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException } @Test(groups = { "standalone", "default_provider" }) - public void replayHeaderResponseFilterTest() throws Throwable { + public void replayHeaderResponseFilterTest() throws Exception { AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); final AtomicBoolean replay = new AtomicBoolean(true); diff --git a/api/src/test/java/org/asynchttpclient/async/FluentCaseInsensitiveStringsMapTest.java b/api/src/test/java/org/asynchttpclient/async/FluentCaseInsensitiveStringsMapTest.java index d586318015..97797d1396 100644 --- a/api/src/test/java/org/asynchttpclient/async/FluentCaseInsensitiveStringsMapTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FluentCaseInsensitiveStringsMapTest.java @@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue; public class FluentCaseInsensitiveStringsMapTest { + @Test public void emptyTest() { FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(); @@ -315,7 +316,7 @@ public void deleteAllCollectionTest() { map.deleteAll(Arrays.asList("bAz", "fOO")); - assertEquals(map.keySet(), Collections.emptyList()); + assertEquals(map.keySet(), Collections. emptyList()); assertNull(map.getFirstValue("foo")); assertNull(map.getJoinedValue("foo", ", ")); assertNull(map.get("foo")); diff --git a/api/src/test/java/org/asynchttpclient/async/FluentStringsMapTest.java b/api/src/test/java/org/asynchttpclient/async/FluentStringsMapTest.java index ffbb651a7a..3a04b962d6 100644 --- a/api/src/test/java/org/asynchttpclient/async/FluentStringsMapTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FluentStringsMapTest.java @@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue; public class FluentStringsMapTest { + @Test public void emptyTest() { FluentStringsMap map = new FluentStringsMap(); @@ -364,7 +365,7 @@ public void deleteAllCollectionTest() { map.deleteAll(Arrays.asList("baz", "foo")); - assertEquals(map.keySet(), Collections.emptyList()); + assertEquals(map.keySet(), Collections. emptyList()); assertNull(map.getFirstValue("foo")); assertNull(map.getJoinedValue("foo", ", ")); assertNull(map.get("foo")); diff --git a/api/src/test/java/org/asynchttpclient/async/Head302Test.java b/api/src/test/java/org/asynchttpclient/async/Head302Test.java index a01b47c910..e19936ec4b 100644 --- a/api/src/test/java/org/asynchttpclient/async/Head302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/Head302Test.java @@ -15,18 +15,8 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncCompletionHandlerBase; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.testng.Assert.fail; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CountDownLatch; @@ -34,16 +24,29 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncCompletionHandlerBase; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; + /** * Tests HEAD request that gets 302 response. * * @author Hubert Iwaniuk */ public abstract class Head302Test extends AbstractBasicTest { + /** * Handler that does Found (302) in response to HEAD method. */ - private class Head302handler extends AbstractHandler { + private static class Head302handler extends AbstractHandler { public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("HEAD".equalsIgnoreCase(request.getMethod())) { if (request.getPathInfo().endsWith("_moved")) { @@ -52,12 +55,17 @@ public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequ response.setStatus(HttpServletResponse.SC_FOUND); // 302 response.setHeader("Location", request.getPathInfo() + "_moved"); } - } else { // this handler is to handle HEAD reqeust + } else { // this handler is to handle HEAD request response.setStatus(HttpServletResponse.SC_FORBIDDEN); } } } + @Override + public AbstractHandler configureHandler() throws Exception { + return new Head302handler(); + } + @Test(groups = { "standalone", "default_provider" }) public void testHEAD302() throws IOException, BrokenBarrierException, InterruptedException, ExecutionException, TimeoutException { AsyncHttpClient client = getAsyncHttpClient(null); @@ -74,15 +82,10 @@ public Response onCompleted(Response response) throws Exception { }).get(3, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { client.close(); } } - - @Override - public AbstractHandler configureHandler() throws Exception { - return new Head302handler(); - } } diff --git a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java index 989e78b280..0e2fb055b9 100644 --- a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java @@ -12,27 +12,18 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; import java.io.IOException; -import java.io.InputStream; import java.net.ConnectException; -import java.security.KeyStore; -import java.security.SecureRandom; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; import java.util.Enumeration; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -55,7 +46,7 @@ public static class EchoHandler extends AbstractHandler { /* @Override */ public void handle(String pathInContext, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException { - httpResponse.setContentType("text/html; charset=utf-8"); + httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration e = httpRequest.getHeaderNames(); String param; while (e.hasMoreElements()) { @@ -134,24 +125,24 @@ public AbstractHandler configureHandler() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void positiveHostnameVerifierTest() throws Throwable { + public void positiveHostnameVerifierTest() throws Exception { - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new PositiveHostVerifier()).setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new PositiveHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { Future f = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute(); Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void negativeHostnameVerifierTest() throws Throwable { + public void negativeHostnameVerifierTest() throws Exception { - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new NegativeHostVerifier()).setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new NegativeHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { try { client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); @@ -165,9 +156,9 @@ public void negativeHostnameVerifierTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void remoteIDHostnameVerifierTest() throws Throwable { + public void remoteIDHostnameVerifierTest() throws Exception { - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("bouette")).setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("bouette")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); @@ -179,9 +170,9 @@ public void remoteIDHostnameVerifierTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void remoteNegHostnameVerifierTest() throws Throwable { + public void remoteNegHostnameVerifierTest() throws Exception { // request is made to 127.0.0.1, but cert presented for localhost - this should fail - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("localhost")).setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("localhost")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); @@ -193,14 +184,14 @@ public void remoteNegHostnameVerifierTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void remotePosHostnameVerifierTest() throws Throwable { + public void remotePosHostnameVerifierTest() throws Exception { - final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("127.0.0.1")).setSSLContext(createSSLContext()).build()); + final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("127.0.0.1")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } @@ -232,46 +223,4 @@ public boolean verify(String s, SSLSession sslSession) { return s != null && s.equalsIgnoreCase(hostName); } } - - private static SSLContext createSSLContext() { - try { - InputStream keyStoreStream = HostnameVerifierTest.class.getResourceAsStream("ssltest-cacerts.jks"); - char[] keyStorePassword = "changeit".toCharArray(); - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(keyStoreStream, keyStorePassword); - - // Set up key manager factory to use our key store - char[] certificatePassword = "changeit".toCharArray(); - KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); - kmf.init(ks, certificatePassword); - - // Initialize the SSLContext to work with our key managers. - KeyManager[] keyManagers = kmf.getKeyManagers(); - TrustManager[] trustManagers = new TrustManager[] { DUMMY_TRUST_MANAGER }; - SecureRandom secureRandom = new SecureRandom(); - - SSLContext sslContext = SSLContext.getInstance("TLS"); - sslContext.init(keyManagers, trustManagers, secureRandom); - - return sslContext; - } catch (Exception e) { - throw new Error("Failed to initialize the server-side SSLContext", e); - } - } - - private static final AtomicBoolean TRUST_SERVER_CERT = new AtomicBoolean(true); - private static final TrustManager DUMMY_TRUST_MANAGER = new X509TrustManager() { - public X509Certificate[] getAcceptedIssuers() { - return new X509Certificate[0]; - } - - public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { - } - - public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { - if (!TRUST_SERVER_CERT.get()) { - throw new CertificateException("Server certificate not trusted."); - } - } - }; } diff --git a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java index a0aa1eac15..e9c6ae6c8d 100644 --- a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java @@ -15,11 +15,10 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; -import java.io.File; import java.io.IOException; -import java.net.URL; import java.util.Enumeration; import java.util.concurrent.atomic.AtomicBoolean; @@ -30,12 +29,8 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.server.ssl.SslSocketConnector; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -48,7 +43,7 @@ private class Relative302Handler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { String param; - httpResponse.setContentType("text/html; charset=utf-8"); + httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration e = httpRequest.getHeaderNames(); while (e.hasMoreElements()) { param = e.nextElement().toString(); @@ -75,50 +70,19 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); port2 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - server.addConnector(listener); - - SslSocketConnector connector = new SslSocketConnector(); - connector.setHost("127.0.0.1"); - connector.setPort(port2); - - ClassLoader cl = getClass().getClassLoader(); - // override system properties - URL cacertsUrl = cl.getResource("ssltest-cacerts.jks"); - String trustStoreFile = new File(cacertsUrl.toURI()).getAbsolutePath(); - connector.setTruststore(trustStoreFile); - connector.setTrustPassword("changeit"); - connector.setTruststoreType("JKS"); - - log.info("SSL certs path: {}", trustStoreFile); - - // override system properties - URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); - String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); - connector.setKeystore(keyStoreFile); - connector.setKeyPassword("changeit"); - connector.setKeystoreType("JKS"); - - log.info("SSL keystore path: {}", keyStoreFile); - - server.addConnector(connector); - + server = newJettyHttpServer(port1); + addHttpsConnector(server, port2); server.setHandler(new Relative302Handler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @Test(groups = { "standalone", "default_provider" }) // FIXME find a way to make this threadsafe, other, set @Test(singleThreaded = true) - public void httpToHttpsRunAllTestsSequentially() throws Exception { + public void runAllSequentiallyBecauseNotThreadSafe() throws Exception { httpToHttpsRedirect(); httpToHttpsProperConfig(); relativeLocationUrl(); diff --git a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java index f5cc4d5b35..3837b799c8 100644 --- a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java @@ -15,6 +15,7 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.fail; import java.io.IOException; @@ -26,11 +27,8 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -53,22 +51,15 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - server.addConnector(listener); - + server = newJettyHttpServer(port1); server.setHandler(new IdleStateHandler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @Test(groups = { "online", "default_provider" }) - public void idleStateTest() throws Throwable { + public void idleStateTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(10 * 1000).build(); AsyncHttpClient c = getAsyncHttpClient(cg); diff --git a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java index 4cf034ada7..a519385473 100644 --- a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java +++ b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java @@ -36,7 +36,7 @@ public abstract class InputStreamTest extends AbstractBasicTest { - private class InputStreamHandler extends AbstractHandler { + private static class InputStreamHandler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("POST".equalsIgnoreCase(request.getMethod())) { byte[] bytes = new byte[3]; @@ -59,6 +59,11 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR } } + @Override + public AbstractHandler configureHandler() throws Exception { + return new InputStreamHandler(); + } + @Test(groups = { "standalone", "default_provider" }) public void testInvalidInputStream() throws IOException, ExecutionException, TimeoutException, InterruptedException { @@ -99,9 +104,4 @@ public int read() throws IOException { c.close(); } } - - @Override - public AbstractHandler configureHandler() throws Exception { - return new InputStreamHandler(); - } } diff --git a/api/src/test/java/org/asynchttpclient/async/ListenableFutureTest.java b/api/src/test/java/org/asynchttpclient/async/ListenableFutureTest.java index 9f9f9ef5fd..3c026d8d57 100644 --- a/api/src/test/java/org/asynchttpclient/async/ListenableFutureTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ListenableFutureTest.java @@ -28,7 +28,7 @@ public abstract class ListenableFutureTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }) - public void testListenableFuture() throws Throwable { + public void testListenableFuture() throws Exception { final AtomicInteger statusCode = new AtomicInteger(500); AsyncHttpClient ahc = getAsyncHttpClient(null); try { diff --git a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java index 8bcdb499f0..94e76c64e9 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxConnectionsInThreads.java @@ -16,20 +16,9 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.net.URI; @@ -37,7 +26,19 @@ import java.util.ArrayList; import java.util.List; -import static org.testng.AssertJUnit.assertTrue; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; abstract public class MaxConnectionsInThreads extends AbstractBasicTest { @@ -49,7 +50,8 @@ public void testMaxConnectionsWithinThreads() { String[] urls = new String[] { servletEndpointUri.toString(), servletEndpointUri.toString() }; - final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(1000).setRequestTimeoutInMs(5000).setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).setMaximumConnectionsPerHost(1).build()); + final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(1000).setRequestTimeoutInMs(5000) + .setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).setMaximumConnectionsPerHost(1).build()); try { final Boolean[] caughtError = new Boolean[] { Boolean.FALSE }; @@ -62,7 +64,7 @@ public void run() { client.prepareGet(url).execute(); } catch (IOException e) { // assert that 2nd request fails, because maxTotalConnections=1 - // System.out.println(i); + // logger.debug(i); caughtError[0] = true; System.err.println("============"); e.printStackTrace(); @@ -92,7 +94,7 @@ public void run() { e1.printStackTrace(); } - assertTrue("Max Connections should have been reached", caughtError[0]); + assertTrue(caughtError[0], "Max Connections should have been reached"); boolean errorInNotThread = false; for (int i = 0; i < urls.length; i++) { @@ -102,7 +104,7 @@ public void run() { // client.prepareGet(url).execute(); } catch (IOException e) { // assert that 2nd request fails, because maxTotalConnections=1 - // System.out.println(i); + // logger.debug(i); errorInNotThread = true; System.err.println("============"); e.printStackTrace(); @@ -116,7 +118,7 @@ public void run() { // TODO Auto-generated catch block e1.printStackTrace(); } - assertTrue("Max Connections should have been reached", errorInNotThread); + assertTrue(errorInNotThread, "Max Connections should have been reached"); } finally { client.close(); } @@ -126,28 +128,18 @@ public void run() { @BeforeClass public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); + server = newJettyHttpServer(port1); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); server.setHandler(context); - context.addServlet(new ServletHolder(new MockTimeoutHttpServlet()), "/timeout/*"); server.start(); String endpoint = "http://127.0.0.1/" + port1 + "/timeout/"; servletEndpointUri = new URI(endpoint); - } public String getTargetUrl() { @@ -162,6 +154,7 @@ public String getTargetUrl() { @SuppressWarnings("serial") public static class MockTimeoutHttpServlet extends HttpServlet { + private static final Logger LOGGER = LoggerFactory.getLogger(MockTimeoutHttpServlet.class); private static final String contentType = "text/plain"; public static long DEFAULT_TIMEOUT = 2000; @@ -177,15 +170,13 @@ public void service(HttpServletRequest req, HttpServletResponse res) throws Serv } try { - System.out.println("======================================="); - System.out.println("Servlet is sleeping for: " + sleepTime); - System.out.println("======================================="); - System.out.flush(); + LOGGER.debug("======================================="); + LOGGER.debug("Servlet is sleeping for: " + sleepTime); + LOGGER.debug("======================================="); Thread.sleep(sleepTime); - System.out.println("======================================="); - System.out.println("Servlet is awake for"); - System.out.println("======================================="); - System.out.flush(); + LOGGER.debug("======================================="); + LOGGER.debug("Servlet is awake for"); + LOGGER.debug("======================================="); } catch (Exception e) { } diff --git a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java index 947d36c554..e2765f3a3e 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java @@ -20,7 +20,7 @@ import org.asynchttpclient.Response; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testng.Assert; +import static org.testng.Assert.*; import org.testng.annotations.Test; import java.io.IOException; @@ -44,11 +44,11 @@ public void testMaxTotalConnectionsExceedingException() { client.prepareGet(urls[i]).execute(); } catch (IOException e) { // assert that 2nd request fails, because maxTotalConnections=1 - Assert.assertEquals(1, i); + assertEquals(i, 1); caughtError = true; } } - Assert.assertTrue(caughtError); + assertTrue(caughtError); } finally { client.close(); } @@ -64,7 +64,7 @@ public void testMaxTotalConnections() { try { client.prepareGet(url).execute(); } catch (IOException e) { - Assert.fail("Smth wrong with connections handling!"); + fail("Smth wrong with connections handling!"); } } } finally { @@ -91,11 +91,11 @@ public void testMaxTotalConnectionsCorrectExceptionHandling() { } } catch (IOException e) { // assert that 2nd request fails, because maxTotalConnections=1 - Assert.assertEquals(i, 1); + assertEquals(i, 1); caughtError = true; } } - Assert.assertTrue(caughtError); + assertTrue(caughtError); // get results of executed requests for (Future future : futures) { @@ -115,11 +115,11 @@ public void testMaxTotalConnectionsCorrectExceptionHandling() { client.prepareGet(urls[i]).execute(); } catch (IOException e) { // assert that 2nd request fails, because maxTotalConnections=1 - Assert.assertEquals(i, 1); + assertEquals(i, 1); caughtError = true; } } - Assert.assertTrue(caughtError); + assertTrue(caughtError); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java index 891781fe19..d9eb881827 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java @@ -12,6 +12,7 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; import java.io.ByteArrayOutputStream; @@ -23,9 +24,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.Writer; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -53,11 +51,10 @@ import org.asynchttpclient.Response; import org.asynchttpclient.StringPart; import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -70,46 +67,21 @@ public abstract class MultipartUploadTest extends AbstractBasicTest { @BeforeClass public void setUp() throws Exception { - server = new Server(); - port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - listener.setHost("localhost"); - listener.setPort(port1); - - server.addConnector(listener); + server = newJettyHttpServer(port1); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); context.addServlet(new ServletHolder(new MockMultipartUploadServlet()), "/upload/*"); server.setHandler(context); server.start(); } - private File getClasspathFile(String file) throws FileNotFoundException { - ClassLoader cl = null; - try { - cl = Thread.currentThread().getContextClassLoader(); - } catch (Throwable ex) { - } - if (cl == null) { - cl = MultipartUploadTest.class.getClassLoader(); - } - URL resourceUrl = cl.getResource(file); - - try { - return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart()); - } catch (URISyntaxException e) { - throw new FileNotFoundException(file); - } - } - /** * Tests that the streaming of a file works. */ - @Test(enabled = true) + @Test public void testSendingSmallFilesAndByteArray() { String expectedContents = "filecontent: hello"; String expectedContents2 = "gzipcontent: hello"; @@ -211,7 +183,7 @@ public void testSendingSmallFilesAndByteArray() { Response res = c.executeRequest(r).get(); - assertEquals(200, res.getStatusCode()); + assertEquals(res.getStatusCode(), 200); testSentFile(expected, testFiles, res, gzipped); @@ -238,14 +210,14 @@ private void testSentFile(List expectedContents, List sourceFiles, try { content = r.getResponseBody(); assertNotNull("===>" + content); - System.out.println(content); + logger.debug(content); } catch (IOException e) { fail("Unable to obtain content"); } String[] contentArray = content.split("\\|\\|"); // TODO: this fail on win32 - assertEquals(2, contentArray.length); + assertEquals(contentArray.length, 2); String tmpFiles = contentArray[1]; assertNotNull(tmpFiles); @@ -254,10 +226,9 @@ private void testSentFile(List expectedContents, List sourceFiles, String[] responseFiles = tmpFiles.split(","); assertNotNull(responseFiles); - assertEquals(sourceFiles.size(), responseFiles.length); + assertEquals(responseFiles.length, sourceFiles.size()); - System.out.println(Arrays.toString(responseFiles)); - // assertTrue("File should exist: " + tmpFile.getAbsolutePath(),tmpFile.exists()); + logger.debug(Arrays.toString(responseFiles)); int i = 0; for (File sourceFile : sourceFiles) { @@ -275,10 +246,10 @@ private void testSentFile(List expectedContents, List sourceFiles, while ((len = instream.read(buf)) > 0) { baos.write(buf, 0, len); } - System.out.println("================"); - System.out.println("Length of file: " + baos.toByteArray().length); - System.out.println("Contents: " + Arrays.toString(baos.toByteArray())); - System.out.println("================"); + logger.debug("================"); + logger.debug("Length of file: " + baos.toByteArray().length); + logger.debug("Contents: " + Arrays.toString(baos.toByteArray())); + logger.debug("================"); System.out.flush(); sourceBytes = baos.toByteArray(); } finally { @@ -286,9 +257,9 @@ private void testSentFile(List expectedContents, List sourceFiles, } tmp = new File(responseFiles[i].trim()); - System.out.println("=============================="); - System.out.println(tmp.getAbsolutePath()); - System.out.println("=============================="); + logger.debug("=============================="); + logger.debug(tmp.getAbsolutePath()); + logger.debug("=============================="); System.out.flush(); assertTrue(tmp.exists()); @@ -301,21 +272,25 @@ private void testSentFile(List expectedContents, List sourceFiles, } IOUtils.closeQuietly(instream); - assertEquals(sourceBytes, baos2.toByteArray()); + assertEquals(baos2.toByteArray(), sourceBytes); if (!deflate.get(i)) { String helloString = new String(baos2.toByteArray()); - assertEquals(expectedContents.get(i), helloString); + assertEquals(helloString, expectedContents.get(i)); } else { instream = new FileInputStream(tmp); - GZIPInputStream deflater = new GZIPInputStream(instream); ByteArrayOutputStream baos3 = new ByteArrayOutputStream(); - byte[] buf3 = new byte[8092]; - int len3 = 0; - while ((len3 = deflater.read(buf3)) > 0) { - baos3.write(buf3, 0, len3); + GZIPInputStream deflater = new GZIPInputStream(instream); + try { + byte[] buf3 = new byte[8092]; + int len3 = 0; + while ((len3 = deflater.read(buf3)) > 0) { + baos3.write(buf3, 0, len3); + } + } finally { + deflater.close(); } String helloString = new String(baos3.toByteArray()); @@ -341,9 +316,9 @@ private void testSentFile(List expectedContents, List sourceFiles, * @author dominict */ public static class MockMultipartUploadServlet extends HttpServlet { - /** - * - */ + + private static final Logger LOGGER = LoggerFactory.getLogger(MockMultipartUploadServlet.class); + private static final long serialVersionUID = 1L; private int filesProcessed = 0; private int stringsProcessed = 0; @@ -397,10 +372,10 @@ public void service(HttpServletRequest request, HttpServletResponse response) th stream = item.openStream(); if (item.isFormField()) { - System.out.println("Form field " + name + " with value " + Streams.asString(stream) + " detected."); + LOGGER.debug("Form field " + name + " with value " + Streams.asString(stream) + " detected."); incrementStringsProcessed(); } else { - System.out.println("File field " + name + " with file name " + item.getName() + " detected."); + LOGGER.debug("File field " + name + " with file name " + item.getName() + " detected."); // Process the input stream OutputStream os = null; try { diff --git a/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java b/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java index ed6c6b413e..f2855e8c7d 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipleHeaderTest.java @@ -12,17 +12,8 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.findFreePort; +import static org.testng.Assert.*; import java.io.BufferedReader; import java.io.IOException; @@ -40,6 +31,17 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + /** * @author Hubert Iwaniuk */ @@ -63,7 +65,7 @@ public Void call() throws Exception { String req = reader.readLine().split(" ")[1]; int i = inputStream.available(); long l = inputStream.skip(i); - Assert.assertEquals(l, i); + assertEquals(l, i); socket.shutdownInput(); if (req.endsWith("MultiEnt")) { OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); @@ -127,16 +129,16 @@ public Void onCompleted() throws Exception { }).get(3, TimeUnit.SECONDS); if (!latch.await(2, TimeUnit.SECONDS)) { - Assert.fail("Time out"); + fail("Time out"); } - Assert.assertNotNull(xffHeaders[0]); - Assert.assertNotNull(xffHeaders[1]); + assertNotNull(xffHeaders[0]); + assertNotNull(xffHeaders[1]); try { - Assert.assertEquals(xffHeaders[0], "abc"); - Assert.assertEquals(xffHeaders[1], "def"); + assertEquals(xffHeaders[0], "abc"); + assertEquals(xffHeaders[1], "def"); } catch (AssertionError ex) { - Assert.assertEquals(xffHeaders[1], "abc"); - Assert.assertEquals(xffHeaders[0], "def"); + assertEquals(xffHeaders[1], "abc"); + assertEquals(xffHeaders[0], "def"); } } finally { ahc.close(); @@ -182,18 +184,18 @@ public Void onCompleted() throws Exception { }).get(3, TimeUnit.SECONDS); if (!latch.await(2, TimeUnit.SECONDS)) { - Assert.fail("Time out"); + fail("Time out"); } - Assert.assertNotNull(clHeaders[0]); - Assert.assertNotNull(clHeaders[1]); + assertNotNull(clHeaders[0]); + assertNotNull(clHeaders[1]); // We can predict the order try { - Assert.assertEquals(clHeaders[0], "2"); - Assert.assertEquals(clHeaders[1], "1"); + assertEquals(clHeaders[0], "2"); + assertEquals(clHeaders[1], "1"); } catch (Throwable ex) { - Assert.assertEquals(clHeaders[0], "1"); - Assert.assertEquals(clHeaders[1], "2"); + assertEquals(clHeaders[0], "1"); + assertEquals(clHeaders[1], "2"); } } finally { ahc.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java index 2e85846920..8d4359b4ea 100644 --- a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java @@ -20,7 +20,7 @@ import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; -import org.testng.Assert; +import static org.testng.Assert.*; import org.testng.annotations.Test; import javax.net.ssl.SSLContext; @@ -34,7 +34,7 @@ public abstract class NoNullResponseTest extends AbstractBasicTest { private static final String GOOGLE_HTTPS_URL = "https://www.google.com/"; @Test(invocationCount = 4, groups = { "online", "default_provider" }) - public void multipleSslRequestsWithDelayAndKeepAlive() throws Throwable { + public void multipleSslRequestsWithDelayAndKeepAlive() throws Exception { final AsyncHttpClient client = create(); try { final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); @@ -46,8 +46,8 @@ public void multipleSslRequestsWithDelayAndKeepAlive() throws Throwable { } else { System.out.println("Failed (2nd response was null)."); } - Assert.assertNotNull(response1); - Assert.assertNotNull(response2); + assertNotNull(response1); + assertNotNull(response2); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java index 156b177a26..cbfdf6546c 100644 --- a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java @@ -12,16 +12,12 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; @@ -29,23 +25,20 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import static org.testng.Assert.assertEquals; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; public abstract class NonAsciiContentLengthTest extends AbstractBasicTest { @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); port1 = findFreePort(); - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - server.addConnector(listener); + server = newJettyHttpServer(port1); server.setHandler(new AbstractHandler() { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java index b94d9a59a6..edc1856ce5 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java @@ -15,20 +15,9 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.ConnectException; import java.net.URI; @@ -36,9 +25,17 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; public abstract class PerRequestRelative302Test extends AbstractBasicTest { @@ -49,7 +46,7 @@ private class Relative302Handler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { String param; - httpResponse.setContentType("text/html; charset=utf-8"); + httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration e = httpRequest.getHeaderNames(); while (e.hasMoreElements()) { param = e.nextElement().toString(); @@ -70,27 +67,22 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); port2 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - server.addConnector(listener); + server = newJettyHttpServer(port1); server.setHandler(new Relative302Handler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @Test(groups = { "online", "default_provider" }) + // FIXME threadsafe public void runAllSequentiallyBecauseNotThreadSafe() throws Exception { redirected302Test(); notRedirected302Test(); relativeLocationUrl(); + redirected302InvalidTest(); } // @Test(groups = { "online", "default_provider" }) @@ -144,8 +136,8 @@ private static int getPort(URI uri) { return port; } - @Test(groups = { "standalone", "default_provider" }) - public void redirected302InvalidTest() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void redirected302InvalidTest() throws Exception { isSet.getAndSet(false); AsyncHttpClient c = getAsyncHttpClient(null); try { diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java index c98749bb46..d1a139f324 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java @@ -69,9 +69,9 @@ public void run() { response.getOutputStream().print(MSG); response.getOutputStream().flush(); } catch (InterruptedException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } catch (IOException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } } }).start(); @@ -83,9 +83,9 @@ public void run() { response.getOutputStream().flush(); continuation.complete(); } catch (InterruptedException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } catch (IOException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } } }).start(); @@ -178,7 +178,7 @@ public void onThrowable(Throwable t) { } catch (InterruptedException e) { fail("Interrupted.", e); } catch (ExecutionException e) { - log.info(String.format("\n@%dms Last body part received\n@%dms Connection killed\n %dms difference.", times[0], times[1], (times[1] - times[0]))); + logger.info(String.format("\n@%dms Last body part received\n@%dms Connection killed\n %dms difference.", times[0], times[1], (times[1] - times[0]))); fail("Timeouted on idle.", e); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java index e741a6240b..e6a338cfc0 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java @@ -13,6 +13,16 @@ package org.asynchttpclient.async; +import static org.testng.Assert.*; + +import java.io.IOException; +import java.util.concurrent.Future; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -23,16 +33,8 @@ import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.ResponseFilter; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.Future; -import java.util.concurrent.atomic.AtomicInteger; - public abstract class PostRedirectGetTest extends AbstractBasicTest { // ------------------------------------------------------ Test Configuration @@ -95,12 +97,12 @@ public Integer onCompleted(Response response) throws Exception { /* @Override */ public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } }); int statusCode = responseFuture.get(); - Assert.assertEquals(statusCode, 200); + assertEquals(statusCode, 200); } finally { p.close(); } @@ -130,12 +132,12 @@ public Integer onCompleted(Response response) throws Exception { /* @Override */ public void onThrowable(Throwable t) { t.printStackTrace(); - Assert.fail("Unexpected exception: " + t.getMessage(), t); + fail("Unexpected exception: " + t.getMessage(), t); } }); int statusCode = responseFuture.get(); - Assert.assertEquals(statusCode, 200); + assertEquals(statusCode, 200); } finally { p.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index 81b37ad077..e9cba6194c 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -12,6 +12,14 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeoutException; + import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -19,29 +27,17 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.SimpleAsyncHttpClient; -import org.eclipse.jetty.server.Connector; +import org.asynchttpclient.async.util.EchoHandler; +import org.eclipse.jetty.proxy.ConnectHandler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.handler.ProxyHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.server.ssl.SslSocketConnector; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeoutException; - -import static org.testng.Assert.assertEquals; - /** * Proxy usage tests. */ -@SuppressWarnings("deprecation") public abstract class ProxyTunnellingTest extends AbstractBasicTest { private Server server2; @@ -49,46 +45,25 @@ public abstract class ProxyTunnellingTest extends AbstractBasicTest { public abstract String getProviderClass(); public AbstractHandler configureHandler() throws Exception { - ProxyHandler proxy = new ProxyHandler(); - return proxy; + return new ConnectHandler(); } @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - server2 = new Server(); - port1 = findFreePort(); - port2 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - - server.addConnector(listener); - - SslSocketConnector connector = new SslSocketConnector(); - connector.setHost("127.0.0.1"); - connector.setPort(port2); - - ClassLoader cl = getClass().getClassLoader(); - URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); - String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); - connector.setKeystore(keyStoreFile); - connector.setKeyPassword("changeit"); - connector.setKeystoreType("JKS"); - - server2.addConnector(connector); - + server = newJettyHttpServer(port1); server.setHandler(configureHandler()); server.start(); + port2 = findFreePort(); + + server2 = newJettyHttpsServer(port2); server2.setHandler(new EchoHandler()); server2.start(); - log.info("Local HTTP server started successfully"); + + logger.info("Local HTTP server started successfully"); } - + @AfterClass(alwaysRun = true) public void tearDownGlobal() throws Exception { server.stop(); @@ -110,7 +85,7 @@ public void testRequestProxy() throws IOException, InterruptedException, Executi public void onThrowable(Throwable t) { t.printStackTrace(); - log.debug(t.getMessage(), t); + logger.debug(t.getMessage(), t); } @Override @@ -128,21 +103,17 @@ public Response onCompleted(Response response) throws Exception { @Test(groups = { "online", "default_provider" }) public void testConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException { - AsyncHttpClientConfig.Builder b = new AsyncHttpClientConfig.Builder(); - b.setFollowRedirects(true); - - ProxyServer ps = new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1); - b.setProxyServer(ps); - - AsyncHttpClientConfig config = b.build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setFollowRedirects(true)// + .setProxyServer(new ProxyServer(ProxyServer.Protocol.HTTPS, "127.0.0.1", port1))// + .build(); AsyncHttpClient asyncHttpClient = getAsyncHttpClient(config); try { - RequestBuilder rb = new RequestBuilder("GET").setUrl(getTargetUrl2()); - Future responseFuture = asyncHttpClient.executeRequest(rb.build(), new AsyncCompletionHandlerBase() { + Future responseFuture = asyncHttpClient.executeRequest(new RequestBuilder("GET").setUrl(getTargetUrl2()).build(), new AsyncCompletionHandlerBase() { public void onThrowable(Throwable t) { t.printStackTrace(); - log.debug(t.getMessage(), t); + logger.debug(t.getMessage(), t); } @Override @@ -161,7 +132,11 @@ public Response onCompleted(Response response) throws Exception { @Test(groups = { "online", "default_provider" }) public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, ExecutionException, TimeoutException { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setProxyProtocol(ProxyServer.Protocol.HTTPS).setProxyHost("127.0.0.1").setProxyPort(port1).setFollowRedirects(true).setUrl(getTargetUrl2()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder()// + .setProviderClass(getProviderClass())// + .setProxyProtocol(ProxyServer.Protocol.HTTPS).setProxyHost("127.0.0.1").setProxyPort(port1).setFollowRedirects(true).setUrl(getTargetUrl2())// + .setHeader("Content-Type", "text/html")// + .build(); try { Response r = client.get().get(); diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index 88af885b2d..e4f1a68c75 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -12,6 +12,9 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.createTempFile; +import static org.testng.Assert.assertEquals; + import java.io.File; import java.io.IOException; @@ -24,7 +27,6 @@ import org.asynchttpclient.Response; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; import org.testng.annotations.Test; /** @@ -35,15 +37,14 @@ public abstract class PutLargeFileTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutLargeFile() throws Exception { - long repeats = (1024 * 1024 * 100 / PATTERN_BYTES.length) + 1; - File file = createTempFile(PATTERN_BYTES, (int) repeats); + File file = createTempFile(1024 * 1024); - int timeout = (int) (repeats / 1000); + int timeout = (int) file.length() / 1000; AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); try { Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); - Assert.assertEquals(200, response.getStatusCode()); + assertEquals(response.getStatusCode(), 200); } finally { client.close(); } @@ -52,13 +53,12 @@ public void testPutLargeFile() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testPutSmallFile() throws Exception { - long repeats = (1024 / PATTERN_BYTES.length) + 1; - File file = createTempFile(PATTERN_BYTES, (int) repeats); + File file = createTempFile(1024); AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); - Assert.assertEquals(200, response.getStatusCode()); + assertEquals(response.getStatusCode(), 200); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java index a72ec9ebcc..1bc842399a 100644 --- a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java +++ b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java @@ -101,7 +101,7 @@ public void testUrlRequestParametersEncoding() throws IOException, ExecutionExce } @Test(groups = { "standalone", "default_provider" }) - public void urlWithColonTest_Netty() throws Throwable { + public void urlWithColonTest_Netty() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { String query = "test:colon:"; @@ -114,7 +114,7 @@ public void urlWithColonTest_Netty() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void urlWithColonTest_JDK() throws Throwable { + public void urlWithColonTest_JDK() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { String query = "test:colon:"; diff --git a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java index 9b07accd80..7cecf24d13 100644 --- a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java @@ -15,35 +15,34 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.HttpResponseBodyPart; import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - /** * Reverse C10K Problem test. * @@ -62,7 +61,7 @@ public void setUpGlobal() throws Exception { for (int i = 0; i < SRV_COUNT; i++) { ports[i] = createServer(); } - log.info("Local HTTP servers started successfully"); + logger.info("Local HTTP servers started successfully"); } @AfterClass(alwaysRun = true) @@ -73,12 +72,8 @@ public void tearDownGlobal() throws Exception { } private int createServer() throws Exception { - Server srv = new Server(); - Connector listener = new SelectChannelConnector(); - listener.setHost("127.0.0.1"); int port = findFreePort(); - listener.setPort(port); - srv.addConnector(listener); + Server srv = newJettyHttpServer(port); srv.setHandler(configureHandler()); srv.start(); servers.add(srv); @@ -129,7 +124,7 @@ public MyAsyncHandler(int i) { } public void onThrowable(Throwable t) { - log.warn("onThrowable called.", t); + logger.warn("onThrowable called.", t); } public STATE onBodyPartReceived(HttpResponseBodyPart event) throws Exception { diff --git a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java index 4a2b749450..a27873d108 100644 --- a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java @@ -15,8 +15,8 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; -import static org.testng.FileAssert.fail; import java.io.IOException; import java.io.OutputStream; @@ -29,14 +29,10 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.testng.annotations.BeforeClass; @@ -55,23 +51,13 @@ public abstract class RedirectConnectionUsageTest extends AbstractBasicTest { @BeforeClass public void setUp() throws Exception { - server = new Server(); - port1 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - listener.setHost("localhost"); - listener.setPort(port1); - - server.addConnector(listener); + server = newJettyHttpServer(port1); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - - context.setContextPath("/"); - server.setHandler(context); - context.addServlet(new ServletHolder(new MockRedirectHttpServlet()), "/redirect/*"); context.addServlet(new ServletHolder(new MockFullResponseHttpServlet()), "/*"); + server.setHandler(context); server.start(); @@ -83,47 +69,32 @@ public void setUp() throws Exception { * Tests that after a redirect the final url in the response reflect the redirect */ @Test - public void testGetRedirectFinalUrl() { - - AsyncHttpClientConfig.Builder bc = new AsyncHttpClientConfig.Builder(); - - bc.setAllowPoolingConnection(true); - bc.setMaximumConnectionsPerHost(1); - bc.setMaximumConnectionsTotal(1); - bc.setConnectionTimeoutInMs(1000); - bc.setRequestTimeoutInMs(1000); - bc.setFollowRedirects(true); - - AsyncHttpClient c = getAsyncHttpClient(bc.build()); + public void testGetRedirectFinalUrl() throws Exception { + + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsPerHost(1)// + .setMaximumConnectionsTotal(1)// + .setConnectionTimeoutInMs(1000)// + .setRequestTimeoutInMs(1000)// + .setFollowRedirects(true)// + .build(); + + AsyncHttpClient c = getAsyncHttpClient(config); try { + Request r = new RequestBuilder("GET").setUrl(servletEndpointRedirectUrl).build(); - RequestBuilder builder = new RequestBuilder("GET"); - builder.setUrl(servletEndpointRedirectUrl); - - Request r = builder.build(); - - try { - ListenableFuture response = c.executeRequest(r); - Response res = null; - res = response.get(); - assertNotNull(res.getResponseBody()); - assertEquals(BASE_URL + "/overthere", BASE_URL + "/overthere", res.getUri().toString()); - - } catch (Exception e) { - System.err.print("============"); - e.printStackTrace(); - System.err.print("============"); - System.err.flush(); - fail("Should not get here, The request threw an exception"); - } + ListenableFuture response = c.executeRequest(r); + Response res = null; + res = response.get(); + assertNotNull(res.getResponseBody()); + assertEquals(res.getUri().toString(), BASE_URL + "/overthere"); } finally { c.close(); } } - protected abstract AsyncHttpProviderConfig getProviderConfig(); - @SuppressWarnings("serial") class MockRedirectHttpServlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { @@ -140,7 +111,7 @@ class MockFullResponseHttpServlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String xmlToReturn = String.format(xml, new Object[] { new Date().toString() }); - res.setStatus(200, "Complete, XML Being Returned"); + res.setStatus(200); res.addHeader("Content-Type", contentType); res.addHeader("X-Method", req.getMethod()); res.addHeader("MultiValue", "1"); diff --git a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java index e2b65dbf29..86c21eaac5 100644 --- a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java @@ -15,20 +15,9 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.ConnectException; import java.net.URI; @@ -36,9 +25,17 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicBoolean; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Response; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; public abstract class Relative302Test extends AbstractBasicTest { private final AtomicBoolean isSet = new AtomicBoolean(false); @@ -48,7 +45,7 @@ private class Relative302Handler extends AbstractHandler { public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { String param; - httpResponse.setContentType("text/html; charset=utf-8"); + httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); Enumeration e = httpRequest.getHeaderNames(); while (e.hasMoreElements()) { param = e.nextElement().toString(); @@ -69,24 +66,24 @@ public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServ @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); port2 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - - listener.setHost("127.0.0.1"); - listener.setPort(port1); - server.addConnector(listener); - + server = newJettyHttpServer(port1); server.setHandler(new Relative302Handler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @Test(groups = { "online", "default_provider" }) - public void redirected302Test() throws Throwable { + public void testAllSequentiallyBecauseNotThreadSafe() throws Exception { + redirected302Test(); + redirected302InvalidTest(); + absolutePathRedirectTest(); + relativePathRedirectTest(); + } + + // @Test(groups = { "online", "default_provider" }) + public void redirected302Test() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -105,25 +102,8 @@ public void redirected302Test() throws Throwable { } } - private String getBaseUrl(URI uri) { - String url = uri.toString(); - int port = uri.getPort(); - if (port == -1) { - port = getPort(uri); - url = url.substring(0, url.length() - 1) + ":" + port; - } - return url.substring(0, url.lastIndexOf(":") + String.valueOf(port).length() + 1); - } - - private static int getPort(URI uri) { - int port = uri.getPort(); - if (port == -1) - port = uri.getScheme().equals("http") ? 80 : 443; - return port; - } - - @Test(groups = { "standalone", "default_provider" }) - public void redirected302InvalidTest() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void redirected302InvalidTest() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -141,8 +121,8 @@ public void redirected302InvalidTest() throws Throwable { } } - @Test(groups = { "standalone", "default_provider" }) - public void absolutePathRedirectTest() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void absolutePathRedirectTest() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); @@ -156,14 +136,14 @@ public void absolutePathRedirectTest() throws Throwable { assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); - log.debug("{} was redirected to {}", redirectTarget, destinationUrl); + logger.debug("{} was redirected to {}", redirectTarget, destinationUrl); } finally { c.close(); } } - @Test(groups = { "standalone", "default_provider" }) - public void relativePathRedirectTest() throws Throwable { + // @Test(groups = { "standalone", "default_provider" }) + public void relativePathRedirectTest() throws Exception { isSet.getAndSet(false); AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); @@ -177,9 +157,26 @@ public void relativePathRedirectTest() throws Throwable { assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); - log.debug("{} was redirected to {}", redirectTarget, destinationUrl); + logger.debug("{} was redirected to {}", redirectTarget, destinationUrl); } finally { c.close(); } } + + private String getBaseUrl(URI uri) { + String url = uri.toString(); + int port = uri.getPort(); + if (port == -1) { + port = getPort(uri); + url = url.substring(0, url.length() - 1) + ":" + port; + } + return url.substring(0, url.lastIndexOf(":") + String.valueOf(port).length() + 1); + } + + private static int getPort(URI uri) { + int port = uri.getPort(); + if (port == -1) + port = uri.getScheme().equals("http") ? 80 : 443; + return port; + } } diff --git a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java index f94ff385a3..a5025ffb17 100644 --- a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java @@ -15,9 +15,7 @@ */ package org.asynchttpclient.async; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.Assert.*; import java.io.InputStream; import java.net.URLEncoder; @@ -25,13 +23,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.asynchttpclient.Cookie; -import org.testng.Assert; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Cookie; import org.asynchttpclient.HttpResponseBodyPart; import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; @@ -39,6 +34,7 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.testng.annotations.Test; /** * Unit tests for remote site. @@ -53,7 +49,7 @@ public abstract class RemoteSiteTest extends AbstractBasicTest { public static final String REQUEST_PARAM = "github github \n" + "github"; @Test(groups = { "online", "default_provider" }) - public void testGoogleCom() throws Throwable { + public void testGoogleCom() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://www.google.com/").execute().get(10, TimeUnit.SECONDS); @@ -64,7 +60,7 @@ public void testGoogleCom() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void testMailGoogleCom() throws Throwable { + public void testMailGoogleCom() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://mail.google.com/").execute().get(10, TimeUnit.SECONDS); @@ -76,7 +72,7 @@ public void testMailGoogleCom() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void testMicrosoftCom() throws Throwable { + public void testMicrosoftCom() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://microsoft.com/").execute().get(10, TimeUnit.SECONDS); @@ -88,7 +84,7 @@ public void testMicrosoftCom() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void testWwwMicrosoftCom() throws Throwable { + public void testWwwMicrosoftCom() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://www.microsoft.com/").execute().get(10, TimeUnit.SECONDS); @@ -100,7 +96,7 @@ public void testWwwMicrosoftCom() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void testUpdateMicrosoftCom() throws Throwable { + public void testUpdateMicrosoftCom() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://update.microsoft.com/").execute().get(10, TimeUnit.SECONDS); @@ -112,7 +108,7 @@ public void testUpdateMicrosoftCom() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void testGoogleComWithTimeout() throws Throwable { + public void testGoogleComWithTimeout() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).build()); try { Response response = c.prepareGet("http://google.com/").execute().get(10, TimeUnit.SECONDS); @@ -124,7 +120,7 @@ public void testGoogleComWithTimeout() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void asyncStatusHEADContentLenghtTest() throws Throwable { + public void asyncStatusHEADContentLenghtTest() throws Exception { AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); try { final CountDownLatch l = new CountDownLatch(1); @@ -133,14 +129,17 @@ public void asyncStatusHEADContentLenghtTest() throws Throwable { p.executeRequest(request, new AsyncCompletionHandlerAdapter() { @Override public Response onCompleted(Response response) throws Exception { - Assert.assertEquals(response.getStatusCode(), 200); - l.countDown(); - return response; + try { + assertEquals(response.getStatusCode(), 200); + return response; + } finally { + l.countDown(); + } } }).get(); if (!l.await(5, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { p.close(); @@ -148,8 +147,9 @@ public Response onCompleted(Response response) throws Exception { } @Test(groups = { "online", "default_provider" }, enabled = false) - public void invalidStreamTest2() throws Throwable { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).setFollowRedirects(true).setAllowPoolingConnection(false).setMaximumNumberOfRedirects(6).build(); + public void invalidStreamTest2() throws Exception { + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(10000).setFollowRedirects(true).setAllowPoolingConnection(false) + .setMaximumNumberOfRedirects(6).build(); AsyncHttpClient c = getAsyncHttpClient(config); try { @@ -167,31 +167,32 @@ public void invalidStreamTest2() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void asyncFullBodyProperlyRead() throws Throwable { + public void asyncFullBodyProperlyRead() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(); InputStream stream = r.getResponseBodyAsStream(); + // FIXME available is an ESTIMATE!!! int available = stream.available(); int[] lengthWrapper = new int[1]; - /* byte[] bytes = */AsyncHttpProviderUtils.readFully(stream, lengthWrapper); + AsyncHttpProviderUtils.readFully(stream, lengthWrapper); int byteToRead = lengthWrapper[0]; - Assert.assertEquals(available, byteToRead); + assertEquals(available, byteToRead); } finally { client.close(); } } @Test(groups = { "online", "default_provider" }) - public void testUrlRequestParametersEncoding() throws Throwable { + public void testUrlRequestParametersEncoding() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, "UTF-8"); - log.info(String.format("Executing request [%s] ...", requestUrl2)); + logger.info(String.format("Executing request [%s] ...", requestUrl2)); Response response = client.prepareGet(requestUrl2).execute().get(); - Assert.assertEquals(response.getStatusCode(), 301); + assertEquals(response.getStatusCode(), 301); } finally { client.close(); } @@ -200,21 +201,21 @@ public void testUrlRequestParametersEncoding() throws Throwable { /** * See https://issues.sonatype.org/browse/AHC-61 * - * @throws Throwable + * @throws Exception */ @Test(groups = { "online", "default_provider" }) - public void testAHC60() throws Throwable { + public void testAHC60() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Response response = client.prepareGet("http://www.meetup.com/stackoverflow/Mountain-View-CA/").execute().get(); - Assert.assertEquals(response.getStatusCode(), 200); + assertEquals(response.getStatusCode(), 200); } finally { client.close(); } } @Test(groups = { "online", "default_provider" }) - public void stripQueryStringTest() throws Throwable { + public void stripQueryStringTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -229,7 +230,7 @@ public void stripQueryStringTest() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void stripQueryStringNegativeTest() throws Throwable { + public void stripQueryStringNegativeTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setRemoveQueryParamsOnRedirect(false).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); @@ -244,7 +245,7 @@ public void stripQueryStringNegativeTest() throws Throwable { } @Test(groups = { "online", "default_provider" }) - public void evilCoookieTest() throws Throwable { + public void evilCoookieTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { RequestBuilder builder2 = new RequestBuilder("GET"); @@ -263,7 +264,7 @@ public void evilCoookieTest() throws Throwable { } @Test(groups = { "online", "default_provider" }, enabled = false) - public void testAHC62Com() throws Throwable { + public void testAHC62Com() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); try { Response response = c.prepareGet("http://api.crunchbase.com/v/1/financial-organization/kinsey-hills-group.js").execute(new AsyncHandler() { diff --git a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java index d9dc0970d2..6c27502c6e 100644 --- a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java @@ -68,7 +68,7 @@ public AbstractHandler configureHandler() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void testMaxRetry() throws Throwable { + public void testMaxRetry() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build()); try { ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build()).get(); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java index 3baf664f2f..76dac21427 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java @@ -39,7 +39,7 @@ public class SimpleAsyncClientErrorBehaviourTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }) - public void testAccumulateErrorBody() throws Throwable { + public void testAccumulateErrorBody() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.ACCUMULATE).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); @@ -56,7 +56,7 @@ public void testAccumulateErrorBody() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void testOmitErrorBody() throws Throwable { + public void testOmitErrorBody() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.OMIT).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 73bc1ff0c9..ef0dfacf51 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -12,6 +12,14 @@ */ package org.asynchttpclient.async; +import static org.testng.Assert.*; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Future; + import org.asynchttpclient.ByteArrayPart; import org.asynchttpclient.Response; import org.asynchttpclient.SimpleAsyncHttpClient; @@ -23,18 +31,6 @@ import org.asynchttpclient.simple.SimpleAHCTransferListener; import org.testng.annotations.Test; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.util.concurrent.Future; - -import static junit.framework.Assert.assertTrue; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertNotSame; - public abstract class SimpleAsyncHttpClientTest extends AbstractBasicTest { private final static String MY_MESSAGE = "my message"; @@ -42,7 +38,7 @@ public abstract class SimpleAsyncHttpClientTest extends AbstractBasicTest { public abstract String getProviderClass(); @Test(groups = { "standalone", "default_provider" }) - public void inpuStreamBodyConsumerTest() throws Throwable { + public void inpuStreamBodyConsumerTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { @@ -58,7 +54,7 @@ public void inpuStreamBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void stringBuilderBodyConsumerTest() throws Throwable { + public void stringBuilderBodyConsumerTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { @@ -75,7 +71,7 @@ public void stringBuilderBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void byteArrayOutputStreamBodyConsumerTest() throws Throwable { + public void byteArrayOutputStreamBodyConsumerTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { @@ -92,7 +88,7 @@ public void byteArrayOutputStreamBodyConsumerTest() throws Throwable { } @Test(groups = { "standalone", "default_provider" }) - public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable { + public void requestByteArrayOutputStreamBodyConsumerTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); try { @@ -112,7 +108,7 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Throwable { * See https://issues.sonatype.org/browse/AHC-5 */ @Test(groups = { "standalone", "default_provider" }, enabled = true) - public void testPutZeroBytesFileTest() throws Throwable { + public void testPutZeroBytesFileTest() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain") .build(); try { diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index cb67385dff..38e0e402b9 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -12,6 +12,7 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.createTempFile; import static org.testng.Assert.*; import java.io.File; @@ -34,7 +35,6 @@ import org.asynchttpclient.listener.TransferCompletionHandler; import org.asynchttpclient.listener.TransferListener; import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.Assert; import org.testng.annotations.Test; public abstract class TransferListenerTest extends AbstractBasicTest { @@ -77,7 +77,7 @@ public AbstractHandler configureHandler() throws Exception { } @Test(groups = { "standalone", "default_provider" }) - public void basicGetTest() throws Throwable { + public void basicGetTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final AtomicReference throwable = new AtomicReference(); @@ -131,7 +131,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void basicPutFileTest() throws Throwable { + public void basicPutFileTest() throws Exception { final AtomicReference throwable = new AtomicReference(); final AtomicReference hSent = new AtomicReference(); final AtomicReference hRead = new AtomicReference(); @@ -140,12 +140,9 @@ public void basicPutFileTest() throws Throwable { final AtomicBoolean completed = new AtomicBoolean(false); - long repeats = (1024 * 100 * 10 / PATTERN_BYTES.length) + 1; - File file = createTempFile(PATTERN_BYTES, (int) repeats); - long expectedFileSize = PATTERN_BYTES.length * repeats; - Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); + File file = createTempFile(1024 * 100 * 10); - int timeout = (int) (repeats / 1000); + int timeout = (int) (file.length() / 1000); AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); try { @@ -184,8 +181,8 @@ public void onThrowable(Throwable t) { assertEquals(response.getStatusCode(), 200); assertNotNull(hRead.get()); assertNotNull(hSent.get()); - assertEquals(bbReceivedLenght.get(), expectedFileSize, "Number of received bytes incorrect"); - assertEquals(bbSentLenght.get(), expectedFileSize, "Number of sent bytes incorrect"); + assertEquals(bbReceivedLenght.get(), file.length(), "Number of received bytes incorrect"); + assertEquals(bbSentLenght.get(), file.length(), "Number of sent bytes incorrect"); } catch (IOException ex) { fail("Should have timed out"); } @@ -195,7 +192,7 @@ public void onThrowable(Throwable t) { } @Test(groups = { "standalone", "default_provider" }) - public void basicPutFileBodyGeneratorTest() throws Throwable { + public void basicPutFileBodyGeneratorTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { final AtomicReference throwable = new AtomicReference(); @@ -206,10 +203,7 @@ public void basicPutFileBodyGeneratorTest() throws Throwable { final AtomicBoolean completed = new AtomicBoolean(false); - long repeats = (1024 * 100 * 10 / PATTERN_BYTES.length) + 1; - File file = createTempFile(PATTERN_BYTES, (int) repeats); - long expectedFileSize = PATTERN_BYTES.length * repeats; - Assert.assertEquals(expectedFileSize, file.length(), "Invalid file length"); + File file = createTempFile(1024 * 100 * 10); TransferCompletionHandler tl = new TransferCompletionHandler(); tl.addTransferListener(new TransferListener() { @@ -246,8 +240,8 @@ public void onThrowable(Throwable t) { assertEquals(response.getStatusCode(), 200); assertNotNull(hRead.get()); assertNotNull(hSent.get()); - assertEquals(bbReceivedLenght.get(), expectedFileSize, "Number of received bytes incorrect"); - assertEquals(bbSentLenght.get(), expectedFileSize, "Number of sent bytes incorrect"); + assertEquals(bbReceivedLenght.get(), file.length(), "Number of received bytes incorrect"); + assertEquals(bbSentLenght.get(), file.length(), "Number of sent bytes incorrect"); } catch (IOException ex) { fail("Should have timed out"); } diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index dd8a80d21f..8959d7a8bc 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -12,12 +12,13 @@ */ package org.asynchttpclient.async; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.webdav.WebDavCompletionHandlerBase; -import org.asynchttpclient.webdav.WebDavResponse; +import static org.asynchttpclient.async.util.TestUtils.findFreePort; +import static org.testng.Assert.*; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.ExecutionException; + import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; @@ -25,19 +26,17 @@ import org.apache.catalina.connector.Connector; import org.apache.catalina.startup.Embedded; import org.apache.coyote.http11.Http11NioProtocol; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.asynchttpclient.webdav.WebDavCompletionHandlerBase; +import org.asynchttpclient.webdav.WebDavResponse; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import java.io.File; -import java.io.IOException; -import java.util.concurrent.ExecutionException; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - public abstract class WebDavBasicTest extends AbstractBasicTest { protected Embedded embedded; diff --git a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java index 1394542177..490931ce8c 100644 --- a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java @@ -12,6 +12,7 @@ */ package org.asynchttpclient.async; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.*; import java.io.File; @@ -87,7 +88,7 @@ public Response onCompleted(Response response) throws Exception { }).get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); assertTrue(operationCompleted.get()); assertTrue(headerSent.get()); } finally { @@ -103,7 +104,7 @@ public void zeroCopyPutTest() throws IOException, ExecutionException, TimeoutExc Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); - assertEquals(resp.getResponseBody(), "This is a simple test file"); + assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); } finally { client.close(); } diff --git a/api/src/test/java/org/asynchttpclient/async/util/EchoHandler.java b/api/src/test/java/org/asynchttpclient/async/util/EchoHandler.java new file mode 100644 index 0000000000..5d10eabe12 --- /dev/null +++ b/api/src/test/java/org/asynchttpclient/async/util/EchoHandler.java @@ -0,0 +1,103 @@ +package org.asynchttpclient.async.util; + +import java.io.IOException; +import java.util.Enumeration; + +import javax.servlet.ServletException; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; + +public class EchoHandler extends AbstractHandler { + + @Override + public void handle(String pathInContext, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { + + if (httpRequest.getHeader("X-HEAD") != null) { + httpResponse.setContentLength(1); + } + + if (httpRequest.getHeader("X-ISO") != null) { + httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET); + } else { + httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); + } + + if (request.getMethod().equalsIgnoreCase("OPTIONS")) { + httpResponse.addHeader("Allow", "GET,HEAD,POST,OPTIONS,TRACE"); + } + ; + + Enumeration e = httpRequest.getHeaderNames(); + String param; + while (e.hasMoreElements()) { + param = e.nextElement().toString(); + + if (param.startsWith("LockThread")) { + try { + Thread.sleep(40 * 1000); + } catch (InterruptedException ex) { + } + } + + if (param.startsWith("X-redirect")) { + httpResponse.sendRedirect(httpRequest.getHeader("X-redirect")); + return; + } + httpResponse.addHeader("X-" + param, httpRequest.getHeader(param)); + } + + Enumeration i = httpRequest.getParameterNames(); + + StringBuilder requestBody = new StringBuilder(); + while (i.hasMoreElements()) { + param = i.nextElement().toString(); + httpResponse.addHeader("X-" + param, httpRequest.getParameter(param)); + requestBody.append(param); + requestBody.append("_"); + } + + String pathInfo = httpRequest.getPathInfo(); + if (pathInfo != null) + httpResponse.addHeader("X-pathInfo", pathInfo); + + String queryString = httpRequest.getQueryString(); + if (queryString != null) + httpResponse.addHeader("X-queryString", queryString); + + httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort()); + + Cookie[] cs = httpRequest.getCookies(); + if (cs != null) { + for (Cookie c : cs) { + httpResponse.addCookie(c); + } + } + + if (requestBody.length() > 0) { + httpResponse.getOutputStream().write(requestBody.toString().getBytes()); + } + + int size = 16384; + if (httpRequest.getContentLength() > 0) { + size = httpRequest.getContentLength(); + } + byte[] bytes = new byte[size]; + if (bytes.length > 0) { + int read = 0; + while (read > -1) { + read = httpRequest.getInputStream().read(bytes); + if (read > 0) { + httpResponse.getOutputStream().write(bytes, 0, read); + } + } + } + + httpResponse.setStatus(200); + httpResponse.getOutputStream().flush(); + httpResponse.getOutputStream().close(); + } +} \ No newline at end of file diff --git a/api/src/test/java/org/asynchttpclient/async/util/TestUtils.java b/api/src/test/java/org/asynchttpclient/async/util/TestUtils.java new file mode 100644 index 0000000000..e4adbd01fa --- /dev/null +++ b/api/src/test/java/org/asynchttpclient/async/util/TestUtils.java @@ -0,0 +1,253 @@ +package org.asynchttpclient.async.util; + +import static org.testng.Assert.assertEquals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.charset.Charset; +import java.security.KeyStore; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +import org.apache.commons.io.FileUtils; +import org.asynchttpclient.async.HostnameVerifierTest; +import org.eclipse.jetty.security.ConstraintMapping; +import org.eclipse.jetty.security.ConstraintSecurityHandler; +import org.eclipse.jetty.security.HashLoginService; +import org.eclipse.jetty.security.LoginService; +import org.eclipse.jetty.security.authentication.BasicAuthenticator; +import org.eclipse.jetty.security.authentication.DigestAuthenticator; +import org.eclipse.jetty.security.authentication.LoginAuthenticator; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.util.security.Constraint; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +public class TestUtils { + + public static final String USER = "user"; + public static final String ADMIN = "admin"; + public static final String TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET = "text/html; charset=UTF-8"; + public static final String TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET = "text/html; charset=ISO-8859-1"; + private static final File TMP_DIR = new File(System.getProperty("java.io.tmpdir"), "ahc-tests-" + UUID.randomUUID().toString().substring(0, 8)); + public static final byte[] PATTERN_BYTES = "FooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQixFooBarBazQix".getBytes(Charset.forName("UTF-16")); + public static final File LARGE_IMAGE_FILE; + public static byte[] LARGE_IMAGE_BYTES; + public static final File SIMPLE_TEXT_FILE; + public static final String SIMPLE_TEXT_FILE_STRING; + private static final LoginService LOGIN_SERVICE = new HashLoginService("MyRealm", "src/test/resources/realm.properties"); + + static { + try { + TMP_DIR.mkdirs(); + TMP_DIR.deleteOnExit(); + LARGE_IMAGE_FILE = new File(TestUtils.class.getClassLoader().getResource("300k.png").toURI()); + LARGE_IMAGE_BYTES = FileUtils.readFileToByteArray(LARGE_IMAGE_FILE); + SIMPLE_TEXT_FILE = new File(TestUtils.class.getClassLoader().getResource("SimpleTextFile.txt").toURI()); + SIMPLE_TEXT_FILE_STRING = FileUtils.readFileToString(SIMPLE_TEXT_FILE, "UTF-8"); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + + public static synchronized int findFreePort() throws IOException { + ServerSocket socket = null; + + try { + socket = new ServerSocket(0); + + return socket.getLocalPort(); + } finally { + if (socket != null) + socket.close(); + } + } + + public static File createTempFile(int approxSize) throws IOException { + long repeats = approxSize / TestUtils.PATTERN_BYTES.length + 1; + File tmpFile = File.createTempFile("tmpfile-", ".data", TMP_DIR); + tmpFile.deleteOnExit(); + FileOutputStream out = null; + try { + out = new FileOutputStream(tmpFile); + for (int i = 0; i < repeats; i++) { + out.write(PATTERN_BYTES); + } + + long expectedFileSize = PATTERN_BYTES.length * repeats; + assertEquals(tmpFile.length(), expectedFileSize, "Invalid file length"); + + return tmpFile; + } finally { + if (out != null) { + out.close(); + } + } + } + + public static Server newJettyHttpServer(int port) { + Server server = new Server(); + addHttpConnector(server, port); + return server; + } + + public static void addHttpConnector(Server server, int port) { + ServerConnector connector = new ServerConnector(server); + connector.setPort(port); + + server.addConnector(connector); + } + + public static Server newJettyHttpsServer(int port) throws URISyntaxException { + Server server = new Server(); + addHttpsConnector(server, port); + return server; + } + + public static void addHttpsConnector(Server server, int port) throws URISyntaxException { + ClassLoader cl = TestUtils.class.getClassLoader(); + + URL keystoreUrl = cl.getResource("ssltest-keystore.jks"); + String keyStoreFile = new File(keystoreUrl.toURI()).getAbsolutePath(); + SslContextFactory sslContextFactory = new SslContextFactory(keyStoreFile); + sslContextFactory.setKeyStorePassword("changeit"); + + String trustStoreFile = new File(cl.getResource("ssltest-cacerts.jks").toURI()).getAbsolutePath(); + sslContextFactory.setTrustStorePath(trustStoreFile); + sslContextFactory.setTrustStorePassword("changeit"); + + HttpConfiguration httpsConfig = new HttpConfiguration(); + httpsConfig.setSecureScheme("https"); + httpsConfig.setSecurePort(port); + httpsConfig.addCustomizer(new SecureRequestCustomizer()); + + ServerConnector connector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, "http/1.1"), new HttpConnectionFactory(httpsConfig)); + connector.setPort(port); + server.addConnector(connector); + + server.addConnector(connector); + } + + public static void addBasicAuthHandler(Server server, boolean strict, Handler handler) { + addAuthHandler(server, Constraint.__BASIC_AUTH, new BasicAuthenticator(), strict, handler); + } + + public static void addDigestAuthHandler(Server server, boolean strict, Handler handler) { + addAuthHandler(server, Constraint.__DIGEST_AUTH, new DigestAuthenticator(), strict, handler); + } + + private static void addAuthHandler(Server server, String auth, LoginAuthenticator authenticator, boolean strict, Handler handler) { + + server.addBean(LOGIN_SERVICE); + + Constraint constraint = new Constraint(); + constraint.setName(auth); + constraint.setRoles(new String[] { USER, ADMIN }); + constraint.setAuthenticate(true); + + ConstraintMapping mapping = new ConstraintMapping(); + mapping.setConstraint(constraint); + mapping.setPathSpec("/*"); + + Set knownRoles = new HashSet(); + knownRoles.add(USER); + knownRoles.add(ADMIN); + + List cm = new ArrayList(); + cm.add(mapping); + + ConstraintSecurityHandler security = new ConstraintSecurityHandler(); + security.setConstraintMappings(cm, knownRoles); + security.setAuthenticator(authenticator); + security.setLoginService(LOGIN_SERVICE); + security.setStrict(strict); + security.setHandler(handler); + server.setHandler(security); + } + + public static SSLContext createSSLContext(AtomicBoolean trust) { + try { + InputStream keyStoreStream = HostnameVerifierTest.class.getResourceAsStream("ssltest-cacerts.jks"); + char[] keyStorePassword = "changeit".toCharArray(); + KeyStore ks = KeyStore.getInstance("JKS"); + ks.load(keyStoreStream, keyStorePassword); + + // Set up key manager factory to use our key store + char[] certificatePassword = "changeit".toCharArray(); + KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); + kmf.init(ks, certificatePassword); + + // Initialize the SSLContext to work with our key managers. + KeyManager[] keyManagers = kmf.getKeyManagers(); + TrustManager[] trustManagers = new TrustManager[] { dummyTrustManager(trust) }; + SecureRandom secureRandom = new SecureRandom(); + + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(keyManagers, trustManagers, secureRandom); + + return sslContext; + } catch (Exception e) { + throw new Error("Failed to initialize the server-side SSLContext", e); + } + } + + private static final TrustManager dummyTrustManager(final AtomicBoolean trust) { + return new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return new X509Certificate[0]; + } + + public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { + } + + public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { + if (!trust.get()) { + throw new CertificateException("Server certificate not trusted."); + } + } + }; + } + + public static File getClasspathFile(String file) throws FileNotFoundException { + ClassLoader cl = null; + try { + cl = Thread.currentThread().getContextClassLoader(); + } catch (Throwable ex) { + } + if (cl == null) { + cl = TestUtils.class.getClassLoader(); + } + URL resourceUrl = cl.getResource(file); + + try { + return new File(new URI(resourceUrl.toString()).getSchemeSpecificPart()); + } catch (URISyntaxException e) { + throw new FileNotFoundException(file); + } + } +} diff --git a/api/src/test/java/org/asynchttpclient/oauth/TestSignatureCalculator.java b/api/src/test/java/org/asynchttpclient/oauth/TestSignatureCalculator.java index f2256fad08..69b36f1e1d 100644 --- a/api/src/test/java/org/asynchttpclient/oauth/TestSignatureCalculator.java +++ b/api/src/test/java/org/asynchttpclient/oauth/TestSignatureCalculator.java @@ -15,16 +15,12 @@ */ package org.asynchttpclient.oauth; -import org.asynchttpclient.oauth.ConsumerKey; -import org.asynchttpclient.oauth.OAuthSignatureCalculator; -import org.asynchttpclient.oauth.RequestToken; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; import org.asynchttpclient.FluentStringsMap; +import org.testng.annotations.Test; -public class TestSignatureCalculator -{ +public class TestSignatureCalculator { private static final String CONSUMER_KEY = "dpf43f3p2l4k3l03"; private static final String CONSUMER_SECRET = "kd94hf93k423kf44"; @@ -36,12 +32,11 @@ public class TestSignatureCalculator public static final String NONCE = "kllo9940pd9333jh"; final static long TIMESTAMP = 1191242096; - + // based on the reference test case from // http://oauth.pbwiki.com/TestCases - @Test(groups="fast") - public void test() - { + @Test(groups = "fast") + public void test() { ConsumerKey consumer = new ConsumerKey(CONSUMER_KEY, CONSUMER_SECRET); RequestToken user = new RequestToken(TOKEN_KEY, TOKEN_SECRET); OAuthSignatureCalculator calc = new OAuthSignatureCalculator(consumer, user); @@ -51,6 +46,6 @@ public void test() String url = "http://photos.example.net/photos"; String sig = calc.calculateSignature("GET", url, TIMESTAMP, NONCE, null, queryParams); - Assert.assertEquals("tR3+Ty81lMeYAr/Fid0kMTYa/WM=", sig); + assertEquals(sig, "tR3+Ty81lMeYAr/Fid0kMTYa/WM="); } } diff --git a/api/src/test/java/org/asynchttpclient/org/jboss/netty/handler/codec/http/CookieDecoderTest.java b/api/src/test/java/org/asynchttpclient/org/jboss/netty/handler/codec/http/CookieDecoderTest.java index 2c4e3853f6..1086d14a14 100644 --- a/api/src/test/java/org/asynchttpclient/org/jboss/netty/handler/codec/http/CookieDecoderTest.java +++ b/api/src/test/java/org/asynchttpclient/org/jboss/netty/handler/codec/http/CookieDecoderTest.java @@ -12,43 +12,41 @@ */ package org.asynchttpclient.org.jboss.netty.handler.codec.http; -import java.util.Set; +import static org.testng.Assert.assertEquals; -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; -import org.testng.Assert; -import org.testng.annotations.Test; +import java.util.Set; import org.asynchttpclient.Cookie; +import org.testng.annotations.Test; public class CookieDecoderTest { - + @Test(groups = "fast") public void testDecodeUnquoted() { - Set cookies = CookieDecoder.decode( - "foo=value; domain=/; path=/"); - Assert.assertEquals(cookies.size(), 1); + Set cookies = CookieDecoder.decode("foo=value; domain=/; path=/"); + assertEquals(cookies.size(), 1); Cookie first = cookies.iterator().next(); - Assert.assertEquals(first.getValue(), "value"); - Assert.assertEquals(first.getDomain(), "/"); - Assert.assertEquals(first.getPath(), "/"); + assertEquals(first.getValue(), "value"); + assertEquals(first.getDomain(), "/"); + assertEquals(first.getPath(), "/"); } @Test(groups = "fast") public void testDecodeQuoted() { Set cookies = CookieDecoder.decode("ALPHA=\"VALUE1\"; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly"); - Assert.assertEquals(cookies.size(), 1); + assertEquals(cookies.size(), 1); Cookie first = cookies.iterator().next(); - Assert.assertEquals(first.getValue(), "VALUE1"); + assertEquals(first.getValue(), "VALUE1"); } @Test(groups = "fast") public void testDecodeQuotedContainingEscapedQuote() { Set cookies = CookieDecoder.decode("ALPHA=\"VALUE1\\\"\"; Domain=docs.foo.com; Path=/accounts; Expires=Wed, 13-Jan-2021 22:23:01 GMT; Secure; HttpOnly"); - Assert.assertEquals(cookies.size(), 1); + assertEquals(cookies.size(), 1); Cookie first = cookies.iterator().next(); - Assert.assertEquals(first.getValue(), "VALUE1\""); + assertEquals(first.getValue(), "VALUE1\""); } } \ No newline at end of file diff --git a/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java b/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java index d1300614ed..be33e4e90e 100644 --- a/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java +++ b/api/src/test/java/org/asynchttpclient/util/AsyncHttpProviderUtilsTest.java @@ -12,10 +12,10 @@ */ package org.asynchttpclient.util; +import static org.testng.Assert.assertEquals; + import java.net.URI; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.testng.Assert; import org.testng.annotations.Test; public class AsyncHttpProviderUtilsTest { @@ -26,7 +26,7 @@ public void getRedirectUriShouldHandleProperlyEncodedLocation() { String url = "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505"; URI uri = AsyncHttpProviderUtils.getRedirectUri( URI.create("http://www.ebay.de/"), url); - Assert.assertEquals("http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505", uri.toString()); + assertEquals( uri.toString(), "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505"); } @Test(groups = "fast") @@ -34,7 +34,7 @@ public void getRedirectUriShouldHandleRawQueryParamsLocation() { String url = "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505"; URI uri = AsyncHttpProviderUtils.getRedirectUri(URI.create("http://www.ebay.de/"), url); - Assert.assertEquals("http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505", uri.toString()); + assertEquals(uri.toString(), "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505"); } @Test(groups = "fast") @@ -42,6 +42,6 @@ public void getRedirectUriShouldHandleRelativeLocation() { String url = "/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC Lifebook E8310 Core2Duo T8100 2 1GHz 4GB DVD RW&_itemId=150731406505"; URI uri = AsyncHttpProviderUtils.getRedirectUri(URI.create("http://www.ebay.de/"), url); - Assert.assertEquals("http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505", uri.toString()); + assertEquals(uri.toString(), "http://www.ebay.de/sch/sis.html;jsessionid=92D73F80262E3EBED7E115ED01035DDA?_nkw=FSC%20Lifebook%20E8310%20Core2Duo%20T8100%202%201GHz%204GB%20DVD%20RW&_itemId=150731406505"); } } diff --git a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java index 4fc002c578..cd24e9ca08 100644 --- a/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java +++ b/api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java @@ -12,11 +12,11 @@ */ package org.asynchttpclient.util; +import static org.testng.Assert.*; + import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.util.ProxyUtils; -import org.testng.Assert; import org.testng.annotations.Test; public class ProxyUtilsTest { @@ -24,24 +24,24 @@ public class ProxyUtilsTest { public void testBasics() { // should avoid, there is no proxy (is null) Request req = new RequestBuilder("GET").setUrl("http://somewhere.com/foo").build(); - Assert.assertTrue(ProxyUtils.avoidProxy(null, req)); + assertTrue(ProxyUtils.avoidProxy(null, req)); // should avoid, it's in non-proxy hosts req = new RequestBuilder("GET").setUrl("http://somewhere.com/foo").build(); ProxyServer proxyServer = new ProxyServer("foo", 1234); proxyServer.addNonProxyHost("somewhere.com"); - Assert.assertTrue(ProxyUtils.avoidProxy(proxyServer, req)); + assertTrue(ProxyUtils.avoidProxy(proxyServer, req)); // should avoid, it's in non-proxy hosts (with "*") req = new RequestBuilder("GET").setUrl("http://sub.somewhere.com/foo").build(); proxyServer = new ProxyServer("foo", 1234); proxyServer.addNonProxyHost("*.somewhere.com"); - Assert.assertTrue(ProxyUtils.avoidProxy(proxyServer, req)); + assertTrue(ProxyUtils.avoidProxy(proxyServer, req)); // should use it req = new RequestBuilder("GET").setUrl("http://sub.somewhere.com/foo").build(); proxyServer = new ProxyServer("foo", 1234); proxyServer.addNonProxyHost("*.somewhere.org"); - Assert.assertFalse(ProxyUtils.avoidProxy(proxyServer, req)); + assertFalse(ProxyUtils.avoidProxy(proxyServer, req)); } } diff --git a/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java b/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java index dee5562997..3b1dcdfba3 100644 --- a/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java +++ b/api/src/test/java/org/asynchttpclient/util/TestUTF8UrlCodec.java @@ -15,15 +15,15 @@ */ package org.asynchttpclient.util; -import org.asynchttpclient.util.UTF8UrlEncoder; -import org.testng.Assert; +import static org.testng.Assert.assertEquals; + import org.testng.annotations.Test; public class TestUTF8UrlCodec { @Test(groups = "fast") public void testBasics() { - Assert.assertEquals(UTF8UrlEncoder.encode("foobar"), "foobar"); - Assert.assertEquals(UTF8UrlEncoder.encode("a&b"), "a%26b"); - Assert.assertEquals(UTF8UrlEncoder.encode("a+b"), "a%2Bb"); + assertEquals(UTF8UrlEncoder.encode("foobar"), "foobar"); + assertEquals(UTF8UrlEncoder.encode("a&b"), "a%26b"); + assertEquals(UTF8UrlEncoder.encode("a+b"), "a%2Bb"); } } diff --git a/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java b/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java index c8e765c7d1..efabb307ad 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/AbstractBasicTest.java @@ -12,41 +12,23 @@ */ package org.asynchttpclient.websocket; -import java.io.IOException; +import static org.asynchttpclient.async.util.TestUtils.*; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.HandlerWrapper; -import org.eclipse.jetty.server.nio.SelectChannelConnector; -import org.eclipse.jetty.websocket.WebSocketFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.eclipse.jetty.websocket.server.WebSocketHandler; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; public abstract class AbstractBasicTest extends org.asynchttpclient.async.AbstractBasicTest { - protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); - @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); port1 = findFreePort(); - - SelectChannelConnector connector = new SelectChannelConnector(); - connector.setPort(port1); - server.addConnector(connector); - WebSocketHandler _wsHandler = getWebSocketHandler(); - - server.setHandler(_wsHandler); + server = newJettyHttpServer(port1); + server.setHandler(getWebSocketHandler()); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @AfterClass(alwaysRun = true) @@ -54,29 +36,6 @@ public void tearDownGlobal() throws Exception { server.stop(); } - public abstract class WebSocketHandler extends HandlerWrapper implements WebSocketFactory.Acceptor { - private final WebSocketFactory _webSocketFactory = new WebSocketFactory(this, 32 * 1024); - - public WebSocketHandler() { - _webSocketFactory.setMaxIdleTime(10000); - } - - public WebSocketFactory getWebSocketFactory() { - return _webSocketFactory; - } - - @Override - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (_webSocketFactory.acceptWebSocket(request, response) || response.isCommitted()) - return; - super.handle(target, baseRequest, request, response); - } - - public boolean checkOrigin(HttpServletRequest request, String origin) { - return true; - } - } - protected String getTargetUrl() { return String.format("ws://127.0.0.1:%d/", port1); } diff --git a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java index 8676d63628..5a362fd53a 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java @@ -12,69 +12,36 @@ */ package org.asynchttpclient.websocket; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.websocket.WebSocket; -import org.asynchttpclient.websocket.WebSocketByteListener; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; -import static org.testng.Assert.assertEquals; +import org.asynchttpclient.AsyncHttpClient; +import org.eclipse.jetty.websocket.server.WebSocketHandler; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.testng.annotations.Test; public abstract class ByteMessageTest extends AbstractBasicTest { - private final class EchoByteWebSocket implements org.eclipse.jetty.websocket.WebSocket, org.eclipse.jetty.websocket.WebSocket.OnBinaryMessage { - - private Connection connection; - - @Override - public void onOpen(Connection connection) { - this.connection = connection; - connection.setMaxBinaryMessageSize(1000); - } - - @Override - public void onClose(int i, String s) { - connection.close(); - } - - @Override - public void onMessage(byte[] bytes, int i, int i1) { - try { - connection.sendMessage(bytes, i, i1); - } catch (IOException e) { - try { - connection.sendMessage("FAIL"); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - } - @Override public WebSocketHandler getWebSocketHandler() { return new WebSocketHandler() { @Override - public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletRequest httpServletRequest, String s) { - return new EchoByteWebSocket(); + public void configure(WebSocketServletFactory factory) { + factory.register(EchoSocket.class); } }; } @Test - public void echoByte() throws Throwable { + public void echoByte() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(new byte[0]); - WebSocket - websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketByteListener() { + WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketByteListener() { @Override public void onOpen(WebSocket websocket) { @@ -112,7 +79,7 @@ public void onFragment(byte[] fragment, boolean last) { } @Test - public void echoTwoMessagesTest() throws Throwable { + public void echoTwoMessagesTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(2); @@ -163,7 +130,7 @@ public void onFragment(byte[] fragment, boolean last) { } @Test - public void echoOnOpenMessagesTest() throws Throwable { + public void echoOnOpenMessagesTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(2); @@ -217,24 +184,24 @@ public void echoFragments() throws Exception { try { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(null); - + WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketByteListener() { - + @Override public void onOpen(WebSocket websocket) { } - + @Override public void onClose(WebSocket websocket) { latch.countDown(); } - + @Override public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - + @Override public void onMessage(byte[] message) { if (text.get() == null) { @@ -247,7 +214,7 @@ public void onMessage(byte[] message) { } latch.countDown(); } - + @Override public void onFragment(byte[] fragment, boolean last) { } diff --git a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java index 17beea6214..12fa531e6f 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java @@ -12,23 +12,30 @@ */ package org.asynchttpclient.websocket; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.websocket.WebSocket; -import org.asynchttpclient.websocket.WebSocketCloseCodeReasonListener; -import org.asynchttpclient.websocket.WebSocketListener; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.testng.annotations.Test; +import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import org.asynchttpclient.AsyncHttpClient; +import org.eclipse.jetty.websocket.server.WebSocketHandler; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.testng.annotations.Test; -public abstract class CloseCodeReasonMessageTest extends TextMessageTest { +public abstract class CloseCodeReasonMessageTest extends AbstractBasicTest { + @Override + public WebSocketHandler getWebSocketHandler() { + return new WebSocketHandler() { + @Override + public void configure(WebSocketServletFactory factory) { + factory.register(EchoSocket.class); + } + }; + } + @Test(timeOut = 60000) - public void onCloseWithCode() throws Throwable { + public void onCloseWithCode() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); @@ -46,7 +53,7 @@ public void onCloseWithCode() throws Throwable { } @Test(timeOut = 60000) - public void onCloseWithCodeServerClose() throws Throwable { + public void onCloseWithCodeServerClose() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); @@ -55,13 +62,7 @@ public void onCloseWithCodeServerClose() throws Throwable { c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(); latch.await(); - final String[] parts = text.get().split(" "); - assertEquals(parts.length, 5); - assertEquals(parts[0], "1000-Idle"); - assertEquals(parts[1], "for"); - assertTrue(Integer.parseInt(parts[2].substring(0, parts[2].indexOf('m'))) > 10000); - assertEquals(parts[3], ">"); - assertEquals(parts[4], "10000ms"); + assertEquals(text.get(), "1001-Idle Timeout"); } finally { c.close(); } @@ -84,6 +85,7 @@ public void onOpen(WebSocket websocket) { @Override public void onClose(WebSocket websocket) { + latch.countDown(); } public void onClose(WebSocket websocket, int code, String reason) { diff --git a/api/src/test/java/org/asynchttpclient/websocket/EchoSocket.java b/api/src/test/java/org/asynchttpclient/websocket/EchoSocket.java new file mode 100644 index 0000000000..b2fe413812 --- /dev/null +++ b/api/src/test/java/org/asynchttpclient/websocket/EchoSocket.java @@ -0,0 +1,52 @@ +package org.asynchttpclient.websocket; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.websocket.api.Session; +import org.eclipse.jetty.websocket.api.WebSocketAdapter; + +public class EchoSocket extends WebSocketAdapter { + + @Override + public void onWebSocketConnect(Session sess) { + super.onWebSocketConnect(sess); + sess.setIdleTimeout(10000); + sess.setMaximumMessageSize(1000); + } + + @Override + public void onWebSocketClose(int statusCode, String reason) { + try { + getSession().close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + super.onWebSocketClose(statusCode, reason); + } + + @Override + public void onWebSocketBinary(byte[] payload, int offset, int len) { + if (isNotConnected()) { + return; + } + try { + getRemote().sendBytes(ByteBuffer.wrap(payload, offset, len)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void onWebSocketText(String message) { + if (isNotConnected()) { + return; + } + try { + getRemote().sendString(message); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java index 33fa8c9b5d..92e08e10a2 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java @@ -13,6 +13,7 @@ package org.asynchttpclient.websocket; +import static org.asynchttpclient.async.util.TestUtils.*; import static org.testng.Assert.assertEquals; import java.io.IOException; @@ -26,10 +27,10 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.websocket.server.WebSocketHandler; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -41,15 +42,8 @@ public void setUpGlobal() throws Exception { port1 = findFreePort(); port2 = findFreePort(); - server = new Server(); - - SelectChannelConnector connector = new SelectChannelConnector(); - connector.setPort(port1); - server.addConnector(connector); - - SelectChannelConnector connector2 = new SelectChannelConnector(); - connector2.setPort(port2); - server.addConnector(connector2); + server = newJettyHttpServer(port1); + addHttpConnector(server, port2); HandlerList list = new HandlerList(); list.addHandler(new AbstractHandler() { @@ -64,19 +58,20 @@ public void handle(String s, Request request, HttpServletRequest httpServletRequ server.setHandler(list); server.start(); - log.info("Local HTTP server started successfully"); + logger.info("Local HTTP server started successfully"); } @Override public WebSocketHandler getWebSocketHandler() { return new WebSocketHandler() { @Override - public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletRequest httpServletRequest, String s) { - return new TextMessageTest.EchoTextWebSocket(); + public void configure(WebSocketServletFactory factory) { + factory.register(EchoSocket.class); } }; } + @Test(timeOut = 60000) public void testRedirectToWSResource() throws Exception { AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build()); diff --git a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java index 4bce6f8860..a63c0a15eb 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java @@ -12,65 +12,30 @@ */ package org.asynchttpclient.websocket; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.websocket.WebSocket; -import org.asynchttpclient.websocket.WebSocketListener; -import org.asynchttpclient.websocket.WebSocketTextListener; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.testng.annotations.Test; +import static org.testng.Assert.*; -import javax.servlet.http.HttpServletRequest; -import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicReference; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import org.asynchttpclient.AsyncHttpClient; +import org.eclipse.jetty.websocket.server.WebSocketHandler; +import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; +import org.testng.annotations.Test; public abstract class TextMessageTest extends AbstractBasicTest { - public static final class EchoTextWebSocket implements org.eclipse.jetty.websocket.WebSocket, org.eclipse.jetty.websocket.WebSocket.OnTextMessage { - - private Connection connection; - - @Override - public void onOpen(Connection connection) { - this.connection = connection; - connection.setMaxTextMessageSize(1000); - } - - @Override - public void onClose(int i, String s) { - connection.close(); - } - - @Override - public void onMessage(String s) { - try { - connection.sendMessage(s); - } catch (IOException e) { - try { - connection.sendMessage("FAIL"); - } catch (IOException e1) { - e1.printStackTrace(); - } - } - } - } - @Override public WebSocketHandler getWebSocketHandler() { return new WebSocketHandler() { @Override - public org.eclipse.jetty.websocket.WebSocket doWebSocketConnect(HttpServletRequest httpServletRequest, String s) { - return new EchoTextWebSocket(); + public void configure(WebSocketServletFactory factory) { + factory.register(EchoSocket.class); } }; } @Test(timeOut = 60000) - public void onOpen() throws Throwable { + public void onOpen() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); @@ -103,7 +68,7 @@ public void onError(Throwable t) { } @Test(timeOut = 60000) - public void onEmptyListenerTest() throws Throwable { + public void onEmptyListenerTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { WebSocket websocket = null; @@ -119,7 +84,7 @@ public void onEmptyListenerTest() throws Throwable { } @Test(timeOut = 60000) - public void onFailureTest() throws Throwable { + public void onFailureTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { Throwable t = null; @@ -135,13 +100,13 @@ public void onFailureTest() throws Throwable { } @Test(timeOut = 60000) - public void onTimeoutCloseTest() throws Throwable { + public void onTimeoutCloseTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - /* WebSocket websocket = */c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { + c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { @Override public void onOpen(WebSocket websocket) { @@ -168,7 +133,7 @@ public void onError(Throwable t) { } @Test(timeOut = 60000) - public void onClose() throws Throwable { + public void onClose() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); @@ -203,7 +168,7 @@ public void onError(Throwable t) { } @Test(timeOut = 60000) - public void echoText() throws Throwable { + public void echoText() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); @@ -247,7 +212,7 @@ public void onError(Throwable t) { } @Test(timeOut = 60000) - public void echoDoubleListenerText() throws Throwable { + public void echoDoubleListenerText() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(2); @@ -317,7 +282,7 @@ public void onError(Throwable t) { } @Test - public void echoTwoMessagesTest() throws Throwable { + public void echoTwoMessagesTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(2); @@ -359,7 +324,7 @@ public void onError(Throwable t) { } } - public void echoFragments() throws Throwable { + public void echoFragments() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { final CountDownLatch latch = new CountDownLatch(1); diff --git a/extras/jdeferred/src/test/java/org/asynchttpclient/extra/AsyncHttpTest.java b/extras/jdeferred/src/test/java/org/asynchttpclient/extra/AsyncHttpTest.java index b3c2a900b6..3ee7428450 100644 --- a/extras/jdeferred/src/test/java/org/asynchttpclient/extra/AsyncHttpTest.java +++ b/extras/jdeferred/src/test/java/org/asynchttpclient/extra/AsyncHttpTest.java @@ -15,108 +15,90 @@ */ package org.asynchttpclient.extra; +import static org.testng.Assert.*; + import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.asynchttpclient.extra.AsyncHttpDeferredObject; -import org.asynchttpclient.extra.HttpProgress; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.Response; import org.jdeferred.DoneCallback; import org.jdeferred.ProgressCallback; import org.jdeferred.Promise; import org.jdeferred.impl.DefaultDeferredManager; import org.jdeferred.multiple.MultipleResults; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.Response; - -public class AsyncHttpTest extends TestCase { - protected DefaultDeferredManager deferredManager; - - protected void setUp() throws Exception { - super.setUp(); - deferredManager = new DefaultDeferredManager(); - } - - protected void tearDown() throws Exception { - super.tearDown(); - } - - public void testPromiseAdapter() throws IOException { - final CountDownLatch latch = new CountDownLatch(1); - final AtomicInteger successCount = new AtomicInteger(); - final AtomicInteger progressCount = new AtomicInteger(); - - AsyncHttpClient client = new AsyncHttpClient(); - - Promise p1 = AsyncHttpDeferredObject - .promise(client.prepareGet("http://www.ning.com/")); - p1.done(new DoneCallback() { - @Override - public void onDone(Response response) { - try { - Assert.assertEquals(200, response.getStatusCode()); - successCount.incrementAndGet(); - } finally { - latch.countDown(); - } - } - }).progress(new ProgressCallback() { - - @Override - public void onProgress(HttpProgress progress) { - progressCount.incrementAndGet(); - } - }); - - try { - latch.await(); - Assert.assertTrue(progressCount.get() > 0); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - - public void testMultiplePromiseAdapter() throws IOException { - final CountDownLatch latch = new CountDownLatch(1); - final AtomicInteger successCount = new AtomicInteger(); - - AsyncHttpClient client = new AsyncHttpClient(); - - Promise p1 = AsyncHttpDeferredObject - .promise(client.prepareGet("http://www.ning.com/")); - Promise p2 = AsyncHttpDeferredObject - .promise(client.prepareGet("http://www.google.com/")); - AsyncHttpDeferredObject deferredRequest = new AsyncHttpDeferredObject( - client.prepareGet("http://jdeferred.org/")); - - deferredManager.when(p1, p2, deferredRequest).then( - new DoneCallback() { - @Override - public void onDone(MultipleResults result) { - try { - Assert.assertEquals(3, result.size()); - Assert.assertEquals(200, ((Response) result.get(0) - .getResult()).getStatusCode()); - Assert.assertEquals(200, ((Response) result.get(1) - .getResult()).getStatusCode()); - Assert.assertEquals(200, ((Response) result.get(2) - .getResult()).getStatusCode()); - successCount.incrementAndGet(); - } finally { - latch.countDown(); - } - } - }); - - try { - latch.await(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - +public class AsyncHttpTest { + protected DefaultDeferredManager deferredManager = new DefaultDeferredManager(); + + public void testPromiseAdapter() throws IOException { + final CountDownLatch latch = new CountDownLatch(1); + final AtomicInteger successCount = new AtomicInteger(); + final AtomicInteger progressCount = new AtomicInteger(); + + AsyncHttpClient client = new AsyncHttpClient(); + + try { + Promise p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.ning.com/")); + p1.done(new DoneCallback() { + @Override + public void onDone(Response response) { + try { + assertEquals(response.getStatusCode(), 200); + successCount.incrementAndGet(); + } finally { + latch.countDown(); + } + } + }).progress(new ProgressCallback() { + + @Override + public void onProgress(HttpProgress progress) { + progressCount.incrementAndGet(); + } + }); + + latch.await(); + assertTrue(progressCount.get() > 0); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + client.close(); + } + } + + public void testMultiplePromiseAdapter() throws IOException { + final CountDownLatch latch = new CountDownLatch(1); + final AtomicInteger successCount = new AtomicInteger(); + + AsyncHttpClient client = new AsyncHttpClient(); + + try { + Promise p1 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.ning.com/")); + Promise p2 = AsyncHttpDeferredObject.promise(client.prepareGet("http://www.google.com/")); + AsyncHttpDeferredObject deferredRequest = new AsyncHttpDeferredObject(client.prepareGet("http://jdeferred.org/")); + + deferredManager.when(p1, p2, deferredRequest).then(new DoneCallback() { + @Override + public void onDone(MultipleResults result) { + try { + assertEquals(result.size(), 3); + assertEquals(Response.class.cast(result.get(0).getResult()).getStatusCode(), 200); + assertEquals(Response.class.cast(result.get(1).getResult()).getStatusCode(), 200); + assertEquals(Response.class.cast(result.get(2).getResult()).getStatusCode(), 200); + successCount.incrementAndGet(); + } finally { + latch.countDown(); + } + } + }); + latch.await(); + + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } finally { + client.close(); + } + } } diff --git a/pom.xml b/pom.xml index f7601bc353..fe94209066 100644 --- a/pom.xml +++ b/pom.xml @@ -214,7 +214,6 @@ - org.apache.maven.plugins maven-resources-plugin 2.4.3 @@ -222,12 +221,9 @@ - org.apache.maven.plugins maven-release-plugin - 2.1 - org.apache.maven.plugins maven-jar-plugin 2.3.1 @@ -239,7 +235,6 @@ - org.apache.maven.plugins maven-source-plugin 2.1.2 @@ -253,12 +248,10 @@ - org.apache.maven.plugins maven-site-plugin 3.0 - org.apache.maven.plugins maven-javadoc-plugin 2.8.1 @@ -280,34 +273,11 @@ - - - org.apache.maven.plugins maven-javadoc-plugin 2.8.1 @@ -344,7 +314,6 @@ - org.apache.maven.plugins maven-surefire-report-plugin ${surefire.version} @@ -362,7 +331,6 @@ - org.apache.maven.plugins maven-gpg-plugin @@ -382,7 +350,6 @@ - org.apache.maven.plugins maven-surefire-plugin standalone @@ -399,7 +366,6 @@ - org.apache.maven.plugins maven-surefire-plugin standalone, online @@ -466,34 +432,54 @@ testng ${testng.version} test + + + junit + junit + + + org.beanshell + bsh + + + org.yaml + snakeyaml + + org.eclipse.jetty - jetty-server + jetty-servlet ${jetty.version} test org.eclipse.jetty - jetty-servlet + jetty-servlets ${jetty.version} test org.eclipse.jetty - jetty-websocket + jetty-security ${jetty.version} test org.eclipse.jetty - jetty-servlets + jetty-proxy ${jetty.version} test - org.eclipse.jetty - jetty-security + org.eclipse.jetty.websocket + websocket-server + ${jetty.version} + test + + + org.eclipse.jetty.websocket + websocket-servlet ${jetty.version} test @@ -536,8 +522,8 @@ 2.16 1.0.13 1.2.17 - 6.8.5 - 8.1.12.v20130726 + 6.8.7 + 9.0.5.v20130815 6.0.29 2.4 1.3 diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java index e393235e03..a20c34b49f 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java @@ -28,20 +28,13 @@ public class GrizzlyAsyncProviderBasicTest extends AsyncProvidersBasicTest { - @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } @Override - @Test - public void asyncHeaderPOSTTest() throws Throwable { - super.asyncHeaderPOSTTest(); //To change body of overridden methods use File | Settings | File Templates. - } - - @Override - protected AsyncHttpProviderConfig getProviderConfig() { + protected AsyncHttpProviderConfig getProviderConfig() { final GrizzlyAsyncHttpProviderConfig config = new GrizzlyAsyncHttpProviderConfig(); config.addProperty(TRANSPORT_CUSTOMIZER, new TransportCustomizer() { @Override @@ -53,7 +46,7 @@ public void customize(TCPNIOTransport transport, FilterChainBuilder builder) { return config; } - @Test(groups = {"standalone", "default_provider", "async"}, enabled = false) - public void asyncDoPostBasicGZIPTest() throws Throwable { + @Test(groups = { "standalone", "default_provider", "async" }, enabled = false) + public void asyncDoPostBasicGZIPTest() throws Exception { } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java index f7551168fd..c7d077308f 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java @@ -16,6 +16,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; +import org.testng.annotations.Test; public class GrizzlyBasicAuthTest extends BasicAuthTest { @@ -26,6 +27,18 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { @Override public String getProviderClass() { - return GrizzlyAsyncHttpProvider.class.getName(); + return GrizzlyAsyncHttpProvider.class.getName(); + } + + @Test(groups = { "standalone", "default_provider" }, enabled = false) + @Override + public void basicAuthFileTest() throws Exception { + // FIXME + } + + @Test(groups = { "standalone", "default_provider" }, enabled = false) + @Override + public void basicAuthFileNoKeepAliveTest() throws Exception { + // FIXME } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyByteBufferCapacityTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyByteBufferCapacityTest.java index 3d43f261bc..a5eecc63da 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyByteBufferCapacityTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyByteBufferCapacityTest.java @@ -26,6 +26,6 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Test(groups = {"standalone", "default_provider"}, enabled=false) - public void basicByteBufferTest() throws Throwable { + public void basicByteBufferTest() throws Exception { } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java index 5ed9e95bb2..18e781c0c8 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyConnectionPoolTest.java @@ -144,7 +144,7 @@ public void destroy() { @Override @Test - public void multipleMaxConnectionOpenTest() throws Throwable { + public void multipleMaxConnectionOpenTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true).setConnectionTimeoutInMs(5000).setMaximumConnectionsTotal(1).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyPerRequestTimeoutTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyPerRequestTimeoutTest.java index 34f049e4e0..d56f5f3cc9 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyPerRequestTimeoutTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyPerRequestTimeoutTest.java @@ -23,7 +23,7 @@ public class GrizzlyPerRequestTimeoutTest extends PerRequestTimeoutTest { @Override protected void checkTimeoutMessage(String message) { - assertEquals("Timeout exceeded", message); + assertEquals(message, "Timeout exceeded"); } @Override diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyRedirectConnectionUsageTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyRedirectConnectionUsageTest.java index c68810799f..b9fbc218a7 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyRedirectConnectionUsageTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyRedirectConnectionUsageTest.java @@ -15,15 +15,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.RedirectConnectionUsageTest; -import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig; -import org.asynchttpclient.providers.grizzly.TransportCustomizer; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.strategies.SameThreadIOStrategy; - -import static org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProviderConfig.Property.TRANSPORT_CUSTOMIZER; public class GrizzlyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { @@ -31,19 +23,4 @@ public class GrizzlyRedirectConnectionUsageTest extends RedirectConnectionUsageT public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } - - @Override - protected AsyncHttpProviderConfig getProviderConfig() { - final GrizzlyAsyncHttpProviderConfig config = new GrizzlyAsyncHttpProviderConfig(); - config.addProperty(TRANSPORT_CUSTOMIZER, new TransportCustomizer() { - @Override - public void customize(TCPNIOTransport transport, FilterChainBuilder builder) { - if (System.getProperty("blockingio") != null) { - transport.configureBlocking(true); - } - transport.setIOStrategy(SameThreadIOStrategy.getInstance()); - } - }); - return config; - } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyUnexpectingTimeoutTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyUnexpectingTimeoutTest.java index 3698d8e187..e5dcdd07ab 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyUnexpectingTimeoutTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyUnexpectingTimeoutTest.java @@ -13,6 +13,18 @@ package org.asynchttpclient.providers.grizzly; +import static org.testng.Assert.*; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -24,20 +36,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.testng.annotations.Test; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; - public class GrizzlyUnexpectingTimeoutTest extends AbstractBasicTest { private static final String MSG = "Unauthorized without WWW-Authenticate header"; @@ -67,7 +65,7 @@ public void run() { response.getOutputStream().print(MSG); response.getOutputStream().flush(); } catch (IOException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } } }).start(); @@ -113,7 +111,7 @@ public void onThrowable(Throwable t) { fail("Interrupted.", e); } // the result should be either onCompleted or onThrowable. - assertEquals(1, counts.get(), "result should be one"); + assertEquals(counts.get(), 1, "result should be one"); } finally { client.close(); } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyByteMessageTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyByteMessageTest.java index 516e499287..7a809b1d71 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyByteMessageTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyByteMessageTest.java @@ -15,7 +15,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.grizzly.GrizzlyProviderUtil; -import org.asynchttpclient.providers.grizzly.GrizzlyProviderUtil; import org.asynchttpclient.websocket.ByteMessageTest; import org.testng.annotations.Test; diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyCloseCodeReasonMsgTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyCloseCodeReasonMsgTest.java index 9844fb439f..7ff2884f72 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyCloseCodeReasonMsgTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyCloseCodeReasonMsgTest.java @@ -17,7 +17,6 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.grizzly.GrizzlyProviderUtil; import org.asynchttpclient.websocket.CloseCodeReasonMessageTest; -import org.testng.annotations.Test; public class GrizzlyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { @@ -25,10 +24,4 @@ public class GrizzlyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } - - @Override - @Test - public void onCloseWithCode() throws Throwable { - super.onCloseWithCode(); //To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyTextMessageTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyTextMessageTest.java index cf7db9228f..c89bb0b0fb 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyTextMessageTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/websocket/GrizzlyTextMessageTest.java @@ -14,21 +14,12 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; -import org.asynchttpclient.providers.grizzly.GrizzlyProviderUtil; import org.asynchttpclient.providers.grizzly.GrizzlyProviderUtil; import org.asynchttpclient.websocket.ByteMessageTest; -import org.testng.annotations.Test; public class GrizzlyTextMessageTest extends ByteMessageTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return GrizzlyProviderUtil.grizzlyProvider(config); } - - @Test(timeOut = 60000) - @Override - public void echoFragments() throws Exception { - super.echoFragments(); //To change body of overridden methods use File | Settings | File Templates. - } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index f5b6879d10..e6f97d738d 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -769,6 +769,7 @@ else if (uri.getRawQuery() != null) nettyRequest.setContent(ChannelBuffers.wrappedBuffer(bytes)); } else if (request.getStreamData() != null) { int[] lengthWrapper = new int[1]; + // FIXME should be streaming instead! byte[] bytes = AsyncHttpProviderUtils.readFully(request.getStreamData(), lengthWrapper); int length = lengthWrapper[0]; nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length)); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java index 860764a4c6..38c08df1a3 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java @@ -128,6 +128,12 @@ public void close() { public void close(int statusCode, String reason) { onClose(statusCode, reason); listeners.clear(); + try { + channel.write(new CloseWebSocketFrame(statusCode, reason)); + channel.getCloseFuture().awaitUninterruptibly(); + } finally { + channel.close(); + } } protected void onBinaryFragment(byte[] message, boolean last) { diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java index 54262deaad..c55b13996c 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java @@ -26,8 +26,13 @@ public class NettyAsyncHttpProviderTest extends AbstractBasicTest { + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return NettyProviderUtil.nettyProvider(config); + } + @Test - public void bossThreadPoolExecutor() throws Throwable { + public void bossThreadPoolExecutor() throws Exception { NettyAsyncHttpProviderConfig conf = new NettyAsyncHttpProviderConfig(); conf.setBossExecutorService(Executors.newSingleThreadExecutor()); @@ -40,9 +45,4 @@ public void bossThreadPoolExecutor() throws Throwable { c.close(); } } - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java index a8902eb655..87c313345d 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java @@ -13,28 +13,25 @@ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.asynchttpclient.providers.netty.NettyAsyncHttpProvider; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.Response; +import org.asynchttpclient.async.AbstractBasicTest; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.handler.codec.http.HttpMessage; -import org.testng.Assert; import org.testng.annotations.Test; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.async.AbstractBasicTest; - public class NettyAsyncProviderPipelineTest extends AbstractBasicTest { @Override @@ -43,7 +40,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Test(groups = { "standalone", "netty_provider" }) - public void asyncPipelineTest() throws Throwable { + public void asyncPipelineTest() throws Exception { AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build()); try { final CountDownLatch l = new CountDownLatch(1); @@ -61,7 +58,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { p.close(); diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java index d824606453..2e0a4091fc 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java @@ -29,4 +29,9 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return NettyAsyncHttpProvider.class.getName(); } + + @Test(enabled = false) + public void stringBuilderBodyConsumerTest() throws Exception { + // FIXME + } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java index fdbfb52d13..4989481508 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java @@ -15,10 +15,12 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.MultipartUploadTest; +import org.testng.annotations.Test; /** * @author dominict */ +@Test public class NettyMultipartUploadTest extends MultipartUploadTest { @Override diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java index e376f9a414..cd62bb347e 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRedirectConnectionUsageTest.java @@ -14,22 +14,11 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.RedirectConnectionUsageTest; -import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - - @Override - protected AsyncHttpProviderConfig getProviderConfig() { - final NettyAsyncHttpProviderConfig config = new NettyAsyncHttpProviderConfig(); - if (System.getProperty("blockingio") != null) { - config.setUseBlockingIO(true); - } - return config; - } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java index f0685b4561..6ca05960ab 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java @@ -66,9 +66,9 @@ public void run() { response.getOutputStream().flush(); continuation.complete(); } catch (InterruptedException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } catch (IOException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } } }).start(); diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java index 2cf3b30b15..6169dc0fe3 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java @@ -12,7 +12,8 @@ */ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertTrue; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; import java.io.IOException; import java.util.ArrayList; @@ -27,8 +28,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import junit.framework.Assert; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ListenableFuture; @@ -36,9 +35,6 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.testng.annotations.BeforeClass; @@ -54,20 +50,11 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - listener.setHost("localhost"); - listener.setPort(port1); - - server.addConnector(listener); - + server = newJettyHttpServer(port1); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*"); - server.setHandler(context); server.start(); } @@ -77,12 +64,12 @@ protected String getTargetUrl() { } private ListenableFuture testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException { - Request r = new RequestBuilder("GET")/**/ - .setUrl(getTargetUrl())/**/ - .addQueryParameter(action, "1")/**/ - .addQueryParameter("maxRequests", "" + requests)/**/ - .addQueryParameter("id", id)/**/ - .build(); + Request r = new RequestBuilder("GET")// + .setUrl(getTargetUrl())// + .addQueryParameter(action, "1")// + .addQueryParameter("maxRequests", "" + requests)// + .addQueryParameter("id", id)// + .build(); return client.executeRequest(r); } @@ -96,12 +83,12 @@ private ListenableFuture testMethodRequest(AsyncHttpClient client, int @Test public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .build(); AsyncHttpClient client = getAsyncHttpClient(config); try { @@ -113,7 +100,7 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, Exe StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -132,13 +119,13 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, Exe @Test public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .setAsyncConnectMode(true) /**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .setAsyncConnectMode(true) // + .build(); AsyncHttpClient client = getAsyncHttpClient(config); @@ -151,7 +138,7 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -173,13 +160,13 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); nettyConfig.setUseBlockingIO(true); - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .setAsyncHttpClientProviderConfig(nettyConfig)/**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .setAsyncHttpClientProviderConfig(nettyConfig)// + .build(); AsyncHttpClient client = getAsyncHttpClient(config); @@ -192,7 +179,7 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -201,8 +188,7 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut assertTrue(heads.size() > 0); } - System.out.println(b.toString()); - System.out.flush(); + logger.debug(b.toString()); } finally { client.close(); diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java index 2dc624466b..deec16902c 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyCloseCodeReasonMsgTest.java @@ -24,5 +24,4 @@ public class NettyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java index c1286255ad..cb35f53be2 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java @@ -16,7 +16,9 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.netty.NettyProviderUtil; import org.asynchttpclient.websocket.TextMessageTest; +import org.testng.annotations.Test; +@Test public class NettyTextMessageTest extends TextMessageTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java index b3f5cf2d86..b6ee69b065 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java @@ -188,7 +188,7 @@ public void configure(final NettyChannelHandler httpProcessor) { @Override protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline()/**/ + ChannelPipeline pipeline = ch.pipeline()// .addLast(HTTP_HANDLER, newHttpClientCodec()); if (config.getRequestCompressionLevel() > 0) { @@ -198,7 +198,7 @@ protected void initChannel(Channel ch) throws Exception { if (config.isCompressionEnabled()) { pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); } - pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())/**/ + pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())// .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getHttpAdditionalChannelInitializer() != null) { @@ -210,9 +210,9 @@ protected void initChannel(Channel ch) throws Exception { ChannelInitializer webSocketChannelInitializer = new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { - ch.pipeline()/**/ - .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())/**/ - .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())/**/ + ch.pipeline()// + .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getWsAdditionalChannelInitializer() != null) { @@ -266,7 +266,7 @@ protected void initChannel(Channel ch) throws Exception { if (config.isCompressionEnabled()) { pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); } - pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())/**/ + pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())// .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getHttpsAdditionalChannelInitializer() != null) { @@ -288,8 +288,8 @@ protected void initChannel(Channel ch) throws Exception { abort(future, ex); } - pipeline.addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())/**/ - .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())/**/ + pipeline.addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getWssAdditionalChannelInitializer() != null) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java index 95a3b5a834..484a8b694b 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java @@ -789,42 +789,35 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object } else if (e instanceof WebSocketFrame) { - invokeOnSucces(ctx, h); - final WebSocketFrame frame = (WebSocketFrame) e; + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + invokeOnSucces(ctx, h); - if (frame instanceof TextWebSocketFrame) { - pendingOpcode = OPCODE_TEXT; - } else if (frame instanceof BinaryWebSocketFrame) { - pendingOpcode = OPCODE_BINARY; - } - - if (frame.content() != null && frame.content().readableBytes() > 0) { - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); - h.onBodyPartReceived(rp); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - if (webSocket != null) { - if (pendingOpcode == OPCODE_BINARY) { - webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); - } else { - webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); + if (webSocket != null) { + if (frame instanceof CloseWebSocketFrame) { + Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); + webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); + } else { + if (frame instanceof TextWebSocketFrame) { + pendingOpcode = OPCODE_TEXT; + } else if (frame instanceof BinaryWebSocketFrame) { + pendingOpcode = OPCODE_BINARY; } - if (frame instanceof CloseWebSocketFrame) { - try { - Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); - webSocket.onClose(CloseWebSocketFrame.class.cast(frame).statusCode(), CloseWebSocketFrame.class.cast(frame).reasonText()); - } catch (Throwable t) { - // Swallow any exception that may comes from a - // Netty version released before 3.4.0 - LOGGER.trace("", t); + if (frame.content() != null && frame.content().readableBytes() > 0) { + ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); + h.onBodyPartReceived(rp); + + if (pendingOpcode == OPCODE_BINARY) { + webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); + } else { + webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); } } - } else { - LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); } + } else { + LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); } } else if (e instanceof LastHttpContent) { // FIXME what to do with this kind of messages? diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java index c935ee0e8d..f4a4a8dd76 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java @@ -117,7 +117,7 @@ public void close() { onClose(); listeners.clear(); try { - channel.write(new CloseWebSocketFrame()); + channel.writeAndFlush(new CloseWebSocketFrame()); channel.closeFuture().awaitUninterruptibly(); } finally { channel.close(); @@ -128,6 +128,12 @@ public void close() { public void close(int statusCode, String reason) { onClose(statusCode, reason); listeners.clear(); + try { + channel.writeAndFlush(new CloseWebSocketFrame()); + channel.closeFuture().awaitUninterruptibly(); + } finally { + channel.close(); + } } protected void onBinaryFragment(byte[] message, boolean last) { diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java index 7e4fa7d82b..177e28611a 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java @@ -12,31 +12,12 @@ */ package org.asynchttpclient.providers.netty4; -import static org.testng.Assert.assertEquals; - -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; -import org.testng.annotations.Test; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; public class NettyAsyncHttpProviderTest extends AbstractBasicTest { - @Test - public void bossThreadPoolExecutor() throws Throwable { - NettyAsyncHttpProviderConfig conf = new NettyAsyncHttpProviderConfig(); - - AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setAsyncHttpClientProviderConfig(conf).build(); - AsyncHttpClient c = getAsyncHttpClient(cf); - try { - Response r = c.prepareGet(getTargetUrl()).execute().get(); - assertEquals(r.getStatusCode(), 200); - } finally { - c.close(); - } - } - @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java index 64aba79512..c670f5dfa6 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java @@ -13,7 +13,7 @@ package org.asynchttpclient.providers.netty4; -import static org.testng.Assert.assertEquals; +import static org.testng.Assert.*; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; @@ -29,7 +29,6 @@ import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig.AdditionalChannelInitializer; -import org.testng.Assert; import org.testng.annotations.Test; public class NettyAsyncProviderPipelineTest extends AbstractBasicTest { @@ -40,7 +39,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Test(groups = { "standalone", "netty_provider" }) - public void asyncPipelineTest() throws Throwable { + public void asyncPipelineTest() throws Exception { NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); nettyConfig.setHttpAdditionalChannelInitializer(new AdditionalChannelInitializer() { @@ -67,7 +66,7 @@ public Response onCompleted(Response response) throws Exception { } }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - Assert.fail("Timeout out"); + fail("Timeout out"); } } finally { p.close(); diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java index 7bf3ce2737..d49325760f 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java @@ -15,12 +15,13 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.AuthTimeoutTest; +import org.testng.annotations.Test; +@Test public class NettyAuthTimeoutTest extends AuthTimeoutTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java index e0e99cff6a..91d782bd20 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java @@ -14,7 +14,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.RedirectConnectionUsageTest; public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { @@ -22,13 +21,4 @@ public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTes public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - - @Override - protected AsyncHttpProviderConfig getProviderConfig() { - final NettyAsyncHttpProviderConfig config = new NettyAsyncHttpProviderConfig(); - if (System.getProperty("blockingio") != null) { - config.setUseBlockingIO(true); - } - return config; - } } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java index 96b1288664..766a8f1d97 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java @@ -65,9 +65,9 @@ public void run() { response.getOutputStream().flush(); continuation.complete(); } catch (InterruptedException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } catch (IOException e) { - log.error(e.getMessage(), e); + logger.error(e.getMessage(), e); } } }).start(); diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java index b964da6f38..d1b2dc45ed 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java @@ -12,7 +12,8 @@ */ package org.asynchttpclient.providers.netty4; -import static org.testng.Assert.assertTrue; +import static org.asynchttpclient.async.util.TestUtils.*; +import static org.testng.Assert.*; import java.io.IOException; import java.util.ArrayList; @@ -27,8 +28,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import junit.framework.Assert; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ListenableFuture; @@ -36,9 +35,6 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.nio.SelectChannelConnector; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.testng.annotations.BeforeClass; @@ -54,15 +50,8 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { @BeforeClass(alwaysRun = true) public void setUpGlobal() throws Exception { - server = new Server(); - port1 = findFreePort(); - - Connector listener = new SelectChannelConnector(); - listener.setHost("localhost"); - listener.setPort(port1); - - server.addConnector(listener); + server = newJettyHttpServer(port1); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); @@ -77,12 +66,12 @@ protected String getTargetUrl() { } private ListenableFuture testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException { - Request r = new RequestBuilder("GET")/**/ - .setUrl(getTargetUrl())/**/ - .addQueryParameter(action, "1")/**/ - .addQueryParameter("maxRequests", "" + requests)/**/ - .addQueryParameter("id", id)/**/ - .build(); + Request r = new RequestBuilder("GET")// + .setUrl(getTargetUrl())// + .addQueryParameter(action, "1")// + .addQueryParameter("maxRequests", "" + requests)// + .addQueryParameter("id", id)// + .build(); return client.executeRequest(r); } @@ -96,12 +85,12 @@ private ListenableFuture testMethodRequest(AsyncHttpClient client, int @Test public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .build(); AsyncHttpClient client = getAsyncHttpClient(config); try { @@ -113,7 +102,7 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, Exe StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(200, theres.getStatusCode()); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -132,13 +121,13 @@ public void testRetryNonBlocking() throws IOException, InterruptedException, Exe @Test public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException { - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .setAsyncConnectMode(true) /**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .setAsyncConnectMode(true) // + .build(); AsyncHttpClient client = getAsyncHttpClient(config); @@ -151,7 +140,7 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(theres.getStatusCode(), 200); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -173,13 +162,13 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); nettyConfig.setUseBlockingIO(true); - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()/**/ - .setAllowPoolingConnection(true)/**/ - .setMaximumConnectionsTotal(100)/**/ - .setConnectionTimeoutInMs(60000)/**/ - .setRequestTimeoutInMs(30000)/**/ - .setAsyncHttpClientProviderConfig(nettyConfig)/**/ - .build(); + AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// + .setAllowPoolingConnection(true)// + .setMaximumConnectionsTotal(100)// + .setConnectionTimeoutInMs(60000)// + .setRequestTimeoutInMs(30000)// + .setAsyncHttpClientProviderConfig(nettyConfig)// + .build(); AsyncHttpClient client = getAsyncHttpClient(config); @@ -192,7 +181,7 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - Assert.assertEquals(200, theres.getStatusCode()); + assertEquals(theres.getStatusCode(), 200); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java index 169b3189d6..f44962885b 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java @@ -24,5 +24,4 @@ public class NettyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java index 216083bf83..a5e9d8cec7 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java +++ b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java @@ -23,5 +23,4 @@ public class NettyRedirectTest extends RedirectTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/pom.xml b/providers/pom.xml index 1d46aa0a76..9a7178b576 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -46,7 +46,7 @@ grizzly netty - + netty4 From 6cfd1b5653dd7af751fa37e6f9039f7edd856968 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 18 Sep 2013 14:45:31 +0200 Subject: [PATCH 0123/2389] In case catch Throwable didn't catch everything? --- .../providers/netty/NettyResponseFuture.java | 17 ++++++++--------- .../providers/netty4/NettyResponseFuture.java | 10 ++++------ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java index dab12365f2..a5e75f4c32 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java @@ -245,10 +245,9 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, asyncHandler.onThrowable(te); } catch (Throwable t) { logger.debug("asyncHandler.onThrowable", t); - } finally { - cancelReaper(); - throw new ExecutionException(te); } + cancelReaper(); + throw new ExecutionException(te); } } isDone.set(true); @@ -279,10 +278,9 @@ V getContent() throws ExecutionException { asyncHandler.onThrowable(ex); } catch (Throwable t) { logger.debug("asyncHandler.onThrowable", t); - } finally { - cancelReaper(); - throw new RuntimeException(ex); } + cancelReaper(); + throw new RuntimeException(ex); } } content.compareAndSet(null, update); @@ -303,8 +301,8 @@ public final void done() { } catch (ExecutionException t) { return; } catch (RuntimeException t) { - Throwable exception = t.getCause() != null ? t.getCause() : t; - exEx.compareAndSet(null, new ExecutionException(exception)); + Throwable exception = t.getCause() != null ? t.getCause() : t; + exEx.compareAndSet(null, new ExecutionException(exception)); } finally { latch.countDown(); @@ -471,7 +469,8 @@ public void setRequest(Request request) { } /** - * Return true if the {@link Future} cannot be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can recover from that exception. + * Return true if the {@link Future} cannot be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can + * recover from that exception. * * @return true if that {@link Future} cannot be recovered. */ diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java index f428295a3c..65fa6c714d 100755 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java +++ b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java @@ -230,10 +230,9 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, asyncHandler.onThrowable(te); } catch (Throwable t) { logger.debug("asyncHandler.onThrowable", t); - } finally { - cancelReaper(); - throw new ExecutionException(te); } + cancelReaper(); + throw new ExecutionException(te); } } isDone.set(true); @@ -264,10 +263,9 @@ public V getContent() throws ExecutionException { asyncHandler.onThrowable(ex); } catch (Throwable t) { logger.debug("asyncHandler.onThrowable", t); - } finally { - cancelReaper(); - throw new RuntimeException(ex); } + cancelReaper(); + throw new RuntimeException(ex); } } content.compareAndSet(null, update); From 7aa3e31016bc5cec46e5cbf6fb28004151aa53e5 Mon Sep 17 00:00:00 2001 From: oleksiys Date: Thu, 19 Sep 2013 11:50:14 -0700 Subject: [PATCH 0124/2389] + recycle HttpRequestPacket/HttpResponsePacket in the AsyncHttpClientFilter, when we're sure nobody will try to touch them :) --- .../providers/grizzly/EventHandler.java | 55 +++++++------------ .../filters/AsyncHttpClientFilter.java | 30 +++++++++- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 173c34e6c7..6ead4bbe5b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -375,49 +375,34 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) final HttpResponsePacket response = (HttpResponsePacket) httpHeader; final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); - try { - if (context.isEstablishingTunnel() - && HttpStatus.OK_200.statusMatches(response.getStatus())) { - context.setEstablishingTunnel(false); - final Connection c = ctx.getConnection(); - context.tunnelEstablished(c); - context.getProvider().execute(c, - context.getRequest(), - context.getHandler(), - context.getFuture()); - } else { - cleanup(ctx); - final AsyncHandler handler = context.getHandler(); - if (handler != null) { - try { - context.result(handler.onCompleted()); - } catch (Exception e) { - context.abort(e); - } - } else { - context.done(); + if (context.isEstablishingTunnel() + && HttpStatus.OK_200.statusMatches(response.getStatus())) { + context.setEstablishingTunnel(false); + final Connection c = ctx.getConnection(); + context.tunnelEstablished(c); + context.getProvider().execute(c, + context.getRequest(), + context.getHandler(), + context.getFuture()); + } else { + cleanup(ctx); + final AsyncHandler handler = context.getHandler(); + if (handler != null) { + try { + context.result(handler.onCompleted()); + } catch (Exception e) { + context.abort(e); } + } else { + context.done(); } - return false; - } finally { - recycleRequestResponsePackets(ctx.getConnection(), response); } - + return false; } // ----------------------------------------------------- Private Methods - private static void recycleRequestResponsePackets(final Connection c, - final HttpResponsePacket response) { - if (!Utils.isSpdyConnection(c)) { - HttpRequestPacket request = response.getRequest(); - request.setExpectContent(false); - response.recycle(); - request.recycle(); - } - } - private static void processKeepAlive(final Connection c, final HttpHeader header) { final ProcessingState state = header.getProcessingState(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index ce9078d5ea..2a28405f85 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -63,6 +63,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpResponsePacket; import static org.asynchttpclient.providers.grizzly.filters.SwitchingSSLFilter.getHandshakeError; import static org.asynchttpclient.util.AsyncHttpProviderUtils.getAuthority; @@ -101,6 +104,22 @@ public AsyncHttpClientFilter(GrizzlyAsyncHttpProvider grizzlyAsyncHttpProvider, // --------------------------------------------- Methods from BaseFilter + @Override + public NextAction handleRead(final FilterChainContext ctx) + throws IOException { + final HttpContent httpContent = ctx.getMessage(); + if (httpContent.isLast()) { + // Perform the cleanup logic if it's the last chunk of the payload + final HttpResponsePacket response = + (HttpResponsePacket) httpContent.getHttpHeader(); + + recycleRequestResponsePackets(ctx.getConnection(), response); + return ctx.getStopAction(); + } + + return ctx.getInvokeAction(); + } + @Override public NextAction handleWrite(final FilterChainContext ctx) throws IOException { @@ -174,7 +193,16 @@ public Object onCompleted(Response response) throws Exception { // ----------------------------------------------------- Private Methods - + private static void recycleRequestResponsePackets(final Connection c, + final HttpResponsePacket response) { + if (!Utils.isSpdyConnection(c)) { + HttpRequestPacket request = response.getRequest(); + request.setExpectContent(false); + response.recycle(); + request.recycle(); + } + } + private boolean sendAsGrizzlyRequest(final Request request, final FilterChainContext ctx) throws IOException { From c74191eadad9a3fbe155bb41ce809091f93466f1 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 19 Sep 2013 14:17:16 -0700 Subject: [PATCH 0125/2389] Port Grizzly FeedableBodyGenerator changes from 1.7 to master. --- .../grizzly/FeedableBodyGenerator.java | 648 +++++++++++++++--- 1 file changed, 543 insertions(+), 105 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index 778aa8b8c9..b475ddaadc 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -14,24 +14,29 @@ import java.io.IOException; import java.nio.ByteBuffer; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ExecutionException; -import java.util.concurrent.atomic.AtomicInteger; import org.asynchttpclient.Body; import org.asynchttpclient.BodyGenerator; import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.WriteHandler; +import org.glassfish.grizzly.WriteResult; +import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.nio.NIOConnection; +import org.glassfish.grizzly.nio.SelectorRunner; +import org.glassfish.grizzly.ssl.SSLBaseFilter; +import org.glassfish.grizzly.ssl.SSLFilter; import org.glassfish.grizzly.utils.Futures; import static java.lang.Boolean.TRUE; import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.glassfish.grizzly.ssl.SSLUtils.getSSLEngine; import static org.glassfish.grizzly.utils.Exceptions.*; /** @@ -43,20 +48,37 @@ * @since 1.7.0 */ public class FeedableBodyGenerator implements BodyGenerator { - private final Queue queue = new ConcurrentLinkedQueue(); - private final AtomicInteger queueSize = new AtomicInteger(); - + /** + * There is no limit on bytes waiting to be written. This configuration + * value should be used with caution as it could lead to out-of-memory + * conditions. + */ + @SuppressWarnings("UnusedDeclaration") + public static final int UNBOUND = -1; + + /** + * Defer to whatever the connection has been configured for max pending bytes. + */ + public static final int DEFAULT = -2; + private volatile HttpRequestPacket requestPacket; private volatile FilterChainContext context; private volatile HttpContent.Builder contentBuilder; private final EmptyBody EMPTY_BODY = new EmptyBody(); + private Feeder feeder; + private int origMaxPendingBytes; + private int configuredMaxPendingBytes = DEFAULT; + private boolean asyncTransferInitiated; // ---------------------------------------------- Methods from BodyGenerator + /** + * {@inheritDoc} + */ @Override public Body createBody() throws IOException { return EMPTY_BODY; @@ -67,120 +89,150 @@ public Body createBody() throws IOException { /** - * Feeds the specified buffer. This buffer may be queued to be sent later - * or sent immediately. Note that this method may block if data is being - * fed faster than it is being consumed by the peer. - * - * The maximum duration that this method may block is dependent on - * the current value of {@link org.glassfish.grizzly.Transport#getWriteTimeout(java.util.concurrent.TimeUnit)}. - * This value can be customized by using a {@link TransportCustomizer} to - * fine-tune the transport used by the client instance. + * Configured the maximum number of bytes that may be pending to be written + * to the wire. If not explicitly configured, the connection's current + * configuration will be used instead. + *

+ * Once all data has been fed, the connection's max pending bytes configuration + * will be restored to its original value. * - * @param buffer the {@link Buffer} to feed. - * @param last flag indicating if this is the final buffer of the message. - * @throws IOException if an I/O error occurs. - * - * @see TransportCustomizer - * @see GrizzlyAsyncHttpProviderConfig#addProperty(GrizzlyAsyncHttpProviderConfig.Property, Object) - * @see GrizzlyAsyncHttpProviderConfig.Property#TRANSPORT_CUSTOMIZER + * @param maxPendingBytes maximum number of bytes that may be queued to + * be written to the wire. + * @throws IllegalStateException if called after {@link #initializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket)} + * has been called by the {@link GrizzlyAsyncHttpProvider}. + * @throws IllegalArgumentException if maxPendingBytes is less than zero and is + * not {@link #UNBOUND} or {@link #DEFAULT}. */ @SuppressWarnings("UnusedDeclaration") - public void feed(final Buffer buffer, final boolean last) - throws IOException { - queue.offer(new BodyPart(buffer, last)); - queueSize.incrementAndGet(); - - if (context != null) { - flushQueue(true); + public synchronized void setMaxPendingBytes(final int maxPendingBytes) { + if (maxPendingBytes < DEFAULT) { + throw new IllegalArgumentException( + "Invalid maxPendingBytes value: " + maxPendingBytes); + } + if (asyncTransferInitiated) { + throw new IllegalStateException( + "Unable to set max pending bytes after async data transfer has been initiated."); } + configuredMaxPendingBytes = maxPendingBytes; } - public void initializeAsynchronousTransfer(final FilterChainContext context, - final HttpRequestPacket requestPacket) - throws IOException { - this.context = context; - this.requestPacket = requestPacket; - this.contentBuilder = HttpContent.builder(requestPacket); - // don't block here. If queue is full at the time of the next feed() - // call, it will block. - flushQueue(false); + + /** + * Add a {@link Feeder} implementation that will be invoked when writing + * without blocking is possible. This method must be set before dispatching + * the request this feeder is associated with. + * + * @param feeder the {@link Feeder} responsible for providing data. + * @throws IllegalStateException if called after {@link #initializeAsynchronousTransfer(FilterChainContext, HttpRequestPacket)} + * has been called by the {@link GrizzlyAsyncHttpProvider}. + * @throws IllegalArgumentException if feeder is null + */ + @SuppressWarnings("UnusedDeclaration") + public synchronized void setFeeder(final Feeder feeder) { + if (asyncTransferInitiated) { + throw new IllegalStateException( + "Unable to set Feeder after async data transfer has been initiated."); + } + if (feeder == null) { + throw new IllegalArgumentException( + "Feeder argument cannot be null."); + } + this.feeder = feeder; } - // --------------------------------------------------------- Private Methods + // ------------------------------------------------- Package Private Methods - @SuppressWarnings("unchecked") - private void flushQueue(final boolean allowBlocking) throws IOException { - if (queueSize.get() > 0) { - synchronized(this) { - final Connection c = context.getConnection(); - while(queueSize.get() > 0) { - if (allowBlocking) { - blockUntilQueueFree(c); + /** + * Even though this method is public, it's not intended to be called by + * Developers directly. Please avoid doing so. + */ + public synchronized void initializeAsynchronousTransfer(final FilterChainContext context, + final HttpRequestPacket requestPacket) + throws IOException { + + if (asyncTransferInitiated) { + throw new IllegalStateException( + "Async transfer has already been initiated."); + } + if (feeder == null) { + throw new IllegalStateException( + "No feeder available to perform the transfer."); + } + assert (context != null); + assert (requestPacket != null); + + this.requestPacket = requestPacket; + this.contentBuilder = HttpContent.builder(requestPacket); + final Connection c = context.getConnection(); + origMaxPendingBytes = c.getMaxAsyncWriteQueueSize(); + if (configuredMaxPendingBytes != DEFAULT) { + c.setMaxAsyncWriteQueueSize(configuredMaxPendingBytes); + } + this.context = context; + asyncTransferInitiated = true; + final Runnable r = new Runnable() { + @Override + public void run() { + try { + if (requestPacket.isSecure() && + (getSSLEngine(context.getConnection()) == null)) { + flushOnSSLHandshakeComplete(); + } else { + feeder.flush(); } - final BodyPart bodyPart = queue.poll(); - queueSize.decrementAndGet(); - final HttpContent content = - contentBuilder.content(bodyPart.buffer) - .last(bodyPart.isLast) - .build(); - context.write(content, - ((!requestPacket.isCommitted()) - ? context.getTransportContext() - .getCompletionHandler() - : null)); + } catch (IOException ioe) { + HttpTransactionContext ctx = HttpTransactionContext.get(c); + ctx.abort(ioe); } } + }; + + // If the current thread is a selector thread, we need to execute + // the remainder of the task on the worker thread to prevent + // it from being blocked. + if (isCurrentThreadSelectorRunner()) { + c.getTransport().getWorkerThreadPool().execute(r); + } else { + r.run(); } } - /** - * This method will block if the async write queue is currently larger - * than the configured maximum. The amount of time that this method - * will block is dependent on the write timeout of the transport - * associated with the specified connection. - */ - private void blockUntilQueueFree(final Connection c) { - if (!c.canWrite()) { - final FutureImpl future = - Futures.createSafeFuture(); - - // Connection may be obtained by calling FilterChainContext.getConnection(). - c.notifyCanWrite(new WriteHandler() { - @Override - public void onWritePossible() throws Exception { - future.result(TRUE); - } + // --------------------------------------------------------- Private Methods - @Override - public void onError(Throwable t) { - future.failure(makeIOException(t)); - } - }); - block(c, future); - } + private boolean isCurrentThreadSelectorRunner() { + final NIOConnection c = (NIOConnection) context.getConnection(); + final SelectorRunner runner = c.getSelectorRunner(); + return (Thread.currentThread() == runner.getRunnerThread()); } - private void block(final Connection c, - final FutureImpl future) { - try { - final long writeTimeout = - c.getTransport().getWriteTimeout(MILLISECONDS); - if (writeTimeout != -1) { - future.get(writeTimeout, MILLISECONDS); - } else { - future.get(); + + private void flushOnSSLHandshakeComplete() throws IOException { + final FilterChain filterChain = context.getFilterChain(); + final int idx = filterChain.indexOfType(SSLFilter.class); + assert (idx != -1); + final SSLFilter filter = (SSLFilter) filterChain.get(idx); + final Connection c = context.getConnection(); + filter.addHandshakeListener(new SSLBaseFilter.HandshakeListener() { + public void onStart(Connection connection) { } - } catch (ExecutionException e) { - HttpTransactionContext httpCtx = HttpTransactionContext.get(c); - httpCtx.abort(e.getCause()); - } catch (Exception e) { - HttpTransactionContext httpCtx = HttpTransactionContext.get(c); - httpCtx.abort(e); - } + + public void onComplete(Connection connection) { + if (c.equals(connection)) { + filter.removeHandshakeListener(this); + try { + feeder.flush(); + } catch (IOException ioe) { + HttpTransactionContext ctx = HttpTransactionContext.get(c); + ctx.abort(ioe); + } + } + } + }); + filter.handshake(context.getConnection(), null); } @@ -206,19 +258,405 @@ public void close() throws IOException { requestPacket = null; contentBuilder = null; } - } + + } // END EmptyBody // ---------------------------------------------------------- Nested Classes - private final static class BodyPart { - private final boolean isLast; - private final Buffer buffer; + /** + * Specifies the functionality all Feeders must implement. Typically, + * developers need not worry about implementing this interface directly. + * It should be sufficient, for most use-cases, to simply use the {@link NonBlockingFeeder} + * or {@link SimpleFeeder} implementations. + */ + public interface Feeder { + + /** + * This method will be invoked when it's possible to begin feeding + * data downstream. Implementations of this method must use {@link #feed(Buffer, boolean)} + * to perform the actual write. + * + * @throws IOException if an I/O error occurs. + */ + void flush() throws IOException; + + /** + * This method will write the specified {@link Buffer} to the connection. + * Be aware that this method may block depending if data is being fed + * faster than it can write. How much data may be queued is dictated + * by {@link #setMaxPendingBytes(int)}. Once this threshold is exceeded, + * the method will block until the write queue length drops below the + * aforementioned threshold. + * + * @param buffer the {@link Buffer} to write. + * @param last flag indicating if this is the last buffer to send. + * @throws IOException if an I/O error occurs. + * @throws java.lang.IllegalArgumentException if buffer + * is null. + * @throws java.lang.IllegalStateException if this method is invoked + * before asynchronous transferring has been initiated. + * @see #setMaxPendingBytes(int) + */ + @SuppressWarnings("UnusedDeclaration") + void feed(final Buffer buffer, final boolean last) throws IOException; + + } // END Feeder + + + /** + * Base class for {@link Feeder} implementations. This class provides + * an implementation for the contract defined by the {@link #feed} method. + */ + public static abstract class BaseFeeder implements Feeder { + + protected final FeedableBodyGenerator feedableBodyGenerator; + - public BodyPart(final Buffer buffer, final boolean isLast) { - this.buffer = buffer; - this.isLast = isLast; + // -------------------------------------------------------- Constructors + + + protected BaseFeeder(FeedableBodyGenerator feedableBodyGenerator) { + this.feedableBodyGenerator = feedableBodyGenerator; } - } + + + // --------------------------------------------- Package Private Methods + + + /** + * {@inheritDoc} + */ + @SuppressWarnings("UnusedDeclaration") + public final synchronized void feed(final Buffer buffer, final boolean last) + throws IOException { + if (buffer == null) { + throw new IllegalArgumentException( + "Buffer argument cannot be null."); + } + if (!feedableBodyGenerator.asyncTransferInitiated) { + throw new IllegalStateException( + "Asynchronous transfer has not been initiated."); + } + blockUntilQueueFree(feedableBodyGenerator.context.getConnection()); + final HttpContent content = + feedableBodyGenerator.contentBuilder + .content(buffer) + .last(last) + .build(); + final CompletionHandler handler = + ((last) ? new LastPacketCompletionHandler() : null); + feedableBodyGenerator.context.write(content, handler); + } + + /** + * This method will block if the async write queue is currently larger + * than the configured maximum. The amount of time that this method + * will block is dependent on the write timeout of the transport + * associated with the specified connection. + */ + private static void blockUntilQueueFree(final Connection c) { + if (!c.canWrite()) { + final FutureImpl future = + Futures.createSafeFuture(); + c.notifyCanWrite(new WriteHandler() { + + @Override + public void onWritePossible() throws Exception { + future.result(TRUE); + } + + @Override + public void onError(Throwable t) { + future.failure(makeIOException(t)); + } + }); + + block(c, future); + } + } + + private static void block(final Connection c, + final FutureImpl future) { + try { + final long writeTimeout = + c.getTransport().getWriteTimeout(MILLISECONDS); + if (writeTimeout != -1) { + future.get(writeTimeout, MILLISECONDS); + } else { + future.get(); + } + } catch (ExecutionException e) { + HttpTransactionContext ctx = HttpTransactionContext.get(c); + ctx.abort(e.getCause()); + } catch (Exception e) { + HttpTransactionContext ctx = HttpTransactionContext.get(c); + ctx.abort(e); + } + } + + + // ------------------------------------------------------- Inner Classes + + + private final class LastPacketCompletionHandler + implements CompletionHandler { + + private final CompletionHandler delegate; + private final Connection c; + private final int origMaxPendingBytes; + + // -------------------------------------------------------- Constructors + + + @SuppressWarnings("unchecked") + private LastPacketCompletionHandler() { + delegate = ((!feedableBodyGenerator.requestPacket.isCommitted()) + ? feedableBodyGenerator.context + .getTransportContext() + .getCompletionHandler() + : null); + c = feedableBodyGenerator.context.getConnection(); + origMaxPendingBytes = feedableBodyGenerator.origMaxPendingBytes; + } + + + // -------------------------------------- Methods from CompletionHandler + + + @Override + public void cancelled() { + c.setMaxAsyncWriteQueueSize(origMaxPendingBytes); + if (delegate != null) { + delegate.cancelled(); + } + } + + @Override + public void failed(Throwable throwable) { + c.setMaxAsyncWriteQueueSize(origMaxPendingBytes); + if (delegate != null) { + delegate.failed(throwable); + } + + } + + @Override + public void completed(WriteResult result) { + c.setMaxAsyncWriteQueueSize(origMaxPendingBytes); + if (delegate != null) { + delegate.completed(result); + } + + } + + @Override + public void updated(WriteResult result) { + if (delegate != null) { + delegate.updated(result); + } + } + + } // END LastPacketCompletionHandler + + } // END Feeder + + + /** + * Implementations of this class provide the framework to read data from + * some source and feed data to the {@link FeedableBodyGenerator} + * without blocking. + */ + @SuppressWarnings("UnusedDeclaration") + public static abstract class NonBlockingFeeder extends BaseFeeder { + + + // -------------------------------------------------------- Constructors + + + /** + * Constructs the NonBlockingFeeder with the associated + * {@link FeedableBodyGenerator}. + */ + public NonBlockingFeeder(final FeedableBodyGenerator feedableBodyGenerator) { + super(feedableBodyGenerator); + } + + + // ------------------------------------------------------ Public Methods + + + /** + * Notification that it's possible to send another block of data via + * {@link #feed(org.glassfish.grizzly.Buffer, boolean)}. + *

+ * It's important to only invoke {@link #feed(Buffer, boolean)} + * once per invocation of {@link #canFeed()}. + */ + public abstract void canFeed(); + + /** + * @return true if all data has been fed by this feeder, + * otherwise returns false. + */ + public abstract boolean isDone(); + + /** + * @return true if data is available to be fed, otherwise + * returns false. When this method returns false, + * the {@link FeedableBodyGenerator} will call {@link #notifyReadyToFeed(ReadyToFeedListener)} + * by which this {@link NonBlockingFeeder} implementation may signal data is once + * again available to be fed. + */ + public abstract boolean isReady(); + + /** + * Callback registration to signal the {@link FeedableBodyGenerator} that + * data is available once again to continue feeding. Once this listener + * has been invoked, the NonBlockingFeeder implementation should no longer maintain + * a reference to the listener. + */ + public abstract void notifyReadyToFeed(final ReadyToFeedListener listener); + + + // ------------------------------------------------- Methods from Feeder + + + /** + * {@inheritDoc} + */ + @Override + public synchronized void flush() { + final Connection c = feedableBodyGenerator.context.getConnection(); + if (isReady()) { + writeUntilFullOrDone(c); + if (!isDone()) { + if (!isReady()) { + notifyReadyToFeed(new ReadyToFeedListenerImpl()); + } + if (!c.canWrite()) { + // write queue is full, leverage WriteListener to let us know + // when it is safe to write again. + c.notifyCanWrite(new WriteHandlerImpl()); + } + } + } else { + notifyReadyToFeed(new ReadyToFeedListenerImpl()); + } + } + + + // ----------------------------------------------------- Private Methods + + + private void writeUntilFullOrDone(final Connection c) { + while (c.canWrite()) { + if (isReady()) { + canFeed(); + } + if (!isReady()) { + break; + } + } + } + + + // ------------------------------------------------------- Inner Classes + + + /** + * Listener to signal that data is available to be fed. + */ + public interface ReadyToFeedListener { + + /** + * Data is once again ready to be fed. + */ + @SuppressWarnings("UnusedDeclaration") + void ready(); + + } // END ReadyToFeedListener + + + private final class WriteHandlerImpl implements WriteHandler { + + + private final Connection c; + + + // -------------------------------------------------------- Constructors + + + private WriteHandlerImpl() { + this.c = feedableBodyGenerator.context.getConnection(); + } + + + // ------------------------------------------ Methods from WriteListener + + @Override + public void onWritePossible() throws Exception { + writeUntilFullOrDone(c); + if (!isDone()) { + if (!isReady()) { + notifyReadyToFeed(new ReadyToFeedListenerImpl()); + } + if (!c.canWrite()) { + // write queue is full, leverage WriteListener to let us know + // when it is safe to write again. + c.notifyCanWrite(this); + } + } + } + + @Override + public void onError(Throwable t) { + c.setMaxAsyncWriteQueueSize( + feedableBodyGenerator.origMaxPendingBytes); + HttpTransactionContext ctx = HttpTransactionContext.get(c); + ctx.abort(t); + } + + } // END WriteHandlerImpl + + + private final class ReadyToFeedListenerImpl + implements NonBlockingFeeder.ReadyToFeedListener { + + + // ------------------------------------ Methods from ReadyToFeedListener + + + @Override + public void ready() { + flush(); + } + + } // END ReadToFeedListenerImpl + + } // END NonBlockingFeeder + + + /** + * This simple {@link Feeder} implementation allows the implementation to + * feed data in whatever fashion is deemed appropriate. + */ + @SuppressWarnings("UnusedDeclaration") + public abstract static class SimpleFeeder extends BaseFeeder { + + + // -------------------------------------------------------- Constructors + + + /** + * Constructs the SimpleFeeder with the associated + * {@link FeedableBodyGenerator}. + */ + public SimpleFeeder(FeedableBodyGenerator feedableBodyGenerator) { + super(feedableBodyGenerator); + } + + + } // END SimpleFeeder } From 8c1779ae547089e776ee264d1ac239e163495906 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 19 Sep 2013 14:55:04 -0700 Subject: [PATCH 0126/2389] - Fix redirect test. - Update Grizzly provider to default back to the WorkerThreadIOStrategy. --- .../asynchttpclient/async/AsyncProvidersBasicTest.java | 2 +- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 5 +---- .../grizzly/GrizzlyAsyncProviderBasicTest.java | 10 ---------- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 9146be53aa..0472ef6ba6 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1358,7 +1358,7 @@ public void onThrowable(Throwable t) { } }; - client.prepareGet("http://www.google.com/").execute(handler); + client.prepareGet("http://google.com/").execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timed out"); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index c14e2309c4..5be8420e10 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -65,7 +65,6 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; import org.glassfish.grizzly.ssl.SSLFilter; -import org.glassfish.grizzly.strategies.SameThreadIOStrategy; import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy; import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.IdleTimeoutFilter; @@ -466,11 +465,9 @@ private FilterChainBuilder createSpdyFilterChain(final FilterChainBuilder fcb, private void doDefaultTransportConfig() { final ExecutorService service = clientConfig.executorService(); + clientTransport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); if (service != null) { - clientTransport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); clientTransport.setWorkerThreadPool(service); - } else { - clientTransport.setIOStrategy(SameThreadIOStrategy.getInstance()); } } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java index a20c34b49f..5bc8d7f211 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncProviderBasicTest.java @@ -36,17 +36,7 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { @Override protected AsyncHttpProviderConfig getProviderConfig() { final GrizzlyAsyncHttpProviderConfig config = new GrizzlyAsyncHttpProviderConfig(); - config.addProperty(TRANSPORT_CUSTOMIZER, new TransportCustomizer() { - @Override - public void customize(TCPNIOTransport transport, FilterChainBuilder builder) { - transport.setTcpNoDelay(true); - transport.setIOStrategy(SameThreadIOStrategy.getInstance()); - } - }); return config; } - @Test(groups = { "standalone", "default_provider", "async" }, enabled = false) - public void asyncDoPostBasicGZIPTest() throws Exception { - } } From 173081e6fc58f7f4e2dfca0f86b45aec6b418a8b Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 19 Sep 2013 19:15:00 -0700 Subject: [PATCH 0127/2389] - Removed SSL handshake logic from Grizzly's FeedableBodyGenerator. It's not needed anymore since the handshake is forced when the connection is made. --- .../grizzly/FeedableBodyGenerator.java | 37 +------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index b475ddaadc..584268ed6a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -23,20 +23,16 @@ import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.WriteResult; -import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.SelectorRunner; -import org.glassfish.grizzly.ssl.SSLBaseFilter; -import org.glassfish.grizzly.ssl.SSLFilter; import org.glassfish.grizzly.utils.Futures; import static java.lang.Boolean.TRUE; import static java.util.concurrent.TimeUnit.MILLISECONDS; -import static org.glassfish.grizzly.ssl.SSLUtils.getSSLEngine; import static org.glassfish.grizzly.utils.Exceptions.*; /** @@ -176,12 +172,7 @@ public synchronized void initializeAsynchronousTransfer(final FilterChainContext @Override public void run() { try { - if (requestPacket.isSecure() && - (getSSLEngine(context.getConnection()) == null)) { - flushOnSSLHandshakeComplete(); - } else { - feeder.flush(); - } + feeder.flush(); } catch (IOException ioe) { HttpTransactionContext ctx = HttpTransactionContext.get(c); ctx.abort(ioe); @@ -210,32 +201,6 @@ private boolean isCurrentThreadSelectorRunner() { } - private void flushOnSSLHandshakeComplete() throws IOException { - final FilterChain filterChain = context.getFilterChain(); - final int idx = filterChain.indexOfType(SSLFilter.class); - assert (idx != -1); - final SSLFilter filter = (SSLFilter) filterChain.get(idx); - final Connection c = context.getConnection(); - filter.addHandshakeListener(new SSLBaseFilter.HandshakeListener() { - public void onStart(Connection connection) { - } - - public void onComplete(Connection connection) { - if (c.equals(connection)) { - filter.removeHandshakeListener(this); - try { - feeder.flush(); - } catch (IOException ioe) { - HttpTransactionContext ctx = HttpTransactionContext.get(c); - ctx.abort(ioe); - } - } - } - }); - filter.handshake(context.getConnection(), null); - } - - // ----------------------------------------------------------- Inner Classes From 0eb190110dcb5ff50e310464d38ae4806a47b35f Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 20 Sep 2013 10:27:07 -0700 Subject: [PATCH 0128/2389] Upgrade to Grizzly 2.3.6. --- providers/grizzly/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index f7b481761c..775b199f1e 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -14,7 +14,7 @@ - 2.3.6-SNAPSHOT + 2.3.6 1.0 From c1eb6297a1f3467e2a9e19d2266ca2d03fd07cb7 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 20 Sep 2013 10:42:17 -0700 Subject: [PATCH 0129/2389] Set multiplier to two. --- .../java/org/asynchttpclient/AsyncHttpClientConfigBean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java index 46eb9fe311..b5944629a5 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfigBean.java @@ -54,7 +54,7 @@ void configureDefaults() { maxDefaultRedirects = Integer.getInteger(ASYNC_CLIENT + "defaultMaxRedirects", 5); compressionEnabled = Boolean.getBoolean(ASYNC_CLIENT + "compressionEnabled"); userAgent = System.getProperty(ASYNC_CLIENT + "userAgent", "AsyncHttpClient/" + AHC_VERSION); - ioThreadMultiplier = Integer.getInteger(ASYNC_CLIENT + "ioThreadMultiplier", 8); + ioThreadMultiplier = Integer.getInteger(ASYNC_CLIENT + "ioThreadMultiplier", 2); boolean useProxySelector = Boolean.getBoolean(ASYNC_CLIENT + "useProxySelector"); boolean useProxyProperties = Boolean.getBoolean(ASYNC_CLIENT + "useProxyProperties"); From e3af1bcaa83517ca469b775b124495d7041fe6c0 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 23 Sep 2013 16:15:14 -0700 Subject: [PATCH 0130/2389] Don't apply outbound encodings. --- .../providers/grizzly/filters/ClientEncodingFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java index 095d6c64b4..332c0fb8c9 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ClientEncodingFilter.java @@ -34,7 +34,7 @@ public final class ClientEncodingFilter implements EncodingFilter { public boolean applyEncoding(HttpHeader httpPacket) { httpPacket.addHeader(Header.AcceptEncoding, "gzip"); - return true; + return false; } From 75de57a18f16a427fac5d824f82cd069af608d2d Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 23 Sep 2013 16:18:25 -0700 Subject: [PATCH 0131/2389] Initial connection pool changes to support SPDY. --- .../providers/grizzly/ConnectionPool.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java index dae88f302e..0aec5b6a19 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/ConnectionPool.java @@ -13,6 +13,10 @@ package org.asynchttpclient.providers.grizzly; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.GrizzlyFuture; import org.glassfish.grizzly.connectionpool.EndpointKey; import org.glassfish.grizzly.connectionpool.MultiEndpointPool; import org.glassfish.grizzly.connectionpool.SingleEndpointPool; @@ -29,6 +33,7 @@ */ public class ConnectionPool extends MultiEndpointPool{ + private final Object lock = new Object(); // ------------------------------------------------------------ Constructors @@ -69,6 +74,62 @@ protected SingleEndpointPool obtainSingleEndpointPool( return sePool; } + @Override + public GrizzlyFuture take(final EndpointKey endpointKey) { + synchronized (lock) { + final GrizzlyFuture f = super.take(endpointKey); + f.addCompletionHandler(new EmptyCompletionHandler() { + @Override + public void completed(Connection result) { + if (Utils.isSpdyConnection(result)) { + release(result); + } + super.completed(result); + } + }); + return f; + } + } + + @Override + public void take(final EndpointKey endpointKey, + final CompletionHandler completionHandler) { + synchronized (lock) { + if (completionHandler == null) { + throw new IllegalStateException("CompletionHandler argument cannot be null."); + } + + super.take(endpointKey, new CompletionHandler() { + @Override + public void cancelled() { + completionHandler.cancelled(); + } + + @Override + public void failed(Throwable throwable) { + completionHandler.failed(throwable); + } + + @Override + public void completed(Connection result) { + release(result); + completionHandler.completed(result); + } + + @Override + public void updated(Connection result) { + completionHandler.updated(result); + } + }); + } + } + + @Override + public boolean release(Connection connection) { + synchronized (lock) { + return super.release(connection); + } + } // ---------------------------------------------------------- Nested Classes From 2f6f0d045eb3ec784c145f8e68a4c858c7339d9e Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 25 Sep 2013 12:02:17 -0700 Subject: [PATCH 0132/2389] Remove tunnel establishment checks. They are no longer needed as tunnelling is established when the connection is established. --- .../providers/grizzly/EventHandler.java | 39 ++++++------------- .../grizzly/HttpTransactionContext.java | 20 ---------- .../filters/AsyncHttpClientFilter.java | 2 +- .../ProxyAuthorizationHandler.java | 1 - 4 files changed, 13 insertions(+), 49 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 6ead4bbe5b..0b38e389b1 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -150,9 +150,6 @@ public void onInitialLineParsed(HttpHeader httpHeader, final HttpTransactionContext context = HttpTransactionContext.get(connection); final int status = ((HttpResponsePacket) httpHeader).getStatus(); - if (context.isEstablishingTunnel() && HttpStatus.OK_200.statusMatches(status)) { - return; - } if (HttpStatus.CONINTUE_100.statusMatches(status)) { ctx.notifyUpstream(new ContinueEvent(context)); return; @@ -239,9 +236,7 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, processKeepAlive(ctx.getConnection(), httpHeader); final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); - if (httpHeader.isSkipRemainder() - || (context.isEstablishingTunnel() - && context.getStatusHandler() == null)) { + if (httpHeader.isSkipRemainder()) { return; } @@ -374,28 +369,18 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) final HttpResponsePacket response = (HttpResponsePacket) httpHeader; - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); - if (context.isEstablishingTunnel() - && HttpStatus.OK_200.statusMatches(response.getStatus())) { - context.setEstablishingTunnel(false); - final Connection c = ctx.getConnection(); - context.tunnelEstablished(c); - context.getProvider().execute(c, - context.getRequest(), - context.getHandler(), - context.getFuture()); - } else { - cleanup(ctx); - final AsyncHandler handler = context.getHandler(); - if (handler != null) { - try { - context.result(handler.onCompleted()); - } catch (Exception e) { - context.abort(e); - } - } else { - context.done(); + final HttpTransactionContext context = HttpTransactionContext.get( + ctx.getConnection()); + cleanup(ctx); + final AsyncHandler handler = context.getHandler(); + if (handler != null) { + try { + context.result(handler.onCompleted()); + } catch (Exception e) { + context.abort(e); } + } else { + context.done(); } return false; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java index c9718e0613..c2f0573bfa 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java @@ -18,7 +18,6 @@ import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler; import org.asynchttpclient.providers.grizzly.statushandler.StatusHandler; import org.asynchttpclient.websocket.WebSocket; -import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.attributes.AttributeStorage; @@ -58,7 +57,6 @@ public final class HttpTransactionContext { private HandShake handshake; private ProtocolHandler protocolHandler; private WebSocket webSocket; - private boolean establishingTunnel; // -------------------------------------------------------- Constructors @@ -255,15 +253,6 @@ public void setWebSocket(WebSocket webSocket) { this.webSocket = webSocket; } - public boolean isEstablishingTunnel() { - return establishingTunnel; - } - - public void setEstablishingTunnel(boolean establishingTunnel) { - this.establishingTunnel = establishingTunnel; - } - - // ------------------------------------------------- Package Private Methods @@ -297,13 +286,4 @@ void result(Object result) { } } - public boolean isTunnelEstablished(final Connection c) { - return c.getAttributes().getAttribute("tunnel-established") != null; - } - - - public void tunnelEstablished(final Connection c) { - c.getAttributes().setAttribute("tunnel-established", Boolean.TRUE); - } - } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 2a28405f85..eca4040f98 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -254,7 +254,7 @@ private boolean sendAsGrizzlyRequest(final Request request, } } - if (httpCtx.isWSRequest() && !httpCtx.isEstablishingTunnel()) { + if (httpCtx.isWSRequest()) { try { final URI wsURI = new URI(httpCtx.getWsRequestURI()); httpCtx.setProtocolHandler(Version.RFC6455.createHandler(true)); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index 260a77acaf..5903932971 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -173,7 +173,6 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, HttpTransactionContext.set(c, newContext); newContext.setInvocationStatus(tempInvocationStatus); - httpTransactionContext.setEstablishingTunnel(true); return executeRequest(httpTransactionContext, req, c); From 3e54dfee276035b085cea91f83de0aa31011a3f4 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 25 Sep 2013 12:18:26 -0700 Subject: [PATCH 0133/2389] HttpTransactionContext renamed to HttpTxContext. --- .../providers/grizzly/EventHandler.java | 47 +++++++++---------- .../grizzly/FeedableBodyGenerator.java | 8 ++-- .../grizzly/GrizzlyAsyncHttpProvider.java | 14 +++--- ...sactionContext.java => HttpTxContext.java} | 30 ++++++------ .../grizzly/bodyhandler/FileBodyHandler.java | 6 +-- .../filters/AsyncHttpClientFilter.java | 12 ++--- .../AsyncHttpClientTransportFilter.java | 8 ++-- .../grizzly/filters/ProxyFilter.java | 4 +- .../grizzly/filters/events/ContinueEvent.java | 8 ++-- .../statushandler/AuthorizationHandler.java | 10 ++-- .../ProxyAuthorizationHandler.java | 20 ++++---- .../statushandler/RedirectHandler.java | 10 ++-- .../grizzly/statushandler/StatusHandler.java | 4 +- 13 files changed, 90 insertions(+), 91 deletions(-) rename providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/{HttpTransactionContext.java => HttpTxContext.java} (89%) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 0b38e389b1..d1b94d5bc3 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -34,7 +34,6 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpHeader; -import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.ProcessingState; import org.glassfish.grizzly.http.Protocol; @@ -92,7 +91,7 @@ public final class EventHandler { public void exceptionOccurred(FilterChainContext ctx, Throwable error) { - HttpTransactionContext.get(ctx.getConnection()).abort(error); + HttpTxContext.get(ctx.getConnection()).abort(error); } @@ -100,8 +99,8 @@ public void exceptionOccurred(FilterChainContext ctx, Throwable error) { public void onHttpContentParsed(HttpContent content, FilterChainContext ctx) { - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); if (handler != null && context.getCurrentState() != ABORT) { try { @@ -119,8 +118,8 @@ public void onHttpContentParsed(HttpContent content, @SuppressWarnings("UnusedParameters") public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) { - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); if (handler instanceof TransferCompletionHandler) { ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); @@ -128,8 +127,8 @@ public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) } public void onHttpContentEncoded(HttpContent content, FilterChainContext ctx) { - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); final AsyncHandler handler = context.getHandler(); if (handler instanceof TransferCompletionHandler) { final int written = content.getContent().remaining(); @@ -147,8 +146,8 @@ public void onInitialLineParsed(HttpHeader httpHeader, return; } final Connection connection = ctx.getConnection(); - final HttpTransactionContext context = - HttpTransactionContext.get(connection); + final HttpTxContext context = + HttpTxContext.get(connection); final int status = ((HttpResponsePacket) httpHeader).getStatus(); if (HttpStatus.CONINTUE_100.statusMatches(status)) { ctx.notifyUpstream(new ContinueEvent(context)); @@ -222,8 +221,8 @@ public void onHttpHeaderError(final HttpHeader httpHeader, t.printStackTrace(); httpHeader.setSkipRemainder(true); - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); context.abort(t); } @@ -234,7 +233,7 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, //super.onHttpHeadersParsed(httpHeader, ctx); GrizzlyAsyncHttpProvider.LOGGER.debug("RESPONSE: {}", httpHeader); processKeepAlive(ctx.getConnection(), httpHeader); - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); if (httpHeader.isSkipRemainder()) { return; @@ -270,10 +269,10 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, final Connection c = m.obtainConnection(newRequest, context.getFuture()); - final HttpTransactionContext newContext = + final HttpTxContext newContext = context.copy(); context.setFuture(null); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); context.getProvider().execute(c, newRequest, newHandler, @@ -369,7 +368,7 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) final HttpResponsePacket response = (HttpResponsePacket) httpHeader; - final HttpTransactionContext context = HttpTransactionContext.get( + final HttpTxContext context = HttpTxContext.get( ctx.getConnection()); cleanup(ctx); final AsyncHandler handler = context.getHandler(); @@ -405,7 +404,7 @@ private static void processKeepAlive(final Connection c, } - private static GrizzlyWebSocketAdapter createWebSocketAdapter(final HttpTransactionContext context) { + private static GrizzlyWebSocketAdapter createWebSocketAdapter(final HttpTxContext context) { SimpleWebSocket ws = new SimpleWebSocket(context.getProtocolHandler()); AsyncHttpProviderConfig config = context.getProvider().getClientConfig().getAsyncHttpProviderConfig(); boolean bufferFragments = true; @@ -417,7 +416,7 @@ private static GrizzlyWebSocketAdapter createWebSocketAdapter(final HttpTransact return new GrizzlyWebSocketAdapter(ws, bufferFragments); } - private static boolean isRedirectAllowed(final HttpTransactionContext ctx) { + private static boolean isRedirectAllowed(final HttpTxContext ctx) { boolean allowed = ctx.getRequest().isRedirectEnabled(); if (ctx.getRequest().isRedirectOverrideSet()) { return allowed; @@ -428,12 +427,12 @@ private static boolean isRedirectAllowed(final HttpTransactionContext ctx) { return allowed; } - private static HttpTransactionContext cleanup(final FilterChainContext ctx) { + private static HttpTxContext cleanup(final FilterChainContext ctx) { final Connection c = ctx.getConnection(); - final HttpTransactionContext context = - HttpTransactionContext.get(c); - HttpTransactionContext.set(c, null); + final HttpTxContext context = + HttpTxContext.get(c); + HttpTxContext.set(c, null); if (!Utils.isIgnored(ctx.getConnection())) { final ConnectionManager manager = context.getProvider().getConnectionManager(); @@ -452,7 +451,7 @@ private static HttpTransactionContext cleanup(final FilterChainContext ctx) { } - private static boolean redirectCountExceeded(final HttpTransactionContext context) { + private static boolean redirectCountExceeded(final HttpTxContext context) { return (context.getRedirectCount().get() > context.getMaxRedirectCount()); @@ -474,7 +473,7 @@ public static boolean isRedirect(final int status) { public static Request newRequest(final URI uri, final HttpResponsePacket response, - final HttpTransactionContext ctx, + final HttpTxContext ctx, boolean asGet) { final RequestBuilder builder = new RequestBuilder(ctx.getRequest()); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index 584268ed6a..f338897e6f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -174,7 +174,7 @@ public void run() { try { feeder.flush(); } catch (IOException ioe) { - HttpTransactionContext ctx = HttpTransactionContext.get(c); + HttpTxContext ctx = HttpTxContext.get(c); ctx.abort(ioe); } } @@ -353,10 +353,10 @@ private static void block(final Connection c, future.get(); } } catch (ExecutionException e) { - HttpTransactionContext ctx = HttpTransactionContext.get(c); + HttpTxContext ctx = HttpTxContext.get(c); ctx.abort(e.getCause()); } catch (Exception e) { - HttpTransactionContext ctx = HttpTransactionContext.get(c); + HttpTxContext ctx = HttpTxContext.get(c); ctx.abort(e); } } @@ -579,7 +579,7 @@ public void onWritePossible() throws Exception { public void onError(Throwable t) { c.setMaxAsyncWriteQueueSize( feedableBodyGenerator.origMaxPendingBytes); - HttpTransactionContext ctx = HttpTransactionContext.get(c); + HttpTxContext ctx = HttpTxContext.get(c); ctx.abort(t); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 5be8420e10..12995bb4f6 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -241,8 +241,8 @@ public ListenableFuture execute(final Connection c, final AsyncHandler handler, final GrizzlyResponseFuture future) { Utils.addRequestInFlight(c); - if (HttpTransactionContext.get(c) == null) { - HttpTransactionContext.create(this, future, request, handler, c); + if (HttpTxContext.get(c) == null) { + HttpTxContext.create(this, future, request, handler, c); } c.write(request, createWriteCompletionHandler(future)); @@ -271,8 +271,8 @@ void initializeTransport(final AsyncHttpClientConfig clientConfig) { new IdleTimeoutFilter.TimeoutResolver() { @Override public long getTimeout(FilterChainContext ctx) { - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); if (context != null) { if (context.isWSRequest()) { return clientConfig.getWebSocketIdleTimeoutInMs(); @@ -495,9 +495,9 @@ public void updated(WriteResult result) { void timeout(final Connection c) { - final HttpTransactionContext context = HttpTransactionContext.get(c); + final HttpTxContext context = HttpTxContext.get(c); if (context != null) { - HttpTransactionContext.set(c, null); + HttpTxContext.set(c, null); context.abort(new TimeoutException("Timeout exceeded")); } @@ -513,7 +513,7 @@ public boolean sendRequest(final FilterChainContext ctx, boolean isWriteComplete = true; if (requestHasEntityBody(request)) { - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); BodyHandler handler = bodyHandlerFactory.getBodyHandler(request); if (requestPacket.getHeaders().contains(Header.Expect) && requestPacket.getHeaders().getValue(1).equalsIgnoreCase("100-Continue")) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java similarity index 89% rename from providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java rename to providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java index c2f0573bfa..344128f75a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTransactionContext.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java @@ -29,10 +29,10 @@ import static org.asynchttpclient.providers.grizzly.statushandler.StatusHandler.InvocationStatus; -public final class HttpTransactionContext { +public final class HttpTxContext { - private static final Attribute REQUEST_STATE_ATTR = - Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(HttpTransactionContext.class.getName()); + private static final Attribute REQUEST_STATE_ATTR = + Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(HttpTxContext.class.getName()); private final AtomicInteger redirectCount = new AtomicInteger(0); @@ -62,10 +62,10 @@ public final class HttpTransactionContext { // -------------------------------------------------------- Constructors - private HttpTransactionContext(GrizzlyAsyncHttpProvider provider, - final GrizzlyResponseFuture future, - final Request request, - final AsyncHandler handler) { + private HttpTxContext(final GrizzlyAsyncHttpProvider provider, + final GrizzlyResponseFuture future, + final Request request, + final AsyncHandler handler) { this.provider = provider; this.future = future; @@ -82,7 +82,7 @@ private HttpTransactionContext(GrizzlyAsyncHttpProvider provider, public static void set(final AttributeStorage storage, - final HttpTransactionContext httpTransactionState) { + final HttpTxContext httpTransactionState) { if (httpTransactionState == null) { REQUEST_STATE_ATTR.remove(storage); @@ -92,20 +92,20 @@ public static void set(final AttributeStorage storage, } - public static HttpTransactionContext get(final AttributeStorage storage) { + public static HttpTxContext get(final AttributeStorage storage) { return REQUEST_STATE_ATTR.get(storage); } - public static HttpTransactionContext create(final GrizzlyAsyncHttpProvider provider, + public static HttpTxContext create(final GrizzlyAsyncHttpProvider provider, final GrizzlyResponseFuture future, final Request request, final AsyncHandler handler, final AttributeStorage storage) { - final HttpTransactionContext context = - new HttpTransactionContext(provider, future, request, handler); + final HttpTxContext context = + new HttpTxContext(provider, future, request, handler); set(storage, context); return context; } @@ -256,9 +256,9 @@ public void setWebSocket(WebSocket webSocket) { // ------------------------------------------------- Package Private Methods - public HttpTransactionContext copy() { - final HttpTransactionContext newContext = - new HttpTransactionContext(provider, + public HttpTxContext copy() { + final HttpTxContext newContext = + new HttpTxContext(provider, future, request, handler); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java index 8029d7f80c..368a3a2c09 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java @@ -16,7 +16,7 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.Request; import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.FileTransfer; @@ -55,7 +55,7 @@ public boolean doHandle(final FilterChainContext ctx, final File f = request.getFile(); requestPacket.setContentLengthLong(f.length()); - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); if (!SEND_FILE_SUPPORT || requestPacket.isSecure()) { final FileInputStream fis = new FileInputStream(request.getFile()); final MemoryManager mm = ctx.getMemoryManager(); @@ -109,7 +109,7 @@ public void completed(WriteResult result) { // --------------------------------------------------------- Private Methods - private static void notifyHandlerIfNeeded(final HttpTransactionContext context, + private static void notifyHandlerIfNeeded(final HttpTxContext context, final HttpRequestPacket requestPacket, final WriteResult writeResult) { final AsyncHandler handler = context.getHandler(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index eca4040f98..52527f597c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -28,7 +28,7 @@ import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.GrizzlyResponseFuture; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.asynchttpclient.providers.grizzly.Utils; import org.asynchttpclient.providers.grizzly.bodyhandler.ExpectHandler; import org.asynchttpclient.providers.grizzly.filters.events.ContinueEvent; @@ -207,7 +207,7 @@ private boolean sendAsGrizzlyRequest(final Request request, final FilterChainContext ctx) throws IOException { - final HttpTransactionContext httpCtx = HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext httpCtx = HttpTxContext.get(ctx.getConnection()); if (checkProxyAuthFailure(ctx, httpCtx)) { return true; @@ -218,7 +218,7 @@ private boolean sendAsGrizzlyRequest(final Request request, // If the request is secure, check to see if an error occurred during // the handshake. We have to do this here, as the error would occur - // out of the scope of a HttpTransactionContext so there would be + // out of the scope of a HttpTxContext so there would be // no good way to communicate the problem to the caller. if (secure && checkHandshakeError(ctx, httpCtx)) { return true; @@ -323,7 +323,7 @@ private static void initTransferCompletionHandler(final Request request, } private static boolean checkHandshakeError(final FilterChainContext ctx, - final HttpTransactionContext httpCtx) { + final HttpTxContext httpCtx) { Throwable t = getHandshakeError(ctx.getConnection()); if (t != null) { httpCtx.abort(t); @@ -333,7 +333,7 @@ private static boolean checkHandshakeError(final FilterChainContext ctx, } private static boolean checkProxyAuthFailure(final FilterChainContext ctx, - final HttpTransactionContext httpCtx) { + final HttpTxContext httpCtx) { final Boolean failed = PROXY_AUTH_FAILURE.get(ctx.getConnection()); if (failed != null && failed) { httpCtx.abort(new IllegalStateException("Unable to authenticate with proxy")); @@ -384,7 +384,7 @@ private static boolean isWSRequest(final String requestUri) { return (requestUri.charAt(0) == 'w' && requestUri.charAt(1) == 's'); } - private static void convertToUpgradeRequest(final HttpTransactionContext ctx) { + private static void convertToUpgradeRequest(final HttpTxContext ctx) { final int colonIdx = ctx.getRequestUrl().indexOf(':'); if (colonIdx < 2 || colonIdx > 3) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java index 8de7d91554..39982d6c5c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java @@ -13,7 +13,7 @@ package org.asynchttpclient.providers.grizzly.filters; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; @@ -37,8 +37,8 @@ public final class AsyncHttpClientTransportFilter extends TransportFilter { @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { - final HttpTransactionContext context = - HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = + HttpTxContext.get(ctx.getConnection()); if (context == null) { return super.handleRead(ctx); } @@ -68,7 +68,7 @@ public void updated(Object result) { @Override public void exceptionOccurred(FilterChainContext ctx, Throwable error) { - final HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); if (context != null) { context.abort(error.getCause()); } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java index 9f479db7f4..0a2be3030b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java @@ -17,7 +17,7 @@ import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Realm; import org.asynchttpclient.Request; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; @@ -65,7 +65,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { org.glassfish.grizzly.http.HttpContent content = ctx.getMessage(); HttpRequestPacket request = (HttpRequestPacket) content.getHttpHeader(); - HttpTransactionContext context = HttpTransactionContext.get(ctx.getConnection()); + HttpTxContext context = HttpTxContext.get(ctx.getConnection()); assert(context != null); Request req = context.getRequest(); if (!secure) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java index 247bed46fa..a7a710369f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/ContinueEvent.java @@ -13,7 +13,7 @@ package org.asynchttpclient.providers.grizzly.filters.events; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.glassfish.grizzly.filterchain.FilterChainEvent; /** @@ -24,13 +24,13 @@ */ public final class ContinueEvent implements FilterChainEvent { - private final HttpTransactionContext context; + private final HttpTxContext context; // -------------------------------------------------------- Constructors - public ContinueEvent(final HttpTransactionContext context) { + public ContinueEvent(final HttpTxContext context) { this.context = context; @@ -49,7 +49,7 @@ public Object type() { // ---------------------------------------------------------- Public Methods - public HttpTransactionContext getContext() { + public HttpTxContext getContext() { return context; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java index 04a2d72507..2ee3ef7b08 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java @@ -16,7 +16,7 @@ import org.asynchttpclient.Realm; import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.ConnectionManager; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.asynchttpclient.util.AuthenticatorUtils; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -44,7 +44,7 @@ public boolean handlesStatus(int statusCode) { @SuppressWarnings({"unchecked"}) public boolean handleStatus(final HttpResponsePacket responsePacket, - final HttpTransactionContext httpTransactionContext, + final HttpTxContext httpTransactionContext, final FilterChainContext ctx) { final String auth = responsePacket.getHeader(Header.WWWAuthenticate); @@ -100,10 +100,10 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, req, responsePacket, httpTransactionContext); - final HttpTransactionContext newContext = + final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); newContext.setInvocationStatus(STOP); httpTransactionContext.getProvider().execute(c, req, @@ -124,7 +124,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, private Connection getConnectionForNextRequest(final FilterChainContext ctx, final Request request, final HttpResponsePacket response, - final HttpTransactionContext httpCtx) + final HttpTxContext httpCtx) throws Exception { if (response.getProcessingState().isKeepAlive()) { return ctx.getConnection(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index 5903932971..dbe8ff5d9a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -18,7 +18,7 @@ import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.ConnectionManager; import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.asynchttpclient.util.AuthenticatorUtils; import org.asynchttpclient.util.Base64; import org.glassfish.grizzly.Connection; @@ -53,7 +53,7 @@ public boolean handlesStatus(int statusCode) { @SuppressWarnings({"unchecked"}) public boolean handleStatus(final HttpResponsePacket responsePacket, - final HttpTransactionContext httpTransactionContext, + final HttpTxContext httpTransactionContext, final FilterChainContext ctx) { final String proxyAuth = @@ -146,10 +146,10 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, req, responsePacket, httpTransactionContext); - final HttpTransactionContext newContext = + final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); newContext.setInvocationStatus(tempInvocationStatus); @@ -166,11 +166,11 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, return executeRequest(httpTransactionContext, req, c); } else if (isNTLMSecondHandShake(proxyAuth)) { final Connection c = ctx.getConnection(); - final HttpTransactionContext newContext = + final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); newContext.setInvocationStatus(tempInvocationStatus); @@ -181,10 +181,10 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, req, responsePacket, httpTransactionContext); - final HttpTransactionContext newContext = + final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); newContext.setInvocationStatus(tempInvocationStatus); @@ -199,7 +199,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, } private boolean executeRequest( - final HttpTransactionContext httpTransactionContext, + final HttpTxContext httpTransactionContext, final Request req, final Connection c) { httpTransactionContext.getProvider().execute(c, req, @@ -220,7 +220,7 @@ private static boolean isNTLMFirstHandShake(final String proxy_auth) { private Connection getConnectionForNextRequest(final FilterChainContext ctx, final Request request, final HttpResponsePacket response, - final HttpTransactionContext httpCtx) + final HttpTxContext httpCtx) throws Exception { if (response.getProcessingState().isKeepAlive()) { return ctx.getConnection(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java index b9e2d6519d..448d004c16 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java @@ -16,7 +16,7 @@ import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.ConnectionManager; import org.asynchttpclient.providers.grizzly.EventHandler; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -41,7 +41,7 @@ public boolean handlesStatus(int statusCode) { @SuppressWarnings({"unchecked"}) public boolean handleStatus(final HttpResponsePacket responsePacket, - final HttpTransactionContext httpTransactionContext, + final HttpTxContext httpTransactionContext, final FilterChainContext ctx) { final String redirectURL = responsePacket.getHeader(Header.Location); @@ -83,13 +83,13 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, try { final Connection c = m.obtainConnection(requestToSend, httpTransactionContext.getFuture()); - final HttpTransactionContext newContext = + final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); newContext.setInvocationStatus(CONTINUE); newContext.setRequest(requestToSend); newContext.setRequestUrl(requestToSend.getUrl()); - HttpTransactionContext.set(c, newContext); + HttpTxContext.set(c, newContext); httpTransactionContext.getProvider().execute(c, requestToSend, newContext.getHandler(), @@ -108,7 +108,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, // ------------------------------------------------- Private Methods private boolean sendAsGet(final HttpResponsePacket response, - final HttpTransactionContext ctx) { + final HttpTxContext ctx) { final int statusCode = response.getStatus(); return !(statusCode < 302 || statusCode > 303) && !(statusCode == 302 diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/StatusHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/StatusHandler.java index 5ec587a422..5e2ec5d0cc 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/StatusHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/StatusHandler.java @@ -13,7 +13,7 @@ package org.asynchttpclient.providers.grizzly.statushandler; -import org.asynchttpclient.providers.grizzly.HttpTransactionContext; +import org.asynchttpclient.providers.grizzly.HttpTxContext; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpResponsePacket; @@ -25,7 +25,7 @@ public enum InvocationStatus { } boolean handleStatus(final HttpResponsePacket httpResponse, - final HttpTransactionContext httpTransactionContext, + final HttpTxContext httpTransactionContext, final FilterChainContext ctx); boolean handlesStatus(final int statusCode); From b8736f9e0c021e205aa01202933840b83afca143 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 25 Sep 2013 18:20:05 -0700 Subject: [PATCH 0134/2389] Include a timeout on all Future.get() calls. --- .../async/AsyncProvidersBasicTest.java | 86 +++++++++---------- .../async/AsyncStreamHandlerTest.java | 2 +- .../async/AuthTimeoutTest.java | 8 +- .../asynchttpclient/async/BasicAuthTest.java | 2 +- .../asynchttpclient/async/BasicHttpsTest.java | 4 +- .../asynchttpclient/async/BodyChunkTest.java | 3 +- .../async/BodyDeferringAsyncHandlerTest.java | 5 +- .../async/ByteBufferCapacityTest.java | 3 +- .../asynchttpclient/async/ChunkingTest.java | 3 +- .../async/ConnectionPoolTest.java | 8 +- .../asynchttpclient/async/EmptyBodyTest.java | 2 +- .../async/Expect100ContinueTest.java | 3 +- .../async/FilePartLargeFileTest.java | 5 +- .../org/asynchttpclient/async/FilterTest.java | 15 ++-- .../async/HostnameVerifierTest.java | 11 +-- .../async/HttpToHttpsRedirectTest.java | 9 +- .../async/IdleStateHandlerTest.java | 3 +- .../async/InputStreamTest.java | 3 +- .../async/MaxTotalConnectionTest.java | 7 +- .../async/MultipartUploadTest.java | 3 +- .../async/NoNullResponseTest.java | 5 +- .../async/NonAsciiContentLengthTest.java | 7 +- .../async/PerRequestRelative302Test.java | 9 +- .../async/PerRequestTimeoutTest.java | 9 +- .../async/PostRedirectGetTest.java | 5 +- .../org/asynchttpclient/async/ProxyTest.java | 2 +- .../async/ProxyTunnellingTest.java | 7 +- .../async/PutLargeFileTest.java | 5 +- .../async/QueryParametersTest.java | 5 +- .../org/asynchttpclient/async/RC10KTest.java | 3 +- .../async/RedirectConnectionUsageTest.java | 3 +- .../async/Relative302Test.java | 9 +- .../asynchttpclient/async/RemoteSiteTest.java | 16 ++-- .../async/RetryRequestTest.java | 3 +- .../SimpleAsyncClientErrorBehaviourTest.java | 5 +- .../async/SimpleAsyncHttpClientTest.java | 25 +++--- .../async/TransferListenerTest.java | 7 +- .../async/WebDavBasicTest.java | 35 +++++--- .../async/ZeroCopyFileTest.java | 9 +- .../websocket/ByteMessageTest.java | 9 +- .../websocket/CloseCodeReasonMessageTest.java | 5 +- .../websocket/RedirectTest.java | 35 ++++---- .../websocket/TextMessageTest.java | 19 ++-- 43 files changed, 234 insertions(+), 188 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 0472ef6ba6..974f264e3f 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -78,7 +78,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertEquals(url, getTargetUrl() + "?q=%20%20x"); } finally { client.close(); @@ -103,7 +103,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertEquals(url, getTargetUrl() + "?q=a%20b"); } finally { client.close(); @@ -128,7 +128,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertEquals(url, getTargetUrl()); } finally { client.close(); @@ -172,7 +172,7 @@ public void onThrowable(Throwable t) { } } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -200,7 +200,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -227,7 +227,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -264,7 +264,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -301,7 +301,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -328,7 +328,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); try { String s = response.getResponseBody(); @@ -370,7 +370,7 @@ public void onThrowable(Throwable t) { } } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(10 * 5 * 1000, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -412,7 +412,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -447,7 +447,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -483,7 +483,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -511,7 +511,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -525,7 +525,7 @@ public Response onCompleted(Response response) throws Exception { public void asyncDoPostBodyIsoTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(); + Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getResponseBody().getBytes("ISO-8859-1"), "\u017D\u017D\u017D\u017D\u017D\u017D".getBytes("ISO-8859-1")); } finally { client.close(); @@ -561,7 +561,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -601,7 +601,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -638,7 +638,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -670,7 +670,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -704,7 +704,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -734,7 +734,7 @@ public Response onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { } - }).get(); + }).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-Proxy-Connection"), "keep-alive"); @@ -756,7 +756,7 @@ public void asyncRequestVirtualServerPOSTTest() throws Exception { } Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setParameters(m).setVirtualHost("localhost:" + port1).build(); - Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(); + Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); if (response.getHeader("X-Host").startsWith("localhost")) { @@ -781,7 +781,7 @@ public void asyncDoPutTest() throws Exception { } sb.setLength(sb.length() - 1); - Response response = client.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(); + Response response = client.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { @@ -897,7 +897,7 @@ public void asyncDoPostNullBytesTest() throws Exception { Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { @@ -952,7 +952,7 @@ public void asyncConnectInvalidFuture() throws Exception { public void onThrowable(Throwable t) { count.incrementAndGet(); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(response, "Should have thrown ExecutionException"); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); @@ -978,7 +978,7 @@ public void asyncConnectInvalidPortFuture() throws Exception { public void onThrowable(Throwable t) { t.printStackTrace(); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(response, "Should have thrown ExecutionException"); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); @@ -1004,7 +1004,7 @@ public void asyncConnectInvalidPort() throws Exception { public void onThrowable(Throwable t) { t.printStackTrace(); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(response, "No ExecutionException was thrown"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -1085,7 +1085,7 @@ public void onThrowable(Throwable t) { rightCause.set(true); } } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(response, "No ExecutionException was thrown"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -1107,7 +1107,7 @@ public void asyncContentLenghtGETTest() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -1126,7 +1126,7 @@ public void asyncResponseBodyTooLarge() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE)); } finally { @@ -1144,7 +1144,7 @@ public void asyncResponseEmptyBody() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertEquals(response.getResponseBody(), ""); } finally { @@ -1284,7 +1284,7 @@ public Response onCompleted(Response response) throws Exception { Request req = new RequestBuilder("GET").setUrl(getTargetUrl() + "?foo=bar").build(); - client.executeRequest(req, handler).get(); + client.executeRequest(req, handler).get(5, TimeUnit.SECONDS); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timed out"); @@ -1321,7 +1321,7 @@ public Response onCompleted(Response response) throws Exception { } }; - client.prepareGet(getTargetUrl()).execute(handler).get(); + client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); client.prepareGet(getTargetUrl()).execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { @@ -1415,7 +1415,7 @@ public void onThrowable(Throwable t) { public void asyncDoGetStreamAndBodyTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1426,7 +1426,7 @@ public void asyncDoGetStreamAndBodyTest() throws Exception { public void asyncUrlWithoutPathTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1437,7 +1437,7 @@ public void asyncUrlWithoutPathTest() throws Exception { public void optionsTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareOptions(getTargetUrl()).execute().get(); + Response response = client.prepareOptions(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE"); @@ -1450,7 +1450,7 @@ public void optionsTest() throws Exception { public void testAwsS3() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(5, TimeUnit.SECONDS); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { @@ -1466,7 +1466,7 @@ public void testAsyncHttpProviderConfig() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setAsyncHttpClientProviderConfig(getProviderConfig()).build()); try { - Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(5, TimeUnit.SECONDS); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { @@ -1487,7 +1487,7 @@ public void idleRequestTimeoutTest() throws Exception { long t1 = millisTime(); try { - client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); + client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(10, TimeUnit.SECONDS); fail(); } catch (Throwable ex) { final long elapsedTime = millisTime() - t1; @@ -1560,7 +1560,7 @@ public void headShouldNotAllowBody() throws IllegalArgumentException, IOExceptio public void invalidUri() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(); + Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(5, TimeUnit.SECONDS); assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -1571,7 +1571,7 @@ public void invalidUri() throws Exception { public void asyncHttpClientConfigBeanTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test")); try { - Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(); + Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(5, TimeUnit.SECONDS); assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -1582,7 +1582,7 @@ public void asyncHttpClientConfigBeanTest() throws Exception { public void bodyAsByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet(getTargetUrl()).execute().get(); + Response response = client.prepareGet(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBodyAsBytes(), new byte[] {}); } finally { @@ -1594,7 +1594,7 @@ public void bodyAsByteTest() throws Exception { public void mirrorByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); + Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(new String(response.getResponseBodyAsBytes(), "UTF-8"), "MIRROR"); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index 1d31d21ac7..d78692f9df 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -560,7 +560,7 @@ public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio public Response onCompleted() throws Exception { return builder.build(); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(r); assertEquals(r.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java index 962e996cd2..dd97e21dfa 100644 --- a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java @@ -85,7 +85,7 @@ public void basicAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server, false); - f.get(); + f.get(5, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -99,7 +99,7 @@ public void basicPreemptiveAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server, true); - f.get(); + f.get(5, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -113,7 +113,7 @@ public void digestAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server2, false); - f.get(); + f.get(5, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -127,7 +127,7 @@ public void digestPreemptiveAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server2, true); - f.get(); + f.get(5, TimeUnit.SECONDS); fail("expected timeout"); } catch (Exception e) { inspectException(e); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index 0fecd118d7..ac23977eaf 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -351,7 +351,7 @@ public void stringBuilderBodyConsumerTest() throws Exception { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); - Response response = future.get(); + Response response = future.get(3, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index 1efde2f983..bd24dce5e3 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -42,7 +42,7 @@ public void zeroCopyPostTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -80,7 +80,7 @@ public void multipleSSLWithoutCacheTest() throws Exception { c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute(); - Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(); + Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getResponseBody(), body); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java index e6d19b6401..1993f43e43 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import static org.testng.Assert.assertEquals; @@ -50,7 +51,7 @@ public void negativeContentTypeTest() throws Exception { Future future = client.executeRequest(requestBuilder.build()); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBody(), MY_MESSAGE); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java index 09e16e9763..43efb9c44f 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java @@ -22,6 +22,7 @@ import java.io.PipedOutputStream; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.servlet.ServletException; @@ -126,7 +127,7 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) - f.get(); + f.get(5, TimeUnit.SECONDS); // it all should be here now assertEquals(cos.getByteCount(), HALF_GIG); } finally { @@ -155,7 +156,7 @@ public void deferredSimpleWithFailure() throws IOException, ExecutionException, // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) try { - f.get(); + f.get(5, TimeUnit.SECONDS); fail("get() should fail with IOException!"); } catch (Exception e) { // good diff --git a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java index 47c453e886..75165ae503 100644 --- a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java @@ -20,6 +20,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; @@ -86,7 +87,7 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep return super.onBodyPartReceived(content); } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index 66e9ef3692..10a0b3cf26 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -18,6 +18,7 @@ import java.io.BufferedInputStream; import java.io.FileInputStream; +import java.util.concurrent.TimeUnit; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -60,7 +61,7 @@ public void testCustomChunking() throws Exception { Request r = builder.build(); - Response response = c.executeRequest(r).get(); + Response response = c.executeRequest(r).get(5, TimeUnit.SECONDS); if (500 == response.getStatusCode()) { StringBuilder sb = new StringBuilder(); sb.append("==============\n"); diff --git a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java index 8bce85b03f..80572786b9 100644 --- a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java @@ -47,7 +47,7 @@ public void testMaxTotalConnections() { for (i = 0; i < 3; i++) { try { log.info("{} requesting url [{}]...", i, url); - Response response = client.prepareGet(url).execute().get(); + Response response = client.prepareGet(url).execute().get(5, TimeUnit.SECONDS); log.info("{} response [{}].", i, response); } catch (Exception ex) { exception = ex; @@ -71,7 +71,7 @@ public void testMaxTotalConnectionsException() { log.info("{} requesting url [{}]...", i, url); if (i < 5) { - client.prepareGet(url).execute().get(); + client.prepareGet(url).execute().get(5, TimeUnit.SECONDS); } else { client.prepareGet(url).execute(); } @@ -112,7 +112,7 @@ public Response onCompleted(Response response) throws Exception { } }; - client.prepareGet(getTargetUrl()).execute(handler).get(); + client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); server.stop(); server.start(); client.prepareGet(getTargetUrl()).execute(handler); @@ -215,7 +215,7 @@ public Response onCompleted(Response response) throws Exception { }; try { - client.prepareGet(getTargetUrl()).execute(handler).get(); + client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); fail("Must have received an exception"); } catch (ExecutionException ex) { assertNotNull(ex); diff --git a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java index 044915333d..ca490c6788 100644 --- a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java @@ -127,7 +127,7 @@ public Object onCompleted() throws Exception { public void testPutEmptyBody() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(null); try { - Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get(); + Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 204); diff --git a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java index a1de248e24..9b2fb6e0e7 100644 --- a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java +++ b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -64,7 +65,7 @@ public void Expect100Continue() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setHeader("Expect", "100-continue").setBody(SIMPLE_TEXT_FILE).execute(); - Response resp = f.get(); + Response resp = f.get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index b6a14f2d39..73b1c71974 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; @@ -62,7 +63,7 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle public void testPutImageFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build()); try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -75,7 +76,7 @@ public void testPutLargeTextFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/FilterTest.java b/api/src/test/java/org/asynchttpclient/async/FilterTest.java index 8f4c90725e..843fa417ee 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilterTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilterTest.java @@ -32,6 +32,7 @@ import java.util.Enumeration; import java.util.List; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import static org.testng.Assert.assertEquals; @@ -73,7 +74,7 @@ public void basicTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(); + Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { @@ -94,7 +95,7 @@ public void loadThrottleTest() throws Exception { } for (Future f : futures) { - Response r = f.get(); + Response r = f.get(5, TimeUnit.SECONDS); assertNotNull(f.get()); assertEquals(r.getStatusCode(), 200); } @@ -110,7 +111,7 @@ public void maxConnectionsText() throws Exception { AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - /* Response response = */c.preparePost(getTargetUrl()).execute().get(); + /* Response response = */c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); fail("Should have timed out"); } catch (IOException ex) { assertNotNull(ex); @@ -134,7 +135,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(); + Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -165,7 +166,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(); + Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -197,7 +198,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(); + Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -230,7 +231,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).addHeader("Ping", "Pong").execute().get(); + Response response = c.preparePost(getTargetUrl()).addHeader("Ping", "Pong").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java index 0e2fb055b9..5c7fc5c2ca 100644 --- a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java @@ -20,6 +20,7 @@ import java.util.Enumeration; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HostnameVerifier; @@ -130,7 +131,7 @@ public void positiveHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new PositiveHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { Future f = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute(); - Response resp = f.get(); + Response resp = f.get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -145,7 +146,7 @@ public void negativeHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new NegativeHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -160,7 +161,7 @@ public void remoteIDHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("bouette")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -174,7 +175,7 @@ public void remoteNegHostnameVerifierTest() throws Exception { // request is made to 127.0.0.1, but cert presented for localhost - this should fail final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("localhost")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -188,7 +189,7 @@ public void remotePosHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("127.0.0.1")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); diff --git a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java index e9c6ae6c8d..86bdf98fc0 100644 --- a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Enumeration; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -95,7 +96,7 @@ public void httpToHttpsRedirect() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2()).execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2()).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); @@ -111,13 +112,13 @@ public void httpToHttpsProperConfig() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/test2").execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/test2").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); // Test if the internal channel is downgraded to clean http. - response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/foo2").execute().get(); + response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/foo2").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); @@ -133,7 +134,7 @@ public void relativeLocationUrl() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 302); assertEquals(response.getUri().toString(), getTargetUrl()); diff --git a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java index 3837b799c8..f24030b0ce 100644 --- a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -64,7 +65,7 @@ public void idleStateTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(cg); try { - c.prepareGet(getTargetUrl()).execute().get(); + c.prepareGet(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); } catch (ExecutionException e) { fail("Should allow to finish processing request.", e); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java index a519385473..9d4c86a665 100644 --- a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java +++ b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java @@ -29,6 +29,7 @@ import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import static org.testng.Assert.assertEquals; @@ -96,7 +97,7 @@ public int read() throws IOException { } }; - Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get(); + Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getHeader("X-Param"), "abc"); diff --git a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java index e2765f3a3e..ddcacb02d4 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java @@ -28,6 +28,8 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; public abstract class MaxTotalConnectionTest extends AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); @@ -76,7 +78,8 @@ public void testMaxTotalConnections() { * JFA: Disable this test for 1.2.0 release as it can easily fail because a request may complete before the second one is made, hence failing. The issue occurs frequently on Linux. */ @Test(enabled = false) - public void testMaxTotalConnectionsCorrectExceptionHandling() { + public void testMaxTotalConnectionsCorrectExceptionHandling() + throws TimeoutException { String[] urls = new String[] { "http://google.com/", "http://github.com/" }; AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(1000).setRequestTimeoutInMs(5000).setAllowPoolingConnection(false).setMaximumConnectionsTotal(1).setMaximumConnectionsPerHost(1).build()); @@ -100,7 +103,7 @@ public void testMaxTotalConnectionsCorrectExceptionHandling() { // get results of executed requests for (Future future : futures) { try { - /* Response res = */future.get(); + /* Response res = */future.get(5, TimeUnit.SECONDS); } catch (InterruptedException e) { log.error("Error!", e); } catch (ExecutionException e) { diff --git a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java index d9eb881827..cca751a818 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; +import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; import javax.servlet.ServletException; @@ -181,7 +182,7 @@ public void testSendingSmallFilesAndByteArray() { Request r = builder.build(); - Response res = c.executeRequest(r).get(); + Response res = c.executeRequest(r).get(5, TimeUnit.SECONDS); assertEquals(res.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java index 8d4359b4ea..d3869e6c2c 100644 --- a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java @@ -29,6 +29,7 @@ import java.security.GeneralSecurityException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import java.util.concurrent.TimeUnit; public abstract class NoNullResponseTest extends AbstractBasicTest { private static final String GOOGLE_HTTPS_URL = "https://www.google.com/"; @@ -38,9 +39,9 @@ public void multipleSslRequestsWithDelayAndKeepAlive() throws Exception { final AsyncHttpClient client = create(); try { final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); - final Response response1 = builder.execute().get(); + final Response response1 = builder.execute().get(5, TimeUnit.SECONDS); Thread.sleep(4000); - final Response response2 = builder.execute().get(); + final Response response2 = builder.execute().get(5, TimeUnit.SECONDS); if (response2 != null) { System.out.println("Success (2nd response was not null)."); } else { diff --git a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java index cbfdf6546c..ddd89be55d 100644 --- a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java @@ -18,6 +18,8 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; @@ -75,12 +77,13 @@ public void testNonAsciiContentLength() throws Exception { execute("\u4E00"); // Unicode CJK ideograph for one } - protected void execute(String body) throws IOException, InterruptedException, ExecutionException { + protected void execute(String body) + throws IOException, InterruptedException, ExecutionException, TimeoutException { AsyncHttpClient client = getAsyncHttpClient(null); try { BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(body).setBodyEncoding("UTF-8"); Future f = r.execute(); - Response resp = f.get(); + Response resp = f.get(5, TimeUnit.SECONDS); assertEquals(resp.getStatusCode(), 200); assertEquals(body, resp.getResponseBody("UTF-8")); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java index edc1856ce5..ddb72f9482 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java @@ -23,6 +23,7 @@ import java.net.URI; import java.util.Enumeration; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -90,7 +91,7 @@ public void redirected302Test() throws Exception { isSet.getAndSet(false); AsyncHttpClient c = getAsyncHttpClient(null); try { - Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(); + Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -110,7 +111,7 @@ public void notRedirected302Test() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(false).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(); + Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(false).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 302); @@ -142,7 +143,7 @@ public void redirected302InvalidTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { // If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned. - Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(); + Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 404); @@ -159,7 +160,7 @@ public void relativeLocationUrl() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { - Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get(); + Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 302); assertEquals(response.getUri().toString(), getTargetUrl()); diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java index d1a139f324..8dd51d89dd 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java @@ -113,11 +113,12 @@ public void testRequestTimeout() throws IOException { } @Test(groups = { "standalone", "default_provider" }) - public void testGlobalDefaultPerRequestInfiniteTimeout() throws IOException { + public void testGlobalDefaultPerRequestInfiniteTimeout() + throws IOException, TimeoutException { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100).build()); try { Future responseFuture = client.prepareGet(getTargetUrl()).setRequestTimeoutInMs(-1).execute(); - Response response = responseFuture.get(); + Response response = responseFuture.get(5, TimeUnit.SECONDS); assertNotNull(response); } catch (InterruptedException e) { fail("Interrupted.", e); @@ -149,7 +150,7 @@ public void testGlobalRequestTimeout() throws IOException { } @Test(groups = { "standalone", "default_provider" }) - public void testGlobalIdleTimeout() throws IOException { + public void testGlobalIdleTimeout() throws IOException, TimeoutException { final long times[] = new long[] { -1, -1 }; AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(2000).build()); @@ -172,7 +173,7 @@ public void onThrowable(Throwable t) { super.onThrowable(t); } }); - Response response = responseFuture.get(); + Response response = responseFuture.get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getResponseBody(), MSG + MSG); } catch (InterruptedException e) { diff --git a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java index e6a338cfc0..b4c018e03b 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; @@ -101,7 +102,7 @@ public void onThrowable(Throwable t) { } }); - int statusCode = responseFuture.get(); + int statusCode = responseFuture.get(5, TimeUnit.SECONDS); assertEquals(statusCode, 200); } finally { p.close(); @@ -136,7 +137,7 @@ public void onThrowable(Throwable t) { } }); - int statusCode = responseFuture.get(); + int statusCode = responseFuture.get(5, TimeUnit.SECONDS); assertEquals(statusCode, 200); } finally { p.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java index 5436cb05d8..73cf2dc56b 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java @@ -122,7 +122,7 @@ public void testNonProxyHosts() throws IOException, ExecutionException, TimeoutE try { String target = "http://127.0.0.1:1234/"; - client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1).addNonProxyHost("127.0.0.1")).execute().get(); + client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1).addNonProxyHost("127.0.0.1")).execute().get(5, TimeUnit.SECONDS); assertFalse(true); } catch (Throwable e) { assertNotNull(e.getCause()); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index e9cba6194c..204ebb0f02 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.asynchttpclient.AsyncCompletionHandlerBase; @@ -93,7 +94,7 @@ public Response onCompleted(Response response) throws Exception { return response; } }); - Response r = responseFuture.get(); + Response r = responseFuture.get(5, TimeUnit.SECONDS); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); } finally { @@ -121,7 +122,7 @@ public Response onCompleted(Response response) throws Exception { return response; } }); - Response r = responseFuture.get(); + Response r = responseFuture.get(5, TimeUnit.SECONDS); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); } finally { @@ -138,7 +139,7 @@ public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, .setHeader("Content-Type", "text/html")// .build(); try { - Response r = client.get().get(); + Response r = client.get().get(5, TimeUnit.SECONDS); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index e4f1a68c75..70c21c588c 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -17,6 +17,7 @@ import java.io.File; import java.io.IOException; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -43,7 +44,7 @@ public void testPutLargeFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -57,7 +58,7 @@ public void testPutSmallFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java index 1bc842399a..7312598a60 100644 --- a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java +++ b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java @@ -84,7 +84,8 @@ public void testQueryParameters() throws IOException, ExecutionException, Timeou } @Test(groups = { "standalone", "default_provider" }) - public void testUrlRequestParametersEncoding() throws IOException, ExecutionException, InterruptedException { + public void testUrlRequestParametersEncoding() + throws IOException, ExecutionException, InterruptedException, TimeoutException { String URL = getTargetUrl() + "?q="; String REQUEST_PARAM = "github github \ngithub"; @@ -92,7 +93,7 @@ public void testUrlRequestParametersEncoding() throws IOException, ExecutionExce try { String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, "UTF-8"); LoggerFactory.getLogger(QueryParametersTest.class).info("Executing request [{}] ...", requestUrl2); - Response response = client.prepareGet(requestUrl2).execute().get(); + Response response = client.prepareGet(requestUrl2).execute().get(5, TimeUnit.SECONDS); String s = URLDecoder.decode(response.getHeader("q"), "UTF-8"); assertEquals(s, REQUEST_PARAM); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java index 7cecf24d13..eefbbf8beb 100644 --- a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; @@ -106,7 +107,7 @@ public void rc10kProblem() throws IOException, ExecutionException, TimeoutExcept } i = 0; for (Future fResp : resps) { - Integer resp = fResp.get(); + Integer resp = fResp.get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.intValue(), i++); } diff --git a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java index a27873d108..e0524e9d81 100644 --- a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Date; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -86,7 +87,7 @@ public void testGetRedirectFinalUrl() throws Exception { ListenableFuture response = c.executeRequest(r); Response res = null; - res = response.get(); + res = response.get(3, TimeUnit.SECONDS); assertNotNull(res.getResponseBody()); assertEquals(res.getUri().toString(), BASE_URL + "/overthere"); diff --git a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java index 86c21eaac5..7f0bb6b1eb 100644 --- a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java @@ -23,6 +23,7 @@ import java.net.URI; import java.util.Enumeration; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -89,7 +90,7 @@ public void redirected302Test() throws Exception { AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -110,7 +111,7 @@ public void redirected302InvalidTest() throws Exception { // If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned. try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 404); @@ -131,7 +132,7 @@ public void absolutePathRedirectTest() throws Exception { String redirectTarget = "/bar/test"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); @@ -152,7 +153,7 @@ public void relativePathRedirectTest() throws Exception { String redirectTarget = "bar/test1"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); diff --git a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java index a5025ffb17..1e2b0d96de 100644 --- a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java @@ -136,7 +136,7 @@ public Response onCompleted(Response response) throws Exception { l.countDown(); } } - }).get(); + }).get(5, TimeUnit.SECONDS); if (!l.await(5, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -153,7 +153,7 @@ public void invalidStreamTest2() throws Exception { AsyncHttpClient c = getAsyncHttpClient(config); try { - Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get(); + Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get(5, TimeUnit.SECONDS); if (response != null) { System.out.println(response); } @@ -170,7 +170,7 @@ public void invalidStreamTest2() throws Exception { public void asyncFullBodyProperlyRead() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(); + Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(5, TimeUnit.SECONDS); InputStream stream = r.getResponseBodyAsStream(); // FIXME available is an ESTIMATE!!! @@ -191,7 +191,7 @@ public void testUrlRequestParametersEncoding() throws Exception { try { String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, "UTF-8"); logger.info(String.format("Executing request [%s] ...", requestUrl2)); - Response response = client.prepareGet(requestUrl2).execute().get(); + Response response = client.prepareGet(requestUrl2).execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 301); } finally { client.close(); @@ -207,7 +207,7 @@ public void testUrlRequestParametersEncoding() throws Exception { public void testAHC60() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.meetup.com/stackoverflow/Mountain-View-CA/").execute().get(); + Response response = client.prepareGet("http://www.meetup.com/stackoverflow/Mountain-View-CA/").execute().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -220,7 +220,7 @@ public void stripQueryStringTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(); + Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -235,7 +235,7 @@ public void stripQueryStringNegativeTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setRemoveQueryParamsOnRedirect(false).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(); + Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 301); @@ -254,7 +254,7 @@ public void evilCoookieTest() throws Exception { builder2.addHeader("Content-Type", "text/plain"); builder2.addCookie(new Cookie(".google.com", "evilcookie", "evilcookie", "test", "/", 10, false, 1, false, false, null, null, Collections. emptySet())); Request request2 = builder2.build(); - Response response = c.executeRequest(request2).get(); + Response response = c.executeRequest(request2).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java index 6c27502c6e..4d62240d49 100644 --- a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java @@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.util.concurrent.TimeUnit; import static org.testng.Assert.*; @@ -71,7 +72,7 @@ public AbstractHandler configureHandler() throws Exception { public void testMaxRetry() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build()); try { - ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build()).get(); + ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build()).get(5, TimeUnit.SECONDS); fail(); } catch (Exception t) { assertNotNull(t.getCause()); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java index 76dac21427..f8e697d431 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java @@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -46,7 +47,7 @@ public void testAccumulateErrorBody() throws Exception { Future future = client.get(new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 404); assertEquals(o.toString(), ""); assertTrue(response.getResponseBody().startsWith("")); @@ -63,7 +64,7 @@ public void testOmitErrorBody() throws Exception { Future future = client.get(new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 404); assertEquals(o.toString(), ""); assertEquals(response.getResponseBody(), ""); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index ef0dfacf51..5ab0e349e9 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import org.asynchttpclient.ByteArrayPart; import org.asynchttpclient.Response; @@ -45,7 +46,7 @@ public void inpuStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes()))); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBody(), MY_MESSAGE); } finally { @@ -62,7 +63,7 @@ public void stringBuilderBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); } finally { @@ -79,7 +80,7 @@ public void byteArrayOutputStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -96,7 +97,7 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -118,7 +119,7 @@ public void testPutZeroBytesFileTest() throws Exception { Future future = client.put(new FileBodyGenerator(tmpfile)); System.out.println("waiting for response"); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); tmpfile.delete(); @@ -152,7 +153,7 @@ public void testDeriveOverrideURL() throws Exception { try { Future future = derived.post(generator, consumer); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -203,7 +204,7 @@ public void onBytesReceived(String url, long amount, long current, long total) { Future future = client.post(generator, consumer); - Response response = future.get(); + Response response = future.get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -229,11 +230,11 @@ public void testCloseDerivedValidMaster() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); SimpleAsyncHttpClient derived = client.derive().build(); try { - derived.get().get(); + derived.get().get(5, TimeUnit.SECONDS); derived.close(); - Response response = client.get().get(); + Response response = client.get().get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 200); } finally { @@ -249,7 +250,7 @@ public void testCloseMasterInvalidDerived() throws Exception { client.close(); try { - derived.get().get(); + derived.get().get(5, TimeUnit.SECONDS); fail("Expected closed AHC"); } catch (IOException e) { // expected @@ -260,7 +261,7 @@ public void testCloseMasterInvalidDerived() throws Exception { public void testMultiPartPut() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { - Response response = client.put(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); + Response response = client.put(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(5, TimeUnit.SECONDS); String body = response.getResponseBody(); String contentType = response.getHeader("X-Content-Type"); @@ -284,7 +285,7 @@ public void testMultiPartPut() throws Exception { public void testMultiPartPost() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { - Response response = client.post(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); + Response response = client.post(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(5, TimeUnit.SECONDS); String body = response.getResponseBody(); String contentType = response.getHeader("X-Content-Type"); diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 38e0e402b9..15b63b2b58 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.util.Enumeration; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -114,7 +115,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = c.prepareGet(getTargetUrl()).execute(tl).get(); + Response response = c.prepareGet(getTargetUrl()).execute(tl).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -175,7 +176,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute(tl).get(); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute(tl).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -234,7 +235,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = client.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(file)).execute(tl).get(); + Response response = client.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(file)).execute(tl).get(5, TimeUnit.SECONDS); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index 8959d7a8bc..dc03ca2afe 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -18,6 +18,8 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -90,19 +92,20 @@ public void clean() throws InterruptedException, Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { Request deleteRequest = new RequestBuilder("DELETE").setUrl(getTargetUrl()).build(); - c.executeRequest(deleteRequest).get(); + c.executeRequest(deleteRequest).get(5, TimeUnit.SECONDS); } finally { c.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void mkcolWebDavTest1() throws InterruptedException, IOException, ExecutionException { + public void mkcolWebDavTest1() + throws InterruptedException, IOException, ExecutionException, TimeoutException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(); + Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 201); } finally { @@ -111,12 +114,13 @@ public void mkcolWebDavTest1() throws InterruptedException, IOException, Executi } @Test(groups = { "standalone", "default_provider" }) - public void mkcolWebDavTest2() throws InterruptedException, IOException, ExecutionException { + public void mkcolWebDavTest2() + throws InterruptedException, IOException, ExecutionException, TimeoutException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl() + "/folder2").build(); - Response response = c.executeRequest(mkcolRequest).get(); + Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 409); } finally { c.close(); @@ -124,12 +128,13 @@ public void mkcolWebDavTest2() throws InterruptedException, IOException, Executi } @Test(groups = { "standalone", "default_provider" }) - public void basicPropFindWebDavTest() throws InterruptedException, IOException, ExecutionException { + public void basicPropFindWebDavTest() + throws InterruptedException, IOException, ExecutionException, TimeoutException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(propFindRequest).get(); + Response response = c.executeRequest(propFindRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 404); } finally { @@ -138,20 +143,21 @@ public void basicPropFindWebDavTest() throws InterruptedException, IOException, } @Test(groups = { "standalone", "default_provider" }) - public void propFindWebDavTest() throws InterruptedException, IOException, ExecutionException { + public void propFindWebDavTest() + throws InterruptedException, IOException, ExecutionException, TimeoutException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(); + Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 201); Request putRequest = new RequestBuilder("PUT").setUrl(String.format("http://127.0.0.1:%s/folder1/Test.txt", port1)).setBody("this is a test").build(); - response = c.executeRequest(putRequest).get(); + response = c.executeRequest(putRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 201); Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(String.format("http://127.0.0.1:%s/folder1/Test.txt", port1)).build(); - response = c.executeRequest(propFindRequest).get(); + response = c.executeRequest(propFindRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 207); assertTrue(response.getResponseBody().contains("HTTP/1.1 200 OK")); @@ -161,12 +167,13 @@ public void propFindWebDavTest() throws InterruptedException, IOException, Execu } @Test(groups = { "standalone", "default_provider" }) - public void propFindCompletionHandlerWebDavTest() throws InterruptedException, IOException, ExecutionException { + public void propFindCompletionHandlerWebDavTest() + throws InterruptedException, IOException, ExecutionException, TimeoutException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(); + Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); assertEquals(response.getStatusCode(), 201); Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build(); @@ -184,7 +191,7 @@ public void onThrowable(Throwable t) { public WebDavResponse onCompleted(WebDavResponse response) throws Exception { return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(webDavResponse); assertEquals(webDavResponse.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java index 490931ce8c..f2ba675ead 100644 --- a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java @@ -21,6 +21,7 @@ import java.net.URISyntaxException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; @@ -85,7 +86,7 @@ public STATE onContentWriteCompleted() { public Response onCompleted(Response response) throws Exception { return response; } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -101,7 +102,7 @@ public void zeroCopyPutTest() throws IOException, ExecutionException, TimeoutExc AsyncHttpClient client = getAsyncHttpClient(null); try { Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(); - Response resp = f.get(); + Response resp = f.get(5, TimeUnit.SECONDS); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -142,7 +143,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(resp); assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { @@ -184,7 +185,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }).get(); + }).get(5, TimeUnit.SECONDS); assertNull(resp); assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { diff --git a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java index 5a362fd53a..9788631eba 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java @@ -15,6 +15,7 @@ import static org.testng.Assert.assertEquals; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -67,7 +68,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.sendMessage("ECHO".getBytes()); @@ -118,7 +119,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.sendMessage("ECHO".getBytes()).sendMessage("ECHO".getBytes()); @@ -170,7 +171,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); latch.await(); assertEquals(text.get(), "ECHOECHO".getBytes()); @@ -218,7 +219,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.stream("ECHO".getBytes(), false); websocket.stream("ECHO".getBytes(), true); latch.await(); diff --git a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java index 12fa531e6f..f4dcf1bae5 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java @@ -15,6 +15,7 @@ import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -41,7 +42,7 @@ public void onCloseWithCode() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(); + WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(5, TimeUnit.SECONDS); websocket.close(); @@ -59,7 +60,7 @@ public void onCloseWithCodeServerClose() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(); + c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(5, TimeUnit.SECONDS); latch.await(); assertEquals(text.get(), "1001-Idle Timeout"); diff --git a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java index 92e08e10a2..74f2b359cf 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.servlet.ServletException; @@ -79,26 +80,28 @@ public void testRedirectToWSResource() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - WebSocket websocket = c.prepareGet(getRedirectURL()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { + WebSocket websocket = c.prepareGet(getRedirectURL()).execute( + new WebSocketUpgradeHandler.Builder().addWebSocketListener( + new WebSocketListener() { - @Override - public void onOpen(WebSocket websocket) { - text.set("OnOpen"); - latch.countDown(); - } + @Override + public void onOpen(WebSocket websocket) { + text.set("OnOpen"); + latch.countDown(); + } - @Override - public void onClose(WebSocket websocket) { - } + @Override + public void onClose(WebSocket websocket) { + } - @Override - public void onError(Throwable t) { - t.printStackTrace(); - latch.countDown(); - } - }).build()).get(); + @Override + public void onError(Throwable t) { + t.printStackTrace(); + latch.countDown(); + } + }).build()).get(5, TimeUnit.SECONDS); - latch.await(); + latch.await(5, TimeUnit.SECONDS); assertEquals(text.get(), "OnOpen"); websocket.close(); } finally { diff --git a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java index a63c0a15eb..adc670585e 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java @@ -15,6 +15,7 @@ import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -58,7 +59,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); latch.await(); assertEquals(text.get(), "OnOpen"); @@ -73,7 +74,7 @@ public void onEmptyListenerTest() throws Exception { try { WebSocket websocket = null; try { - websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().build()).get(); + websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().build()).get(5, TimeUnit.SECONDS); } catch (Throwable t) { fail(); } @@ -89,7 +90,7 @@ public void onFailureTest() throws Exception { try { Throwable t = null; try { - /* WebSocket websocket = */c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get(); + /* WebSocket websocket = */c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get(5, TimeUnit.SECONDS); } catch (Throwable t2) { t = t2; } @@ -123,7 +124,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); latch.await(); assertEquals(text.get(), "OnClose"); @@ -156,7 +157,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.close(); @@ -200,7 +201,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.sendTextMessage("ECHO"); @@ -270,7 +271,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.sendTextMessage("ECHO"); @@ -315,7 +316,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); latch.await(); assertEquals(text.get(), "ECHOECHO"); @@ -356,7 +357,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(); + }).build()).get(5, TimeUnit.SECONDS); websocket.streamText("ECHO", false); websocket.streamText("ECHO", true); From e9f0b877401e3366df2a60278a1a76b84b5a1bd4 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 25 Sep 2013 19:19:05 -0700 Subject: [PATCH 0135/2389] Reverting. --- .../async/AsyncProvidersBasicTest.java | 86 +++++++++---------- .../async/AsyncStreamHandlerTest.java | 2 +- .../async/AuthTimeoutTest.java | 8 +- .../asynchttpclient/async/BasicAuthTest.java | 2 +- .../asynchttpclient/async/BasicHttpsTest.java | 4 +- .../asynchttpclient/async/BodyChunkTest.java | 3 +- .../async/BodyDeferringAsyncHandlerTest.java | 5 +- .../async/ByteBufferCapacityTest.java | 3 +- .../asynchttpclient/async/ChunkingTest.java | 3 +- .../async/ConnectionPoolTest.java | 8 +- .../asynchttpclient/async/EmptyBodyTest.java | 2 +- .../async/Expect100ContinueTest.java | 3 +- .../async/FilePartLargeFileTest.java | 5 +- .../org/asynchttpclient/async/FilterTest.java | 15 ++-- .../async/HostnameVerifierTest.java | 11 ++- .../async/HttpToHttpsRedirectTest.java | 9 +- .../async/IdleStateHandlerTest.java | 3 +- .../async/InputStreamTest.java | 3 +- .../async/MaxTotalConnectionTest.java | 7 +- .../async/MultipartUploadTest.java | 3 +- .../async/NoNullResponseTest.java | 5 +- .../async/NonAsciiContentLengthTest.java | 7 +- .../async/PerRequestRelative302Test.java | 9 +- .../async/PerRequestTimeoutTest.java | 9 +- .../async/PostRedirectGetTest.java | 5 +- .../org/asynchttpclient/async/ProxyTest.java | 2 +- .../async/ProxyTunnellingTest.java | 7 +- .../async/PutLargeFileTest.java | 5 +- .../async/QueryParametersTest.java | 5 +- .../org/asynchttpclient/async/RC10KTest.java | 3 +- .../async/RedirectConnectionUsageTest.java | 3 +- .../async/Relative302Test.java | 9 +- .../asynchttpclient/async/RemoteSiteTest.java | 16 ++-- .../async/RetryRequestTest.java | 3 +- .../SimpleAsyncClientErrorBehaviourTest.java | 5 +- .../async/SimpleAsyncHttpClientTest.java | 25 +++--- .../async/TransferListenerTest.java | 7 +- .../async/WebDavBasicTest.java | 35 +++----- .../async/ZeroCopyFileTest.java | 9 +- .../websocket/ByteMessageTest.java | 9 +- .../websocket/CloseCodeReasonMessageTest.java | 5 +- .../websocket/RedirectTest.java | 35 ++++---- .../websocket/TextMessageTest.java | 19 ++-- 43 files changed, 188 insertions(+), 234 deletions(-) diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 974f264e3f..0472ef6ba6 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -78,7 +78,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertEquals(url, getTargetUrl() + "?q=%20%20x"); } finally { client.close(); @@ -103,7 +103,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertEquals(url, getTargetUrl() + "?q=a%20b"); } finally { client.close(); @@ -128,7 +128,7 @@ public void onThrowable(Throwable t) { fail("Unexpected exception: " + t.getMessage(), t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertEquals(url, getTargetUrl()); } finally { client.close(); @@ -172,7 +172,7 @@ public void onThrowable(Throwable t) { } } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -200,7 +200,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -227,7 +227,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -264,7 +264,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -301,7 +301,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -328,7 +328,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); try { String s = response.getResponseBody(); @@ -370,7 +370,7 @@ public void onThrowable(Throwable t) { } } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(10 * 5 * 1000, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -412,7 +412,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -447,7 +447,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -483,7 +483,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -511,7 +511,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -525,7 +525,7 @@ public Response onCompleted(Response response) throws Exception { public void asyncDoPostBodyIsoTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePost(getTargetUrl()).addHeader("X-ISO", "true").setBody("\u017D\u017D\u017D\u017D\u017D\u017D").execute().get(); assertEquals(response.getResponseBody().getBytes("ISO-8859-1"), "\u017D\u017D\u017D\u017D\u017D\u017D".getBytes("ISO-8859-1")); } finally { client.close(); @@ -561,7 +561,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -601,7 +601,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -638,7 +638,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -670,7 +670,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -704,7 +704,7 @@ public Response onCompleted(Response response) throws Exception { } return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timeout out"); } @@ -734,7 +734,7 @@ public Response onCompleted(Response response) throws Exception { @Override public void onThrowable(Throwable t) { } - }).get(5, TimeUnit.SECONDS); + }).get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-Proxy-Connection"), "keep-alive"); @@ -756,7 +756,7 @@ public void asyncRequestVirtualServerPOSTTest() throws Exception { } Request request = new RequestBuilder("POST").setUrl(getTargetUrl()).setHeaders(h).setParameters(m).setVirtualHost("localhost:" + port1).build(); - Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(5, TimeUnit.SECONDS); + Response response = client.executeRequest(request, new AsyncCompletionHandlerAdapter()).get(); assertEquals(response.getStatusCode(), 200); if (response.getHeader("X-Host").startsWith("localhost")) { @@ -781,7 +781,7 @@ public void asyncDoPutTest() throws Exception { } sb.setLength(sb.length() - 1); - Response response = client.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()).get(); assertEquals(response.getStatusCode(), 200); } finally { @@ -897,7 +897,7 @@ public void asyncDoPostNullBytesTest() throws Exception { Future future = client.preparePost(getTargetUrl()).setHeaders(h).setBody(sb.toString()).execute(new AsyncCompletionHandlerAdapter()); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { @@ -952,7 +952,7 @@ public void asyncConnectInvalidFuture() throws Exception { public void onThrowable(Throwable t) { count.incrementAndGet(); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(response, "Should have thrown ExecutionException"); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); @@ -978,7 +978,7 @@ public void asyncConnectInvalidPortFuture() throws Exception { public void onThrowable(Throwable t) { t.printStackTrace(); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(response, "Should have thrown ExecutionException"); } catch (ExecutionException ex) { Throwable cause = ex.getCause(); @@ -1004,7 +1004,7 @@ public void asyncConnectInvalidPort() throws Exception { public void onThrowable(Throwable t) { t.printStackTrace(); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(response, "No ExecutionException was thrown"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -1085,7 +1085,7 @@ public void onThrowable(Throwable t) { rightCause.set(true); } } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(response, "No ExecutionException was thrown"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -1107,7 +1107,7 @@ public void asyncContentLenghtGETTest() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -1126,7 +1126,7 @@ public void asyncResponseBodyTooLarge() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(response.getResponseBodyExcerpt(Integer.MAX_VALUE)); } finally { @@ -1144,7 +1144,7 @@ public void asyncResponseEmptyBody() throws Exception { public void onThrowable(Throwable t) { fail("Unexpected exception", t); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertEquals(response.getResponseBody(), ""); } finally { @@ -1284,7 +1284,7 @@ public Response onCompleted(Response response) throws Exception { Request req = new RequestBuilder("GET").setUrl(getTargetUrl() + "?foo=bar").build(); - client.executeRequest(req, handler).get(5, TimeUnit.SECONDS); + client.executeRequest(req, handler).get(); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { fail("Timed out"); @@ -1321,7 +1321,7 @@ public Response onCompleted(Response response) throws Exception { } }; - client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); + client.prepareGet(getTargetUrl()).execute(handler).get(); client.prepareGet(getTargetUrl()).execute(handler); if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { @@ -1415,7 +1415,7 @@ public void onThrowable(Throwable t) { public void asyncDoGetStreamAndBodyTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1426,7 +1426,7 @@ public void asyncDoGetStreamAndBodyTest() throws Exception { public void asyncUrlWithoutPathTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet("http://www.lemonde.fr/").execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -1437,7 +1437,7 @@ public void asyncUrlWithoutPathTest() throws Exception { public void optionsTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareOptions(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareOptions(getTargetUrl()).execute().get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("Allow"), "GET,HEAD,POST,OPTIONS,TRACE"); @@ -1450,7 +1450,7 @@ public void optionsTest() throws Exception { public void testAwsS3() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { @@ -1466,7 +1466,7 @@ public void testAsyncHttpProviderConfig() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setAsyncHttpClientProviderConfig(getProviderConfig()).build()); try { - Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet("http://test.s3.amazonaws.com/").execute().get(); if (response.getResponseBody() == null || response.getResponseBody().equals("")) { fail("No response Body"); } else { @@ -1487,7 +1487,7 @@ public void idleRequestTimeoutTest() throws Exception { long t1 = millisTime(); try { - client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(10, TimeUnit.SECONDS); + client.prepareGet(getTargetUrl()).setHeaders(h).setUrl(getTargetUrl()).execute().get(); fail(); } catch (Throwable ex) { final long elapsedTime = millisTime() - t1; @@ -1560,7 +1560,7 @@ public void headShouldNotAllowBody() throws IllegalArgumentException, IOExceptio public void invalidUri() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(5, TimeUnit.SECONDS); + Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(); assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -1571,7 +1571,7 @@ public void invalidUri() throws Exception { public void asyncHttpClientConfigBeanTest() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfigBean().setUserAgent("test")); try { - Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(5, TimeUnit.SECONDS); + Response response = client.executeRequest(client.prepareGet(getTargetUrl()).build()).get(); assertEquals(200, response.getStatusCode()); } finally { client.close(); @@ -1582,7 +1582,7 @@ public void asyncHttpClientConfigBeanTest() throws Exception { public void bodyAsByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet(getTargetUrl()).execute().get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBodyAsBytes(), new byte[] {}); } finally { @@ -1594,7 +1594,7 @@ public void bodyAsByteTest() throws Exception { public void mirrorByteTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePost(getTargetUrl()).setBody("MIRROR").execute().get(); assertEquals(response.getStatusCode(), 200); assertEquals(new String(response.getResponseBodyAsBytes(), "UTF-8"), "MIRROR"); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index d78692f9df..1d31d21ac7 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -560,7 +560,7 @@ public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio public Response onCompleted() throws Exception { return builder.build(); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(r); assertEquals(r.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java index dd97e21dfa..962e996cd2 100644 --- a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java @@ -85,7 +85,7 @@ public void basicAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server, false); - f.get(5, TimeUnit.SECONDS); + f.get(); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -99,7 +99,7 @@ public void basicPreemptiveAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server, true); - f.get(5, TimeUnit.SECONDS); + f.get(); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -113,7 +113,7 @@ public void digestAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server2, false); - f.get(5, TimeUnit.SECONDS); + f.get(); fail("expected timeout"); } catch (Exception e) { inspectException(e); @@ -127,7 +127,7 @@ public void digestPreemptiveAuthTimeoutTest() throws Exception { AsyncHttpClient client = newClient(); try { Future f = execute(client, server2, true); - f.get(5, TimeUnit.SECONDS); + f.get(); fail("expected timeout"); } catch (Exception e) { inspectException(e); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java index ac23977eaf..0fecd118d7 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicAuthTest.java @@ -351,7 +351,7 @@ public void stringBuilderBodyConsumerTest() throws Exception { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); - Response response = future.get(3, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); assertEquals(response.getStatusCode(), HttpServletResponse.SC_OK); diff --git a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java index bd24dce5e3..1efde2f983 100644 --- a/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BasicHttpsTest.java @@ -42,7 +42,7 @@ public void zeroCopyPostTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -80,7 +80,7 @@ public void multipleSSLWithoutCacheTest() throws Exception { c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute(); - Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(); assertEquals(response.getResponseBody(), body); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java index 1993f43e43..e6d19b6401 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyChunkTest.java @@ -24,7 +24,6 @@ import java.io.ByteArrayInputStream; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import static org.testng.Assert.assertEquals; @@ -51,7 +50,7 @@ public void negativeContentTypeTest() throws Exception { Future future = client.executeRequest(requestBuilder.build()); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBody(), MY_MESSAGE); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java index 43efb9c44f..09e16e9763 100644 --- a/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/BodyDeferringAsyncHandlerTest.java @@ -22,7 +22,6 @@ import java.io.PipedOutputStream; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import javax.servlet.ServletException; @@ -127,7 +126,7 @@ public void deferredSimple() throws IOException, ExecutionException, TimeoutExce // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) - f.get(5, TimeUnit.SECONDS); + f.get(); // it all should be here now assertEquals(cos.getByteCount(), HALF_GIG); } finally { @@ -156,7 +155,7 @@ public void deferredSimpleWithFailure() throws IOException, ExecutionException, // now be polite and wait for body arrival too (otherwise we would be // dropping the "line" on server) try { - f.get(5, TimeUnit.SECONDS); + f.get(); fail("get() should fail with IOException!"); } catch (Exception e) { // good diff --git a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java index 75165ae503..47c453e886 100644 --- a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java @@ -20,7 +20,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Enumeration; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; @@ -87,7 +86,7 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep return super.onBodyPartReceived(content); } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java index 10a0b3cf26..66e9ef3692 100644 --- a/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ChunkingTest.java @@ -18,7 +18,6 @@ import java.io.BufferedInputStream; import java.io.FileInputStream; -import java.util.concurrent.TimeUnit; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -61,7 +60,7 @@ public void testCustomChunking() throws Exception { Request r = builder.build(); - Response response = c.executeRequest(r).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(r).get(); if (500 == response.getStatusCode()) { StringBuilder sb = new StringBuilder(); sb.append("==============\n"); diff --git a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java index 80572786b9..8bce85b03f 100644 --- a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java @@ -47,7 +47,7 @@ public void testMaxTotalConnections() { for (i = 0; i < 3; i++) { try { log.info("{} requesting url [{}]...", i, url); - Response response = client.prepareGet(url).execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet(url).execute().get(); log.info("{} response [{}].", i, response); } catch (Exception ex) { exception = ex; @@ -71,7 +71,7 @@ public void testMaxTotalConnectionsException() { log.info("{} requesting url [{}]...", i, url); if (i < 5) { - client.prepareGet(url).execute().get(5, TimeUnit.SECONDS); + client.prepareGet(url).execute().get(); } else { client.prepareGet(url).execute(); } @@ -112,7 +112,7 @@ public Response onCompleted(Response response) throws Exception { } }; - client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); + client.prepareGet(getTargetUrl()).execute(handler).get(); server.stop(); server.start(); client.prepareGet(getTargetUrl()).execute(handler); @@ -215,7 +215,7 @@ public Response onCompleted(Response response) throws Exception { }; try { - client.prepareGet(getTargetUrl()).execute(handler).get(5, TimeUnit.SECONDS); + client.prepareGet(getTargetUrl()).execute(handler).get(); fail("Must have received an exception"); } catch (ExecutionException ex) { assertNotNull(ex); diff --git a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java index ca490c6788..044915333d 100644 --- a/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/EmptyBodyTest.java @@ -127,7 +127,7 @@ public Object onCompleted() throws Exception { public void testPutEmptyBody() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(null); try { - Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get(5, TimeUnit.SECONDS); + Response response = ahc.preparePut(getTargetUrl()).setBody("String").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 204); diff --git a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java index 9b2fb6e0e7..a1de248e24 100644 --- a/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java +++ b/api/src/test/java/org/asynchttpclient/async/Expect100ContinueTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -65,7 +64,7 @@ public void Expect100Continue() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setHeader("Expect", "100-continue").setBody(SIMPLE_TEXT_FILE).execute(); - Response resp = f.get(5, TimeUnit.SECONDS); + Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); diff --git a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java index 73b1c71974..b6a14f2d39 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilePartLargeFileTest.java @@ -17,7 +17,6 @@ import java.io.File; import java.io.IOException; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; @@ -63,7 +62,7 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle public void testPutImageFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build()); try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -76,7 +75,7 @@ public void testPutLargeTextFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/FilterTest.java b/api/src/test/java/org/asynchttpclient/async/FilterTest.java index 843fa417ee..8f4c90725e 100644 --- a/api/src/test/java/org/asynchttpclient/async/FilterTest.java +++ b/api/src/test/java/org/asynchttpclient/async/FilterTest.java @@ -32,7 +32,6 @@ import java.util.Enumeration; import java.util.List; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import static org.testng.Assert.assertEquals; @@ -74,7 +73,7 @@ public void basicTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); } finally { @@ -95,7 +94,7 @@ public void loadThrottleTest() throws Exception { } for (Future f : futures) { - Response r = f.get(5, TimeUnit.SECONDS); + Response r = f.get(); assertNotNull(f.get()); assertEquals(r.getStatusCode(), 200); } @@ -111,7 +110,7 @@ public void maxConnectionsText() throws Exception { AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - /* Response response = */c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + /* Response response = */c.preparePost(getTargetUrl()).execute().get(); fail("Should have timed out"); } catch (IOException ex) { assertNotNull(ex); @@ -135,7 +134,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -166,7 +165,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -198,7 +197,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -231,7 +230,7 @@ public FilterContext filter(FilterContext ctx) throws FilterException AsyncHttpClient c = getAsyncHttpClient(b.build()); try { - Response response = c.preparePost(getTargetUrl()).addHeader("Ping", "Pong").execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).addHeader("Ping", "Pong").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java index 5c7fc5c2ca..0e2fb055b9 100644 --- a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java @@ -20,7 +20,6 @@ import java.util.Enumeration; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.net.ssl.HostnameVerifier; @@ -131,7 +130,7 @@ public void positiveHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new PositiveHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { Future f = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute(); - Response resp = f.get(5, TimeUnit.SECONDS); + Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -146,7 +145,7 @@ public void negativeHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new NegativeHostVerifier()).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -161,7 +160,7 @@ public void remoteIDHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("bouette")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -175,7 +174,7 @@ public void remoteNegHostnameVerifierTest() throws Exception { // request is made to 127.0.0.1, but cert presented for localhost - this should fail final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("localhost")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); fail("ConnectException expected"); } catch (ExecutionException ex) { assertEquals(ex.getCause().getClass(), ConnectException.class); @@ -189,7 +188,7 @@ public void remotePosHostnameVerifierTest() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(new Builder().setHostnameVerifier(new CheckHost("127.0.0.1")).setSSLContext(createSSLContext(new AtomicBoolean(true))).build()); try { - Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(5, TimeUnit.SECONDS); + Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); diff --git a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java index 86bdf98fc0..e9c6ae6c8d 100644 --- a/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HttpToHttpsRedirectTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.Enumeration; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -96,7 +95,7 @@ public void httpToHttpsRedirect() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2()).execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2()).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); @@ -112,13 +111,13 @@ public void httpToHttpsProperConfig() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/test2").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/test2").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); // Test if the internal channel is downgraded to clean http. - response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/foo2").execute().get(5, TimeUnit.SECONDS); + response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", getTargetUrl2() + "/foo2").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getHeader("X-httpToHttps"), "PASS"); @@ -134,7 +133,7 @@ public void relativeLocationUrl() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setMaximumNumberOfRedirects(5).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 302); assertEquals(response.getUri().toString(), getTargetUrl()); diff --git a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java index f24030b0ce..3837b799c8 100644 --- a/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/IdleStateHandlerTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -65,7 +64,7 @@ public void idleStateTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(cg); try { - c.prepareGet(getTargetUrl()).execute().get(5, TimeUnit.SECONDS); + c.prepareGet(getTargetUrl()).execute().get(); } catch (ExecutionException e) { fail("Should allow to finish processing request.", e); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java index 9d4c86a665..a519385473 100644 --- a/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java +++ b/api/src/test/java/org/asynchttpclient/async/InputStreamTest.java @@ -29,7 +29,6 @@ import java.io.InputStream; import java.io.ByteArrayOutputStream; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import static org.testng.Assert.assertEquals; @@ -97,7 +96,7 @@ public int read() throws IOException { } }; - Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get(5, TimeUnit.SECONDS); + Response resp = c.preparePost(getTargetUrl()).setHeaders(h).setBody(is).execute().get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getHeader("X-Param"), "abc"); diff --git a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java index ddcacb02d4..e2765f3a3e 100644 --- a/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MaxTotalConnectionTest.java @@ -28,8 +28,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; public abstract class MaxTotalConnectionTest extends AbstractBasicTest { protected final Logger log = LoggerFactory.getLogger(AbstractBasicTest.class); @@ -78,8 +76,7 @@ public void testMaxTotalConnections() { * JFA: Disable this test for 1.2.0 release as it can easily fail because a request may complete before the second one is made, hence failing. The issue occurs frequently on Linux. */ @Test(enabled = false) - public void testMaxTotalConnectionsCorrectExceptionHandling() - throws TimeoutException { + public void testMaxTotalConnectionsCorrectExceptionHandling() { String[] urls = new String[] { "http://google.com/", "http://github.com/" }; AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(1000).setRequestTimeoutInMs(5000).setAllowPoolingConnection(false).setMaximumConnectionsTotal(1).setMaximumConnectionsPerHost(1).build()); @@ -103,7 +100,7 @@ public void testMaxTotalConnectionsCorrectExceptionHandling() // get results of executed requests for (Future future : futures) { try { - /* Response res = */future.get(5, TimeUnit.SECONDS); + /* Response res = */future.get(); } catch (InterruptedException e) { log.error("Error!", e); } catch (ExecutionException e) { diff --git a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java index cca751a818..d9eb881827 100644 --- a/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java +++ b/api/src/test/java/org/asynchttpclient/async/MultipartUploadTest.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.List; import java.util.UUID; -import java.util.concurrent.TimeUnit; import java.util.zip.GZIPInputStream; import javax.servlet.ServletException; @@ -182,7 +181,7 @@ public void testSendingSmallFilesAndByteArray() { Request r = builder.build(); - Response res = c.executeRequest(r).get(5, TimeUnit.SECONDS); + Response res = c.executeRequest(r).get(); assertEquals(res.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java index d3869e6c2c..8d4359b4ea 100644 --- a/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NoNullResponseTest.java @@ -29,7 +29,6 @@ import java.security.GeneralSecurityException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; -import java.util.concurrent.TimeUnit; public abstract class NoNullResponseTest extends AbstractBasicTest { private static final String GOOGLE_HTTPS_URL = "https://www.google.com/"; @@ -39,9 +38,9 @@ public void multipleSslRequestsWithDelayAndKeepAlive() throws Exception { final AsyncHttpClient client = create(); try { final BoundRequestBuilder builder = client.prepareGet(GOOGLE_HTTPS_URL); - final Response response1 = builder.execute().get(5, TimeUnit.SECONDS); + final Response response1 = builder.execute().get(); Thread.sleep(4000); - final Response response2 = builder.execute().get(5, TimeUnit.SECONDS); + final Response response2 = builder.execute().get(); if (response2 != null) { System.out.println("Success (2nd response was not null)."); } else { diff --git a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java index ddd89be55d..cbfdf6546c 100644 --- a/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java +++ b/api/src/test/java/org/asynchttpclient/async/NonAsciiContentLengthTest.java @@ -18,8 +18,6 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import javax.servlet.ServletException; import javax.servlet.ServletInputStream; @@ -77,13 +75,12 @@ public void testNonAsciiContentLength() throws Exception { execute("\u4E00"); // Unicode CJK ideograph for one } - protected void execute(String body) - throws IOException, InterruptedException, ExecutionException, TimeoutException { + protected void execute(String body) throws IOException, InterruptedException, ExecutionException { AsyncHttpClient client = getAsyncHttpClient(null); try { BoundRequestBuilder r = client.preparePost(getTargetUrl()).setBody(body).setBodyEncoding("UTF-8"); Future f = r.execute(); - Response resp = f.get(5, TimeUnit.SECONDS); + Response resp = f.get(); assertEquals(resp.getStatusCode(), 200); assertEquals(body, resp.getResponseBody("UTF-8")); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java index ddb72f9482..edc1856ce5 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestRelative302Test.java @@ -23,7 +23,6 @@ import java.net.URI; import java.util.Enumeration; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -91,7 +90,7 @@ public void redirected302Test() throws Exception { isSet.getAndSet(false); AsyncHttpClient c = getAsyncHttpClient(null); try { - Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -111,7 +110,7 @@ public void notRedirected302Test() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(false).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setFollowRedirects(false).setHeader("X-redirect", "http://www.microsoft.com/").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 302); @@ -143,7 +142,7 @@ public void redirected302InvalidTest() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { // If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned. - Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 404); @@ -160,7 +159,7 @@ public void relativeLocationUrl() throws Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { - Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get(5, TimeUnit.SECONDS); + Response response = c.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 302); assertEquals(response.getUri().toString(), getTargetUrl()); diff --git a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java index 8dd51d89dd..d1a139f324 100644 --- a/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PerRequestTimeoutTest.java @@ -113,12 +113,11 @@ public void testRequestTimeout() throws IOException { } @Test(groups = { "standalone", "default_provider" }) - public void testGlobalDefaultPerRequestInfiniteTimeout() - throws IOException, TimeoutException { + public void testGlobalDefaultPerRequestInfiniteTimeout() throws IOException { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100).build()); try { Future responseFuture = client.prepareGet(getTargetUrl()).setRequestTimeoutInMs(-1).execute(); - Response response = responseFuture.get(5, TimeUnit.SECONDS); + Response response = responseFuture.get(); assertNotNull(response); } catch (InterruptedException e) { fail("Interrupted.", e); @@ -150,7 +149,7 @@ public void testGlobalRequestTimeout() throws IOException { } @Test(groups = { "standalone", "default_provider" }) - public void testGlobalIdleTimeout() throws IOException, TimeoutException { + public void testGlobalIdleTimeout() throws IOException { final long times[] = new long[] { -1, -1 }; AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setIdleConnectionInPoolTimeoutInMs(2000).build()); @@ -173,7 +172,7 @@ public void onThrowable(Throwable t) { super.onThrowable(t); } }); - Response response = responseFuture.get(5, TimeUnit.SECONDS); + Response response = responseFuture.get(); assertNotNull(response); assertEquals(response.getResponseBody(), MSG + MSG); } catch (InterruptedException e) { diff --git a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java index b4c018e03b..e6a338cfc0 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import javax.servlet.ServletException; @@ -102,7 +101,7 @@ public void onThrowable(Throwable t) { } }); - int statusCode = responseFuture.get(5, TimeUnit.SECONDS); + int statusCode = responseFuture.get(); assertEquals(statusCode, 200); } finally { p.close(); @@ -137,7 +136,7 @@ public void onThrowable(Throwable t) { } }); - int statusCode = responseFuture.get(5, TimeUnit.SECONDS); + int statusCode = responseFuture.get(); assertEquals(statusCode, 200); } finally { p.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java index 73cf2dc56b..5436cb05d8 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTest.java @@ -122,7 +122,7 @@ public void testNonProxyHosts() throws IOException, ExecutionException, TimeoutE try { String target = "http://127.0.0.1:1234/"; - client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1).addNonProxyHost("127.0.0.1")).execute().get(5, TimeUnit.SECONDS); + client.prepareGet(target).setProxyServer(new ProxyServer("127.0.0.1", port1).addNonProxyHost("127.0.0.1")).execute().get(); assertFalse(true); } catch (Throwable e) { assertNotNull(e.getCause()); diff --git a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java index 204ebb0f02..e9cba6194c 100644 --- a/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ProxyTunnellingTest.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.asynchttpclient.AsyncCompletionHandlerBase; @@ -94,7 +93,7 @@ public Response onCompleted(Response response) throws Exception { return response; } }); - Response r = responseFuture.get(5, TimeUnit.SECONDS); + Response r = responseFuture.get(); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); } finally { @@ -122,7 +121,7 @@ public Response onCompleted(Response response) throws Exception { return response; } }); - Response r = responseFuture.get(5, TimeUnit.SECONDS); + Response r = responseFuture.get(); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); } finally { @@ -139,7 +138,7 @@ public void testSimpleAHCConfigProxy() throws IOException, InterruptedException, .setHeader("Content-Type", "text/html")// .build(); try { - Response r = client.get().get(5, TimeUnit.SECONDS); + Response r = client.get().get(); assertEquals(r.getStatusCode(), 200); assertEquals(r.getHeader("X-Proxy-Connection"), "keep-alive"); diff --git a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java index 70c21c588c..e4f1a68c75 100644 --- a/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PutLargeFileTest.java @@ -17,7 +17,6 @@ import java.io.File; import java.io.IOException; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -44,7 +43,7 @@ public void testPutLargeFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionTimeoutInMs(timeout).build()); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -58,7 +57,7 @@ public void testPutSmallFile() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); diff --git a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java index 7312598a60..1bc842399a 100644 --- a/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java +++ b/api/src/test/java/org/asynchttpclient/async/QueryParametersTest.java @@ -84,8 +84,7 @@ public void testQueryParameters() throws IOException, ExecutionException, Timeou } @Test(groups = { "standalone", "default_provider" }) - public void testUrlRequestParametersEncoding() - throws IOException, ExecutionException, InterruptedException, TimeoutException { + public void testUrlRequestParametersEncoding() throws IOException, ExecutionException, InterruptedException { String URL = getTargetUrl() + "?q="; String REQUEST_PARAM = "github github \ngithub"; @@ -93,7 +92,7 @@ public void testUrlRequestParametersEncoding() try { String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, "UTF-8"); LoggerFactory.getLogger(QueryParametersTest.class).info("Executing request [{}] ...", requestUrl2); - Response response = client.prepareGet(requestUrl2).execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet(requestUrl2).execute().get(); String s = URLDecoder.decode(response.getHeader("q"), "UTF-8"); assertEquals(s, REQUEST_PARAM); } finally { diff --git a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java index eefbbf8beb..7cecf24d13 100644 --- a/api/src/test/java/org/asynchttpclient/async/RC10KTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RC10KTest.java @@ -23,7 +23,6 @@ import java.util.List; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; @@ -107,7 +106,7 @@ public void rc10kProblem() throws IOException, ExecutionException, TimeoutExcept } i = 0; for (Future fResp : resps) { - Integer resp = fResp.get(5, TimeUnit.SECONDS); + Integer resp = fResp.get(); assertNotNull(resp); assertEquals(resp.intValue(), i++); } diff --git a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java index e0524e9d81..a27873d108 100644 --- a/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RedirectConnectionUsageTest.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Date; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -87,7 +86,7 @@ public void testGetRedirectFinalUrl() throws Exception { ListenableFuture response = c.executeRequest(r); Response res = null; - res = response.get(3, TimeUnit.SECONDS); + res = response.get(); assertNotNull(res.getResponseBody()); assertEquals(res.getUri().toString(), BASE_URL + "/overthere"); diff --git a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java index 7f0bb6b1eb..86c21eaac5 100644 --- a/api/src/test/java/org/asynchttpclient/async/Relative302Test.java +++ b/api/src/test/java/org/asynchttpclient/async/Relative302Test.java @@ -23,7 +23,6 @@ import java.net.URI; import java.util.Enumeration; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import javax.servlet.ServletException; @@ -90,7 +89,7 @@ public void redirected302Test() throws Exception { AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", "http://www.google.com/").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -111,7 +110,7 @@ public void redirected302InvalidTest() throws Exception { // If the test hit a proxy, no ConnectException will be thrown and instead of 404 will be returned. try { - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", String.format("http://127.0.0.1:%d/", port2)).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 404); @@ -132,7 +131,7 @@ public void absolutePathRedirectTest() throws Exception { String redirectTarget = "/bar/test"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); @@ -153,7 +152,7 @@ public void relativePathRedirectTest() throws Exception { String redirectTarget = "bar/test1"; String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString(); - Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); assertEquals(response.getUri().toString(), destinationUrl); diff --git a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java index 1e2b0d96de..a5025ffb17 100644 --- a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java @@ -136,7 +136,7 @@ public Response onCompleted(Response response) throws Exception { l.countDown(); } } - }).get(5, TimeUnit.SECONDS); + }).get(); if (!l.await(5, TimeUnit.SECONDS)) { fail("Timeout out"); @@ -153,7 +153,7 @@ public void invalidStreamTest2() throws Exception { AsyncHttpClient c = getAsyncHttpClient(config); try { - Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet("http://bit.ly/aUjTtG").execute().get(); if (response != null) { System.out.println(response); } @@ -170,7 +170,7 @@ public void invalidStreamTest2() throws Exception { public void asyncFullBodyProperlyRead() throws Exception { final AsyncHttpClient client = getAsyncHttpClient(null); try { - Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(5, TimeUnit.SECONDS); + Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(); InputStream stream = r.getResponseBodyAsStream(); // FIXME available is an ESTIMATE!!! @@ -191,7 +191,7 @@ public void testUrlRequestParametersEncoding() throws Exception { try { String requestUrl2 = URL + URLEncoder.encode(REQUEST_PARAM, "UTF-8"); logger.info(String.format("Executing request [%s] ...", requestUrl2)); - Response response = client.prepareGet(requestUrl2).execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet(requestUrl2).execute().get(); assertEquals(response.getStatusCode(), 301); } finally { client.close(); @@ -207,7 +207,7 @@ public void testUrlRequestParametersEncoding() throws Exception { public void testAHC60() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.prepareGet("http://www.meetup.com/stackoverflow/Mountain-View-CA/").execute().get(5, TimeUnit.SECONDS); + Response response = client.prepareGet("http://www.meetup.com/stackoverflow/Mountain-View-CA/").execute().get(); assertEquals(response.getStatusCode(), 200); } finally { client.close(); @@ -220,7 +220,7 @@ public void stripQueryStringTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -235,7 +235,7 @@ public void stripQueryStringNegativeTest() throws Exception { AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setRemoveQueryParamsOnRedirect(false).setFollowRedirects(true).build(); AsyncHttpClient c = getAsyncHttpClient(cg); try { - Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(5, TimeUnit.SECONDS); + Response response = c.prepareGet("http://www.freakonomics.com/?p=55846").execute().get(); assertNotNull(response); assertEquals(response.getStatusCode(), 301); @@ -254,7 +254,7 @@ public void evilCoookieTest() throws Exception { builder2.addHeader("Content-Type", "text/plain"); builder2.addCookie(new Cookie(".google.com", "evilcookie", "evilcookie", "test", "/", 10, false, 1, false, false, null, null, Collections. emptySet())); Request request2 = builder2.build(); - Response response = c.executeRequest(request2).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(request2).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java index 4d62240d49..6c27502c6e 100644 --- a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java @@ -23,7 +23,6 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; -import java.util.concurrent.TimeUnit; import static org.testng.Assert.*; @@ -72,7 +71,7 @@ public AbstractHandler configureHandler() throws Exception { public void testMaxRetry() throws Exception { AsyncHttpClient ahc = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setMaxRequestRetry(0).build()); try { - ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build()).get(5, TimeUnit.SECONDS); + ahc.executeRequest(ahc.prepareGet(getTargetUrl()).build()).get(); fail(); } catch (Exception t) { assertNotNull(t.getCause()); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java index f8e697d431..76dac21427 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java @@ -17,7 +17,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -47,7 +46,7 @@ public void testAccumulateErrorBody() throws Exception { Future future = client.get(new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 404); assertEquals(o.toString(), ""); assertTrue(response.getResponseBody().startsWith("")); @@ -64,7 +63,7 @@ public void testOmitErrorBody() throws Exception { Future future = client.get(new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 404); assertEquals(o.toString(), ""); assertEquals(response.getResponseBody(), ""); diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index 5ab0e349e9..ef0dfacf51 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -19,7 +19,6 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import org.asynchttpclient.ByteArrayPart; import org.asynchttpclient.Response; @@ -46,7 +45,7 @@ public void inpuStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes()))); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBody(), MY_MESSAGE); } finally { @@ -63,7 +62,7 @@ public void stringBuilderBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); } finally { @@ -80,7 +79,7 @@ public void byteArrayOutputStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -97,7 +96,7 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Exception { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -119,7 +118,7 @@ public void testPutZeroBytesFileTest() throws Exception { Future future = client.put(new FileBodyGenerator(tmpfile)); System.out.println("waiting for response"); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); tmpfile.delete(); @@ -153,7 +152,7 @@ public void testDeriveOverrideURL() throws Exception { try { Future future = derived.post(generator, consumer); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -204,7 +203,7 @@ public void onBytesReceived(String url, long amount, long current, long total) { Future future = client.post(generator, consumer); - Response response = future.get(5, TimeUnit.SECONDS); + Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -230,11 +229,11 @@ public void testCloseDerivedValidMaster() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).build(); SimpleAsyncHttpClient derived = client.derive().build(); try { - derived.get().get(5, TimeUnit.SECONDS); + derived.get().get(); derived.close(); - Response response = client.get().get(5, TimeUnit.SECONDS); + Response response = client.get().get(); assertEquals(response.getStatusCode(), 200); } finally { @@ -250,7 +249,7 @@ public void testCloseMasterInvalidDerived() throws Exception { client.close(); try { - derived.get().get(5, TimeUnit.SECONDS); + derived.get().get(); fail("Expected closed AHC"); } catch (IOException e) { // expected @@ -261,7 +260,7 @@ public void testCloseMasterInvalidDerived() throws Exception { public void testMultiPartPut() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { - Response response = client.put(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(5, TimeUnit.SECONDS); + Response response = client.put(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); String body = response.getResponseBody(); String contentType = response.getHeader("X-Content-Type"); @@ -285,7 +284,7 @@ public void testMultiPartPut() throws Exception { public void testMultiPartPost() throws Exception { SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/multipart").build(); try { - Response response = client.post(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(5, TimeUnit.SECONDS); + Response response = client.post(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")).get(); String body = response.getResponseBody(); String contentType = response.getHeader("X-Content-Type"); diff --git a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java index 15b63b2b58..38e0e402b9 100644 --- a/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/TransferListenerTest.java @@ -18,7 +18,6 @@ import java.io.File; import java.io.IOException; import java.util.Enumeration; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -115,7 +114,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = c.prepareGet(getTargetUrl()).execute(tl).get(5, TimeUnit.SECONDS); + Response response = c.prepareGet(getTargetUrl()).execute(tl).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -176,7 +175,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = client.preparePut(getTargetUrl()).setBody(file).execute(tl).get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).setBody(file).execute(tl).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); @@ -235,7 +234,7 @@ public void onThrowable(Throwable t) { }); try { - Response response = client.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(file)).execute(tl).get(5, TimeUnit.SECONDS); + Response response = client.preparePut(getTargetUrl()).setBody(new FileBodyGenerator(file)).execute(tl).get(); assertNotNull(response); assertEquals(response.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index dc03ca2afe..8959d7a8bc 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -18,8 +18,6 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.apache.catalina.Context; import org.apache.catalina.Engine; @@ -92,20 +90,19 @@ public void clean() throws InterruptedException, Exception { AsyncHttpClient c = getAsyncHttpClient(null); try { Request deleteRequest = new RequestBuilder("DELETE").setUrl(getTargetUrl()).build(); - c.executeRequest(deleteRequest).get(5, TimeUnit.SECONDS); + c.executeRequest(deleteRequest).get(); } finally { c.close(); } } @Test(groups = { "standalone", "default_provider" }) - public void mkcolWebDavTest1() - throws InterruptedException, IOException, ExecutionException, TimeoutException { + public void mkcolWebDavTest1() throws InterruptedException, IOException, ExecutionException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(mkcolRequest).get(); assertEquals(response.getStatusCode(), 201); } finally { @@ -114,13 +111,12 @@ public void mkcolWebDavTest1() } @Test(groups = { "standalone", "default_provider" }) - public void mkcolWebDavTest2() - throws InterruptedException, IOException, ExecutionException, TimeoutException { + public void mkcolWebDavTest2() throws InterruptedException, IOException, ExecutionException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl() + "/folder2").build(); - Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(mkcolRequest).get(); assertEquals(response.getStatusCode(), 409); } finally { c.close(); @@ -128,13 +124,12 @@ public void mkcolWebDavTest2() } @Test(groups = { "standalone", "default_provider" }) - public void basicPropFindWebDavTest() - throws InterruptedException, IOException, ExecutionException, TimeoutException { + public void basicPropFindWebDavTest() throws InterruptedException, IOException, ExecutionException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(propFindRequest).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(propFindRequest).get(); assertEquals(response.getStatusCode(), 404); } finally { @@ -143,21 +138,20 @@ public void basicPropFindWebDavTest() } @Test(groups = { "standalone", "default_provider" }) - public void propFindWebDavTest() - throws InterruptedException, IOException, ExecutionException, TimeoutException { + public void propFindWebDavTest() throws InterruptedException, IOException, ExecutionException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(mkcolRequest).get(); assertEquals(response.getStatusCode(), 201); Request putRequest = new RequestBuilder("PUT").setUrl(String.format("http://127.0.0.1:%s/folder1/Test.txt", port1)).setBody("this is a test").build(); - response = c.executeRequest(putRequest).get(5, TimeUnit.SECONDS); + response = c.executeRequest(putRequest).get(); assertEquals(response.getStatusCode(), 201); Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(String.format("http://127.0.0.1:%s/folder1/Test.txt", port1)).build(); - response = c.executeRequest(propFindRequest).get(5, TimeUnit.SECONDS); + response = c.executeRequest(propFindRequest).get(); assertEquals(response.getStatusCode(), 207); assertTrue(response.getResponseBody().contains("HTTP/1.1 200 OK")); @@ -167,13 +161,12 @@ public void propFindWebDavTest() } @Test(groups = { "standalone", "default_provider" }) - public void propFindCompletionHandlerWebDavTest() - throws InterruptedException, IOException, ExecutionException, TimeoutException { + public void propFindCompletionHandlerWebDavTest() throws InterruptedException, IOException, ExecutionException { AsyncHttpClient c = getAsyncHttpClient(null); try { Request mkcolRequest = new RequestBuilder("MKCOL").setUrl(getTargetUrl()).build(); - Response response = c.executeRequest(mkcolRequest).get(5, TimeUnit.SECONDS); + Response response = c.executeRequest(mkcolRequest).get(); assertEquals(response.getStatusCode(), 201); Request propFindRequest = new RequestBuilder("PROPFIND").setUrl(getTargetUrl()).build(); @@ -191,7 +184,7 @@ public void onThrowable(Throwable t) { public WebDavResponse onCompleted(WebDavResponse response) throws Exception { return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(webDavResponse); assertEquals(webDavResponse.getStatusCode(), 200); diff --git a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java index f2ba675ead..490931ce8c 100644 --- a/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ZeroCopyFileTest.java @@ -21,7 +21,6 @@ import java.net.URISyntaxException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; @@ -86,7 +85,7 @@ public STATE onContentWriteCompleted() { public Response onCompleted(Response response) throws Exception { return response; } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -102,7 +101,7 @@ public void zeroCopyPutTest() throws IOException, ExecutionException, TimeoutExc AsyncHttpClient client = getAsyncHttpClient(null); try { Future f = client.preparePut("http://127.0.0.1/" + port1 + "/").setBody(SIMPLE_TEXT_FILE).execute(); - Response resp = f.get(5, TimeUnit.SECONDS); + Response resp = f.get(); assertNotNull(resp); assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK); assertEquals(resp.getResponseBody(), SIMPLE_TEXT_FILE_STRING); @@ -143,7 +142,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(resp); assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { @@ -185,7 +184,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { public Response onCompleted() throws Exception { return null; } - }).get(5, TimeUnit.SECONDS); + }).get(); assertNull(resp); assertEquals(SIMPLE_TEXT_FILE.length(), tmp.length()); } finally { diff --git a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java index 9788631eba..5a362fd53a 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/ByteMessageTest.java @@ -15,7 +15,6 @@ import static org.testng.Assert.assertEquals; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -68,7 +67,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.sendMessage("ECHO".getBytes()); @@ -119,7 +118,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.sendMessage("ECHO".getBytes()).sendMessage("ECHO".getBytes()); @@ -171,7 +170,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); latch.await(); assertEquals(text.get(), "ECHOECHO".getBytes()); @@ -219,7 +218,7 @@ public void onMessage(byte[] message) { @Override public void onFragment(byte[] fragment, boolean last) { } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.stream("ECHO".getBytes(), false); websocket.stream("ECHO".getBytes(), true); latch.await(); diff --git a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java index f4dcf1bae5..12fa531e6f 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/CloseCodeReasonMessageTest.java @@ -15,7 +15,6 @@ import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -42,7 +41,7 @@ public void onCloseWithCode() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(5, TimeUnit.SECONDS); + WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(); websocket.close(); @@ -60,7 +59,7 @@ public void onCloseWithCodeServerClose() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(5, TimeUnit.SECONDS); + c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new Listener(latch, text)).build()).get(); latch.await(); assertEquals(text.get(), "1001-Idle Timeout"); diff --git a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java index 74f2b359cf..92e08e10a2 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/RedirectTest.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.servlet.ServletException; @@ -80,28 +79,26 @@ public void testRedirectToWSResource() throws Exception { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference text = new AtomicReference(""); - WebSocket websocket = c.prepareGet(getRedirectURL()).execute( - new WebSocketUpgradeHandler.Builder().addWebSocketListener( - new WebSocketListener() { + WebSocket websocket = c.prepareGet(getRedirectURL()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() { - @Override - public void onOpen(WebSocket websocket) { - text.set("OnOpen"); - latch.countDown(); - } + @Override + public void onOpen(WebSocket websocket) { + text.set("OnOpen"); + latch.countDown(); + } - @Override - public void onClose(WebSocket websocket) { - } + @Override + public void onClose(WebSocket websocket) { + } - @Override - public void onError(Throwable t) { - t.printStackTrace(); - latch.countDown(); - } - }).build()).get(5, TimeUnit.SECONDS); + @Override + public void onError(Throwable t) { + t.printStackTrace(); + latch.countDown(); + } + }).build()).get(); - latch.await(5, TimeUnit.SECONDS); + latch.await(); assertEquals(text.get(), "OnOpen"); websocket.close(); } finally { diff --git a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java index adc670585e..a63c0a15eb 100644 --- a/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java +++ b/api/src/test/java/org/asynchttpclient/websocket/TextMessageTest.java @@ -15,7 +15,6 @@ import static org.testng.Assert.*; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHttpClient; @@ -59,7 +58,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); latch.await(); assertEquals(text.get(), "OnOpen"); @@ -74,7 +73,7 @@ public void onEmptyListenerTest() throws Exception { try { WebSocket websocket = null; try { - websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().build()).get(5, TimeUnit.SECONDS); + websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().build()).get(); } catch (Throwable t) { fail(); } @@ -90,7 +89,7 @@ public void onFailureTest() throws Exception { try { Throwable t = null; try { - /* WebSocket websocket = */c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get(5, TimeUnit.SECONDS); + /* WebSocket websocket = */c.prepareGet("ws://abcdefg").execute(new WebSocketUpgradeHandler.Builder().build()).get(); } catch (Throwable t2) { t = t2; } @@ -124,7 +123,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); latch.await(); assertEquals(text.get(), "OnClose"); @@ -157,7 +156,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.close(); @@ -201,7 +200,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.sendTextMessage("ECHO"); @@ -271,7 +270,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.sendTextMessage("ECHO"); @@ -316,7 +315,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); latch.await(); assertEquals(text.get(), "ECHOECHO"); @@ -357,7 +356,7 @@ public void onError(Throwable t) { t.printStackTrace(); latch.countDown(); } - }).build()).get(5, TimeUnit.SECONDS); + }).build()).get(); websocket.streamText("ECHO", false); websocket.streamText("ECHO", true); From cce5a28e23bd6b4b8e1466d969af0cb526756988 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 27 Sep 2013 11:25:13 -0700 Subject: [PATCH 0136/2389] Refactoring in preparation for supporting spdy multiplexing. --- .../providers/grizzly/EventHandler.java | 33 +++--- .../grizzly/FeedableBodyGenerator.java | 54 +++++---- .../grizzly/GrizzlyAsyncHttpProvider.java | 99 ++++------------ .../providers/grizzly/HttpTxContext.java | 61 ++++++---- .../providers/grizzly/RequestInfoHolder.java | 66 +++++++++++ .../providers/grizzly/Utils.java | 12 ++ .../grizzly/bodyhandler/FileBodyHandler.java | 2 +- .../filters/AsyncHttpClientEventFilter.java | 10 +- .../filters/AsyncHttpClientFilter.java | 108 ++++++++++++++---- .../AsyncHttpClientTransportFilter.java | 77 ------------- .../grizzly/filters/ProxyFilter.java | 2 +- .../filters/events/SSLSwitchingEvent.java | 1 - .../statushandler/AuthorizationHandler.java | 5 +- .../ProxyAuthorizationHandler.java | 18 +-- .../statushandler/RedirectHandler.java | 5 +- 15 files changed, 292 insertions(+), 261 deletions(-) create mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/RequestInfoHolder.java delete mode 100644 providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index d1b94d5bc3..0b5ff84d7d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -91,7 +91,7 @@ public final class EventHandler { public void exceptionOccurred(FilterChainContext ctx, Throwable error) { - HttpTxContext.get(ctx.getConnection()).abort(error); + HttpTxContext.get(ctx).abort(error); } @@ -100,7 +100,7 @@ public void onHttpContentParsed(HttpContent content, FilterChainContext ctx) { final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); + HttpTxContext.get(ctx); final AsyncHandler handler = context.getHandler(); if (handler != null && context.getCurrentState() != ABORT) { try { @@ -119,7 +119,7 @@ public void onHttpContentParsed(HttpContent content, @SuppressWarnings("UnusedParameters") public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) { final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); + HttpTxContext.get(ctx); final AsyncHandler handler = context.getHandler(); if (handler instanceof TransferCompletionHandler) { ((TransferCompletionHandler) handler).onHeaderWriteCompleted(); @@ -128,7 +128,7 @@ public void onHttpHeadersEncoded(HttpHeader httpHeader, FilterChainContext ctx) public void onHttpContentEncoded(HttpContent content, FilterChainContext ctx) { final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); + HttpTxContext.get(ctx); final AsyncHandler handler = context.getHandler(); if (handler instanceof TransferCompletionHandler) { final int written = content.getContent().remaining(); @@ -145,9 +145,7 @@ public void onInitialLineParsed(HttpHeader httpHeader, if (httpHeader.isSkipRemainder()) { return; } - final Connection connection = ctx.getConnection(); - final HttpTxContext context = - HttpTxContext.get(connection); + final HttpTxContext context = HttpTxContext.get(ctx); final int status = ((HttpResponsePacket) httpHeader).getStatus(); if (HttpStatus.CONINTUE_100.statusMatches(status)) { ctx.notifyUpstream(new ContinueEvent(context)); @@ -221,8 +219,7 @@ public void onHttpHeaderError(final HttpHeader httpHeader, t.printStackTrace(); httpHeader.setSkipRemainder(true); - final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx); context.abort(t); } @@ -233,7 +230,7 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, //super.onHttpHeadersParsed(httpHeader, ctx); GrizzlyAsyncHttpProvider.LOGGER.debug("RESPONSE: {}", httpHeader); processKeepAlive(ctx.getConnection(), httpHeader); - final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx); if (httpHeader.isSkipRemainder()) { return; @@ -271,12 +268,13 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, context.getFuture()); final HttpTxContext newContext = context.copy(); + newContext.setRequest(newRequest); context.setFuture(null); - HttpTxContext.set(c, newContext); context.getProvider().execute(c, newRequest, newHandler, - context.getFuture()); + context.getFuture(), + newContext); } catch (Exception e) { context.abort(e); } @@ -366,10 +364,7 @@ public boolean onHttpPacketParsed(HttpHeader httpHeader, FilterChainContext ctx) return false; } - final HttpResponsePacket response = - (HttpResponsePacket) httpHeader; - final HttpTxContext context = HttpTxContext.get( - ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx); cleanup(ctx); final AsyncHandler handler = context.getHandler(); if (handler != null) { @@ -431,9 +426,9 @@ private static HttpTxContext cleanup(final FilterChainContext ctx) { final Connection c = ctx.getConnection(); final HttpTxContext context = - HttpTxContext.get(c); - HttpTxContext.set(c, null); - if (!Utils.isIgnored(ctx.getConnection())) { + HttpTxContext.get(ctx); + HttpTxContext.remove(ctx, context); + if (!Utils.isIgnored(c)) { final ConnectionManager manager = context.getProvider().getConnectionManager(); //if (!manager.canReturnConnection(c)) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index f338897e6f..e359626b0f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -21,10 +21,12 @@ import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.OutputSink; import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.nio.NIOConnection; @@ -174,7 +176,7 @@ public void run() { try { feeder.flush(); } catch (IOException ioe) { - HttpTxContext ctx = HttpTxContext.get(c); + HttpTxContext ctx = HttpTxContext.get(context); ctx.abort(ioe); } } @@ -304,7 +306,7 @@ public final synchronized void feed(final Buffer buffer, final boolean last) throw new IllegalStateException( "Asynchronous transfer has not been initiated."); } - blockUntilQueueFree(feedableBodyGenerator.context.getConnection()); + blockUntilQueueFree(feedableBodyGenerator.context); final HttpContent content = feedableBodyGenerator.contentBuilder .content(buffer) @@ -321,11 +323,13 @@ public final synchronized void feed(final Buffer buffer, final boolean last) * will block is dependent on the write timeout of the transport * associated with the specified connection. */ - private static void blockUntilQueueFree(final Connection c) { - if (!c.canWrite()) { + private static void blockUntilQueueFree(final FilterChainContext ctx) { + HttpContext httpContext = HttpContext.get(ctx); + final OutputSink outputSink = httpContext.getOutputSink(); + if (!outputSink.canWrite()) { final FutureImpl future = Futures.createSafeFuture(); - c.notifyCanWrite(new WriteHandler() { + outputSink.notifyCanWrite(new WriteHandler() { @Override public void onWritePossible() throws Exception { @@ -338,26 +342,26 @@ public void onError(Throwable t) { } }); - block(c, future); + block(ctx, future); } } - private static void block(final Connection c, + private static void block(final FilterChainContext ctx, final FutureImpl future) { try { final long writeTimeout = - c.getTransport().getWriteTimeout(MILLISECONDS); + ctx.getConnection().getTransport().getWriteTimeout(MILLISECONDS); if (writeTimeout != -1) { future.get(writeTimeout, MILLISECONDS); } else { future.get(); } } catch (ExecutionException e) { - HttpTxContext ctx = HttpTxContext.get(c); - ctx.abort(e.getCause()); + HttpTxContext httpTxContext = HttpTxContext.get(ctx); + httpTxContext.abort(e.getCause()); } catch (Exception e) { - HttpTxContext ctx = HttpTxContext.get(c); - ctx.abort(e); + HttpTxContext httpTxContext = HttpTxContext.get(ctx); + httpTxContext.abort(e); } } @@ -493,17 +497,19 @@ public NonBlockingFeeder(final FeedableBodyGenerator feedableBodyGenerator) { */ @Override public synchronized void flush() { - final Connection c = feedableBodyGenerator.context.getConnection(); + final HttpContext httpContext = + HttpContext.get(feedableBodyGenerator.context); + final OutputSink outputSink = httpContext.getOutputSink(); if (isReady()) { - writeUntilFullOrDone(c); + writeUntilFullOrDone(outputSink); if (!isDone()) { if (!isReady()) { notifyReadyToFeed(new ReadyToFeedListenerImpl()); } - if (!c.canWrite()) { + if (!outputSink.canWrite()) { // write queue is full, leverage WriteListener to let us know // when it is safe to write again. - c.notifyCanWrite(new WriteHandlerImpl()); + outputSink.notifyCanWrite(new WriteHandlerImpl()); } } } else { @@ -515,8 +521,8 @@ public synchronized void flush() { // ----------------------------------------------------- Private Methods - private void writeUntilFullOrDone(final Connection c) { - while (c.canWrite()) { + private void writeUntilFullOrDone(final OutputSink outputSink) { + while (outputSink.canWrite()) { if (isReady()) { canFeed(); } @@ -548,6 +554,7 @@ private final class WriteHandlerImpl implements WriteHandler { private final Connection c; + private final FilterChainContext ctx; // -------------------------------------------------------- Constructors @@ -555,6 +562,7 @@ private final class WriteHandlerImpl implements WriteHandler { private WriteHandlerImpl() { this.c = feedableBodyGenerator.context.getConnection(); + this.ctx = feedableBodyGenerator.context; } @@ -577,10 +585,12 @@ public void onWritePossible() throws Exception { @Override public void onError(Throwable t) { - c.setMaxAsyncWriteQueueSize( - feedableBodyGenerator.origMaxPendingBytes); - HttpTxContext ctx = HttpTxContext.get(c); - ctx.abort(t); + if (!Utils.isSpdyConnection(c)) { + c.setMaxAsyncWriteQueueSize( + feedableBodyGenerator.origMaxPendingBytes); + } + HttpTxContext httpTxContext = HttpTxContext.get(ctx); + httpTxContext.abort(t); } } // END WriteHandlerImpl diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 12995bb4f6..f03decb5a9 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -24,12 +24,8 @@ import org.asynchttpclient.Request; import org.asynchttpclient.Response; import org.asynchttpclient.ntlm.NTLMEngine; -import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler; -import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandlerFactory; -import org.asynchttpclient.providers.grizzly.bodyhandler.ExpectHandler; import org.asynchttpclient.providers.grizzly.filters.AsyncHttpClientEventFilter; import org.asynchttpclient.providers.grizzly.filters.AsyncHttpClientFilter; -import org.asynchttpclient.providers.grizzly.filters.AsyncHttpClientTransportFilter; import org.asynchttpclient.providers.grizzly.filters.AsyncSpdyClientEventFilter; import org.asynchttpclient.providers.grizzly.filters.ClientEncodingFilter; import org.asynchttpclient.providers.grizzly.filters.SwitchingSSLFilter; @@ -44,12 +40,11 @@ import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.http.ContentEncoding; import org.glassfish.grizzly.http.GZipContentEncoding; import org.glassfish.grizzly.http.HttpClientFilter; -import org.glassfish.grizzly.http.HttpContent; -import org.glassfish.grizzly.http.HttpRequestPacket; -import org.glassfish.grizzly.http.Method; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.npn.ClientSideNegotiator; import org.glassfish.grizzly.spdy.NextProtoNegSupport; import org.glassfish.grizzly.spdy.SpdyFramingFilter; @@ -59,7 +54,6 @@ import org.glassfish.grizzly.ssl.SSLBaseFilter; import org.glassfish.grizzly.ssl.SSLConnectionContext; import org.glassfish.grizzly.ssl.SSLUtils; -import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; @@ -74,7 +68,6 @@ import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; -import java.io.File; import java.io.IOException; import java.util.LinkedHashSet; import java.util.List; @@ -99,7 +92,6 @@ public class GrizzlyAsyncHttpProvider implements AsyncHttpProvider { public static final Logger LOGGER = LoggerFactory.getLogger(GrizzlyAsyncHttpProvider.class); public final static NTLMEngine NTLM_ENGINE = new NTLMEngine(); - private final BodyHandlerFactory bodyHandlerFactory; private final AsyncHttpClientConfig clientConfig; private ConnectionManager connectionManager; @@ -123,8 +115,6 @@ public GrizzlyAsyncHttpProvider(final AsyncHttpClientConfig clientConfig) { } catch (IOException ioe) { throw new RuntimeException(ioe); } - bodyHandlerFactory = new BodyHandlerFactory(this); - } @@ -158,7 +148,7 @@ public void failed(final Throwable throwable) { public void completed(final Connection c) { try { touchConnection(c, request); - execute(c, request, handler, future); + execute(c, request, handler, future, null); } catch (Exception e) { failed(e); } @@ -239,12 +229,12 @@ public DelayedExecutor.Resolver getResolver() { public ListenableFuture execute(final Connection c, final Request request, final AsyncHandler handler, - final GrizzlyResponseFuture future) { + final GrizzlyResponseFuture future, + final HttpTxContext httpTxContext) { Utils.addRequestInFlight(c); - if (HttpTxContext.get(c) == null) { - HttpTxContext.create(this, future, request, handler, c); - } - c.write(request, createWriteCompletionHandler(future)); + final RequestInfoHolder requestInfoHolder = + new RequestInfoHolder(this, request, handler, future, httpTxContext); + c.write(requestInfoHolder, createWriteCompletionHandler(future)); return future; } @@ -253,7 +243,7 @@ public ListenableFuture execute(final Connection c, void initializeTransport(final AsyncHttpClientConfig clientConfig) { final FilterChainBuilder secure = FilterChainBuilder.stateless(); - secure.add(new AsyncHttpClientTransportFilter()); + secure.add(new TransportFilter()); final int timeout = clientConfig.getRequestTimeoutInMs(); if (timeout > 0) { @@ -271,8 +261,7 @@ void initializeTransport(final AsyncHttpClientConfig clientConfig) { new IdleTimeoutFilter.TimeoutResolver() { @Override public long getTimeout(FilterChainContext ctx) { - final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx); if (context != null) { if (context.isWSRequest()) { return clientConfig.getWebSocketIdleTimeoutInMs(); @@ -495,70 +484,26 @@ public void updated(WriteResult result) { void timeout(final Connection c) { - final HttpTxContext context = HttpTxContext.get(c); - if (context != null) { - HttpTxContext.set(c, null); - context.abort(new TimeoutException("Timeout exceeded")); - } - - } - - - @SuppressWarnings({"unchecked"}) - public boolean sendRequest(final FilterChainContext ctx, - final Request request, - final HttpRequestPacket requestPacket) - throws IOException { - - boolean isWriteComplete = true; - - if (requestHasEntityBody(request)) { - final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); - BodyHandler handler = bodyHandlerFactory.getBodyHandler(request); - if (requestPacket.getHeaders().contains(Header.Expect) - && requestPacket.getHeaders().getValue(1).equalsIgnoreCase("100-Continue")) { - // We have to set the content-length now as the headers will be flushed - // before the FileBodyHandler is invoked. If we don't do it here, and - // the user didn't explicitly set the length, then the transfer-encoding - // will be chunked and zero-copy file transfer will not occur. - final File f = request.getFile(); - if (f != null) { - requestPacket.setContentLengthLong(f.length()); - } - handler = new ExpectHandler(handler); + final String key = HttpTxContext.class.getName(); + HttpTxContext ctx = null; + if (!Utils.isSpdyConnection(c)) { + ctx = (HttpTxContext) c.getAttributes().getAttribute(key); + if (ctx != null) { + c.getAttributes().removeAttribute(key); + ctx.abort(new TimeoutException("Timeout exceeded")); } - context.setBodyHandler(handler); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("REQUEST: {}", requestPacket); - } - isWriteComplete = handler.doHandle(ctx, request, requestPacket); } else { - HttpContent content = HttpContent.builder(requestPacket).last(true).build(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("REQUEST: {}", requestPacket); - } - ctx.write(content, ctx.getTransportContext().getCompletionHandler()); + throw new IllegalStateException(); } +// if (context != null) { +// HttpTxContext.set(c, null); +// context.abort(new TimeoutException("Timeout exceeded")); +// } - return isWriteComplete; } - public static boolean requestHasEntityBody(final Request request) { - - final String method = request.getMethod(); - return (Method.POST.matchesMethod(method) - || Method.PUT.matchesMethod(method) - || Method.PATCH.matchesMethod(method) - || Method.DELETE.matchesMethod(method)); - - } - - - // ----------------------------------------------------------- Inner Classes - - // ---------------------------------------------------------- Nested Classes diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java index 344128f75a..3ea419bf67 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java @@ -18,12 +18,17 @@ import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler; import org.asynchttpclient.providers.grizzly.statushandler.StatusHandler; import org.asynchttpclient.websocket.WebSocket; +import org.glassfish.grizzly.CloseListener; +import org.glassfish.grizzly.CloseType; +import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; -import org.glassfish.grizzly.attributes.AttributeStorage; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.websockets.HandShake; import org.glassfish.grizzly.websockets.ProtocolHandler; +import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -57,6 +62,15 @@ public final class HttpTxContext { private HandShake handshake; private ProtocolHandler protocolHandler; private WebSocket webSocket; + private CloseListener listener = new CloseListener< Closeable,CloseType>() { + @Override + public void onClosed(Closeable closeable, CloseType type) + throws IOException { + if (CloseType.REMOTELY.equals(type)) { + abort(new IOException("Remotely Closed")); + } + } + }; // -------------------------------------------------------- Constructors @@ -67,7 +81,6 @@ private HttpTxContext(final GrizzlyAsyncHttpProvider provider, final Request request, final AsyncHandler handler) { this.provider = provider; - this.future = future; this.request = request; this.handler = handler; @@ -81,35 +94,33 @@ private HttpTxContext(final GrizzlyAsyncHttpProvider provider, // ---------------------------------------------------------- Public Methods - public static void set(final AttributeStorage storage, - final HttpTxContext httpTransactionState) { - - if (httpTransactionState == null) { - REQUEST_STATE_ATTR.remove(storage); - } else { - REQUEST_STATE_ATTR.set(storage, httpTransactionState); - } - + public static void set(final FilterChainContext ctx, + final HttpTxContext httpTxContext) { + HttpContext httpContext = HttpContext.get(ctx); + httpContext.getCloseable().addCloseListener(httpTxContext.listener); + REQUEST_STATE_ATTR.set(httpContext, httpTxContext); } - public static HttpTxContext get(final AttributeStorage storage) { - - return REQUEST_STATE_ATTR.get(storage); - + public static void remove(final FilterChainContext ctx, + final HttpTxContext httpTxContext) { + HttpContext httpContext = HttpContext.get(ctx); + httpContext.getCloseable().removeCloseListener(httpTxContext.listener); + REQUEST_STATE_ATTR.remove(ctx); } - - public static HttpTxContext create(final GrizzlyAsyncHttpProvider provider, - final GrizzlyResponseFuture future, - final Request request, - final AsyncHandler handler, - final AttributeStorage storage) { - final HttpTxContext context = - new HttpTxContext(provider, future, request, handler); - set(storage, context); - return context; + public static HttpTxContext get(FilterChainContext ctx) { + HttpContext httpContext = HttpContext.get(ctx); + return ((httpContext != null) + ? REQUEST_STATE_ATTR.get(httpContext) + : null); } + public static HttpTxContext create(final RequestInfoHolder requestInfoHolder) { + return new HttpTxContext(requestInfoHolder.getProvider(), + requestInfoHolder.getFuture(), + requestInfoHolder.getRequest(), + requestInfoHolder.getHandler()); + } public void abort(final Throwable t) { if (future != null) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/RequestInfoHolder.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/RequestInfoHolder.java new file mode 100644 index 0000000000..7cf16c8ecd --- /dev/null +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/RequestInfoHolder.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.grizzly; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.Request; + +public class RequestInfoHolder { + + private final GrizzlyAsyncHttpProvider provider; + private final Request request; + private final AsyncHandler handler; + private final GrizzlyResponseFuture future; + private final HttpTxContext httpTxContext; + + + // ------------------------------------------------------------ Constructors + + + public RequestInfoHolder(final GrizzlyAsyncHttpProvider provider, + final Request request, + final AsyncHandler handler, + final GrizzlyResponseFuture future, + final HttpTxContext httpTxContext) { + this.provider = provider; + this.request = request; + this.handler = handler; + this.future = future; + this.httpTxContext = httpTxContext; + } + + + // ---------------------------------------------------------- Public Methods + + + public GrizzlyAsyncHttpProvider getProvider() { + return provider; + } + + public Request getRequest() { + return request; + } + + public AsyncHandler getHandler() { + return handler; + } + + public GrizzlyResponseFuture getFuture() { + return future; + } + + public HttpTxContext getHttpTxContext() { + return httpTxContext; + } +} diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java index 3426376ee7..f54f828e1b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/Utils.java @@ -13,10 +13,12 @@ package org.asynchttpclient.providers.grizzly; +import org.asynchttpclient.Request; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.attributes.AttributeStorage; +import org.glassfish.grizzly.http.Method; import java.net.URI; import java.util.concurrent.atomic.AtomicInteger; @@ -88,4 +90,14 @@ public static boolean isSpdyConnection(final Connection c) { Boolean result = SPDY.get(c); return (result != null ? result : false); } + + public static boolean requestHasEntityBody(final Request request) { + + final String method = request.getMethod(); + return (Method.POST.matchesMethod(method) + || Method.PUT.matchesMethod(method) + || Method.PATCH.matchesMethod(method) + || Method.DELETE.matchesMethod(method)); + + } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java index 368a3a2c09..be3248d776 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/FileBodyHandler.java @@ -55,7 +55,7 @@ public boolean doHandle(final FilterChainContext ctx, final File f = request.getFile(); requestPacket.setContentLengthLong(f.length()); - final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); + final HttpTxContext context = HttpTxContext.get(ctx); if (!SEND_FILE_SUPPORT || requestPacket.isSecure()) { final FileInputStream fis = new FileInputStream(request.getFile()); final MemoryManager mm = ctx.getMemoryManager(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java index 8b2aa0783d..eb15b9a9aa 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java @@ -15,11 +15,13 @@ import org.asynchttpclient.providers.grizzly.EventHandler; import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; +import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.http.HttpClientFilter; import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpHeader; -import org.glassfish.grizzly.http.HttpResponsePacket; import java.io.IOException; @@ -51,6 +53,12 @@ public AsyncHttpClientEventFilter(final EventHandler eventHandler, this.eventHandler = eventHandler; } + @Override + public NextAction handleRead(FilterChainContext ctx) throws IOException { + final Connection c = ctx.getConnection(); + HttpContext.newInstance(ctx, c, c, c); + return super.handleRead(ctx); + } @Override public void exceptionOccurred(FilterChainContext ctx, Throwable error) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 52527f597c..cda70498c6 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -29,7 +29,10 @@ import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.GrizzlyResponseFuture; import org.asynchttpclient.providers.grizzly.HttpTxContext; +import org.asynchttpclient.providers.grizzly.RequestInfoHolder; import org.asynchttpclient.providers.grizzly.Utils; +import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler; +import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandlerFactory; import org.asynchttpclient.providers.grizzly.bodyhandler.ExpectHandler; import org.asynchttpclient.providers.grizzly.filters.events.ContinueEvent; import org.asynchttpclient.providers.grizzly.filters.events.SSLSwitchingEvent; @@ -42,6 +45,7 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.FilterChainEvent; import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.ProcessingState; @@ -54,6 +58,7 @@ import org.glassfish.grizzly.ssl.SSLUtils; import org.glassfish.grizzly.websockets.Version; +import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URI; @@ -63,9 +68,11 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpResponsePacket; +import org.slf4j.Logger; import static org.asynchttpclient.providers.grizzly.filters.SwitchingSSLFilter.getHandshakeError; import static org.asynchttpclient.util.AsyncHttpProviderUtils.getAuthority; @@ -83,9 +90,11 @@ public final class AsyncHttpClientFilter extends BaseFilter { private ConcurrentLinkedQueue requestCache = new ConcurrentLinkedQueue(); + private final Logger logger; private final AsyncHttpClientConfig config; private final GrizzlyAsyncHttpProvider grizzlyAsyncHttpProvider; + private final BodyHandlerFactory bodyHandlerFactory; private static final Attribute PROXY_AUTH_FAILURE = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(AsyncHttpClientFilter.class.getName() + "-PROXY-AUTH_FAILURE"); @@ -95,9 +104,9 @@ public final class AsyncHttpClientFilter extends BaseFilter { public AsyncHttpClientFilter(GrizzlyAsyncHttpProvider grizzlyAsyncHttpProvider, final AsyncHttpClientConfig config) { this.grizzlyAsyncHttpProvider = grizzlyAsyncHttpProvider; - this.config = config; - + bodyHandlerFactory = new BodyHandlerFactory(grizzlyAsyncHttpProvider); + logger = GrizzlyAsyncHttpProvider.LOGGER; } @@ -125,9 +134,9 @@ public NextAction handleWrite(final FilterChainContext ctx) throws IOException { Object message = ctx.getMessage(); - if (message instanceof Request) { + if (message instanceof RequestInfoHolder) { ctx.setMessage(null); - if (!sendAsGrizzlyRequest((Request) message, ctx)) { + if (!sendAsGrizzlyRequest((RequestInfoHolder) message, ctx)) { return ctx.getSuspendAction(); } } else if (message instanceof Buffer) { @@ -182,7 +191,8 @@ public Object onCompleted(Response response) throws Exception { grizzlyAsyncHttpProvider.execute(ctx.getConnection(), request, handler, - future); + future, + HttpTxContext.get(ctx)); return ctx.getSuspendAction(); } @@ -203,32 +213,36 @@ private static void recycleRequestResponsePackets(final Connection c, } } - private boolean sendAsGrizzlyRequest(final Request request, + private boolean sendAsGrizzlyRequest(final RequestInfoHolder requestInfoHolder, final FilterChainContext ctx) throws IOException { - final HttpTxContext httpCtx = HttpTxContext.get(ctx.getConnection()); + HttpTxContext httpTxContext = requestInfoHolder.getHttpTxContext(); + if (httpTxContext == null) { + httpTxContext = HttpTxContext.create(requestInfoHolder); + } - if (checkProxyAuthFailure(ctx, httpCtx)) { + if (checkProxyAuthFailure(ctx, httpTxContext)) { return true; } - final URI uri = httpCtx.getRequest().getURI(); + final URI uri = httpTxContext.getRequest().getURI(); boolean secure = Utils.isSecure(uri); // If the request is secure, check to see if an error occurred during // the handshake. We have to do this here, as the error would occur // out of the scope of a HttpTxContext so there would be // no good way to communicate the problem to the caller. - if (secure && checkHandshakeError(ctx, httpCtx)) { + if (secure && checkHandshakeError(ctx, httpTxContext)) { return true; } - if (isUpgradeRequest(httpCtx.getHandler()) && isWSRequest(httpCtx.getRequestUrl())) { - httpCtx.setWSRequest(true); - convertToUpgradeRequest(httpCtx); + if (isUpgradeRequest(httpTxContext.getHandler()) && isWSRequest(httpTxContext.getRequestUrl())) { + httpTxContext.setWSRequest(true); + convertToUpgradeRequest(httpTxContext); } + final Request request = httpTxContext.getRequest(); HttpRequestPacket requestPacket = requestCache.poll(); if (requestPacket == null) { requestPacket = new HttpRequestPacketImpl(); @@ -244,7 +258,7 @@ private boolean sendAsGrizzlyRequest(final Request request, requestPacket.setRequestURI(uri.getPath()); } - if (GrizzlyAsyncHttpProvider.requestHasEntityBody(request)) { + if (Utils.requestHasEntityBody(request)) { final long contentLength = request.getContentLength(); if (contentLength > 0) { requestPacket.setContentLengthLong(contentLength); @@ -254,16 +268,16 @@ private boolean sendAsGrizzlyRequest(final Request request, } } - if (httpCtx.isWSRequest()) { + if (httpTxContext.isWSRequest()) { try { - final URI wsURI = new URI(httpCtx.getWsRequestURI()); - httpCtx.setProtocolHandler(Version.RFC6455.createHandler(true)); - httpCtx.setHandshake( - httpCtx.getProtocolHandler().createHandShake(wsURI)); + final URI wsURI = new URI(httpTxContext.getWsRequestURI()); + httpTxContext.setProtocolHandler(Version.RFC6455.createHandler(true)); + httpTxContext.setHandshake( + httpTxContext.getProtocolHandler().createHandShake(wsURI)); requestPacket = (HttpRequestPacket) - httpCtx.getHandshake().composeHeaders().getHttpHeader(); + httpTxContext.getHandshake().composeHeaders().getHttpHeader(); } catch (URISyntaxException e) { - throw new IllegalArgumentException("Invalid WS URI: " + httpCtx.getWsRequestURI()); + throw new IllegalArgumentException("Invalid WS URI: " + httpTxContext.getWsRequestURI()); } } @@ -273,7 +287,7 @@ private boolean sendAsGrizzlyRequest(final Request request, addGeneralHeaders(request, requestPacket); addCookies(request, requestPacket); - initTransferCompletionHandler(request, httpCtx.getHandler()); + initTransferCompletionHandler(request, httpTxContext.getHandler()); final HttpRequestPacket requestPacketLocal = requestPacket; FilterChainContext sendingCtx = ctx; @@ -284,11 +298,55 @@ private boolean sendAsGrizzlyRequest(final Request request, // use a different FilterChainContext when invoking sendRequest(). sendingCtx = checkAndHandleFilterChainUpdate(ctx, sendingCtx); } + final Connection c = ctx.getConnection(); + HttpContext.newInstance(ctx, c, c, c); + HttpTxContext.set(ctx, httpTxContext); + return sendRequest(sendingCtx, request, requestPacketLocal); + + } + + @SuppressWarnings("unchecked") + public boolean sendRequest(final FilterChainContext ctx, + final Request request, + final HttpRequestPacket requestPacket) + throws IOException { + + boolean isWriteComplete = true; + + if (Utils.requestHasEntityBody(request)) { + final HttpTxContext context = + HttpTxContext.get(ctx); + BodyHandler handler = bodyHandlerFactory.getBodyHandler(request); + if (requestPacket.getHeaders().contains(Header.Expect) + && requestPacket.getHeaders() + .getValue(1) + .equalsIgnoreCase("100-Continue")) { + // We have to set the content-length now as the headers will be flushed + // before the FileBodyHandler is invoked. If we don't do it here, and + // the user didn't explicitly set the length, then the transfer-encoding + // will be chunked and zero-copy file transfer will not occur. + final File f = request.getFile(); + if (f != null) { + requestPacket.setContentLengthLong(f.length()); + } + handler = new ExpectHandler(handler); + } + context.setBodyHandler(handler); + if (logger.isDebugEnabled()) { + logger.debug("REQUEST: {}", requestPacket); + } + isWriteComplete = handler.doHandle(ctx, request, requestPacket); + } else { + HttpContent content = + HttpContent.builder(requestPacket).last(true).build(); + if (logger.isDebugEnabled()) { + logger.debug("REQUEST: {}", requestPacket); + } + ctx.write(content, ctx.getTransportContext().getCompletionHandler()); + } - return grizzlyAsyncHttpProvider.sendRequest(sendingCtx, - request, - requestPacketLocal); + return isWriteComplete; } private static FilterChainContext checkAndHandleFilterChainUpdate(final FilterChainContext ctx, diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java deleted file mode 100644 index 39982d6c5c..0000000000 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientTransportFilter.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2013 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.grizzly.filters; - -import org.asynchttpclient.providers.grizzly.HttpTxContext; -import org.glassfish.grizzly.CompletionHandler; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.filterchain.NextAction; -import org.glassfish.grizzly.filterchain.TransportFilter; - -import java.io.EOFException; -import java.io.IOException; - -/** - * Custom {@link TransportFilter} implementation to capture and handle low-level - * exceptions. - * - * @since 1.7 - * @author The Grizzly Team - */ -public final class AsyncHttpClientTransportFilter extends TransportFilter { - - - // ----------------------------------------------------- Methods from Filter - - - @Override - public NextAction handleRead(FilterChainContext ctx) throws IOException { - final HttpTxContext context = - HttpTxContext.get(ctx.getConnection()); - if (context == null) { - return super.handleRead(ctx); - } - ctx.getTransportContext().setCompletionHandler(new CompletionHandler() { - @Override - public void cancelled() { - - } - - @Override - public void failed(Throwable throwable) { - if (throwable instanceof EOFException) { - context.abort(new IOException("Remotely Closed")); - } - } - - @Override - public void completed(Object result) { - } - - @Override - public void updated(Object result) { - } - }); - return super.handleRead(ctx); - } - - @Override - public void exceptionOccurred(FilterChainContext ctx, Throwable error) { - final HttpTxContext context = HttpTxContext.get(ctx.getConnection()); - if (context != null) { - context.abort(error.getCause()); - } - } - -} diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java index 0a2be3030b..6786a95550 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java @@ -65,7 +65,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { org.glassfish.grizzly.http.HttpContent content = ctx.getMessage(); HttpRequestPacket request = (HttpRequestPacket) content.getHttpHeader(); - HttpTxContext context = HttpTxContext.get(ctx.getConnection()); + HttpTxContext context = HttpTxContext.get(ctx); assert(context != null); Request req = context.getRequest(); if (!secure) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java index 84ae75f26c..17612dc953 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/events/SSLSwitchingEvent.java @@ -16,7 +16,6 @@ import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainEvent; -import java.util.concurrent.Callable; /** * {@link FilterChainEvent} to dynamically enable/disable the SSLFilter on diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java index 2ee3ef7b08..d9bf914507 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java @@ -103,12 +103,13 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTxContext.set(c, newContext); + HttpTxContext.set(ctx, newContext); newContext.setInvocationStatus(STOP); httpTransactionContext.getProvider().execute(c, req, httpTransactionContext.getHandler(), - httpTransactionContext.getFuture()); + httpTransactionContext.getFuture(), + newContext); return false; } catch (Exception e) { httpTransactionContext.abort(e); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index dbe8ff5d9a..4720763ca3 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -23,6 +23,7 @@ import org.asynchttpclient.util.Base64; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HttpStatus; @@ -149,7 +150,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTxContext.set(c, newContext); + HttpTxContext.set(ctx, newContext); newContext.setInvocationStatus(tempInvocationStatus); @@ -163,18 +164,18 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, "Negotiate " + challengeHeader); - return executeRequest(httpTransactionContext, req, c); + return executeRequest(httpTransactionContext, req, c, newContext); } else if (isNTLMSecondHandShake(proxyAuth)) { final Connection c = ctx.getConnection(); final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTxContext.set(c, newContext); + HttpTxContext.set(ctx, newContext); newContext.setInvocationStatus(tempInvocationStatus); - return executeRequest(httpTransactionContext, req, c); + return executeRequest(httpTransactionContext, req, c, newContext); } else { final Connection c = getConnectionForNextRequest(ctx, @@ -184,12 +185,12 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, final HttpTxContext newContext = httpTransactionContext.copy(); httpTransactionContext.setFuture(null); - HttpTxContext.set(c, newContext); + HttpTxContext.set(ctx, newContext); newContext.setInvocationStatus(tempInvocationStatus); //NTLM needs the same connection to be used for exchange of tokens - return executeRequest(httpTransactionContext, req, c); + return executeRequest(httpTransactionContext, req, c, newContext); } } catch (Exception e) { httpTransactionContext.abort(e); @@ -200,11 +201,12 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, private boolean executeRequest( final HttpTxContext httpTransactionContext, - final Request req, final Connection c) { + final Request req, final Connection c, final HttpTxContext httpTxContext) { httpTransactionContext.getProvider().execute(c, req, httpTransactionContext.getHandler(), - httpTransactionContext.getFuture()); + httpTransactionContext.getFuture(), + httpTxContext); return false; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java index 448d004c16..4a17602a3f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/RedirectHandler.java @@ -89,11 +89,12 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, newContext.setInvocationStatus(CONTINUE); newContext.setRequest(requestToSend); newContext.setRequestUrl(requestToSend.getUrl()); - HttpTxContext.set(c, newContext); + HttpTxContext.set(ctx, newContext); httpTransactionContext.getProvider().execute(c, requestToSend, newContext.getHandler(), - newContext.getFuture()); + newContext.getFuture(), + newContext); return false; } catch (Exception e) { httpTransactionContext.abort(e); From 078d86af833dbfbda824fd686befbf40c79464c5 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 27 Sep 2013 13:09:18 -0700 Subject: [PATCH 0137/2389] Uptake grizzly 2.3.7-SNAPSHOT. This release includes change necessary to support SPDY multiplexing with AHC. Simple test of 20 concurrent requests over a single connection to https://www.google.com confirm multiplexing is working. --- providers/grizzly/pom.xml | 2 +- .../providers/grizzly/EventHandler.java | 2 +- .../grizzly/GrizzlyAsyncHttpProvider.java | 3 +-- .../filters/AsyncHttpClientEventFilter.java | 7 ------ .../filters/AsyncHttpClientFilter.java | 22 ++++++++++++++++++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index 775b199f1e..ab9d594d5b 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -14,7 +14,7 @@ - 2.3.6 + 2.3.7-SNAPSHOT 1.0 diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 0b5ff84d7d..c0e28d05c1 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -428,7 +428,7 @@ private static HttpTxContext cleanup(final FilterChainContext ctx) { final HttpTxContext context = HttpTxContext.get(ctx); HttpTxContext.remove(ctx, context); - if (!Utils.isIgnored(c)) { + if (!Utils.isSpdyConnection(c) && !Utils.isIgnored(c)) { final ConnectionManager manager = context.getProvider().getConnectionManager(); //if (!manager.canReturnConnection(c)) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index f03decb5a9..a375d815de 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -44,7 +44,6 @@ import org.glassfish.grizzly.http.ContentEncoding; import org.glassfish.grizzly.http.GZipContentEncoding; import org.glassfish.grizzly.http.HttpClientFilter; -import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.npn.ClientSideNegotiator; import org.glassfish.grizzly.spdy.NextProtoNegSupport; import org.glassfish.grizzly.spdy.SpdyFramingFilter; @@ -485,7 +484,7 @@ public void updated(WriteResult result) { void timeout(final Connection c) { final String key = HttpTxContext.class.getName(); - HttpTxContext ctx = null; + HttpTxContext ctx; if (!Utils.isSpdyConnection(c)) { ctx = (HttpTxContext) c.getAttributes().getAttribute(key); if (ctx != null) { diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java index eb15b9a9aa..747d9982ad 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientEventFilter.java @@ -53,13 +53,6 @@ public AsyncHttpClientEventFilter(final EventHandler eventHandler, this.eventHandler = eventHandler; } - @Override - public NextAction handleRead(FilterChainContext ctx) throws IOException { - final Connection c = ctx.getConnection(); - HttpContext.newInstance(ctx, c, c, c); - return super.handleRead(ctx); - } - @Override public void exceptionOccurred(FilterChainContext ctx, Throwable error) { eventHandler.exceptionOccurred(ctx, error); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index cda70498c6..d2724f5925 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -54,6 +54,8 @@ import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.MimeHeaders; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.spdy.SpdySession; +import org.glassfish.grizzly.spdy.SpdyStream; import org.glassfish.grizzly.ssl.SSLConnectionContext; import org.glassfish.grizzly.ssl.SSLUtils; import org.glassfish.grizzly.websockets.Version; @@ -68,6 +70,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.locks.Lock; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.http.HttpContent; @@ -299,7 +302,24 @@ private boolean sendAsGrizzlyRequest(final RequestInfoHolder requestInfoHolder, sendingCtx = checkAndHandleFilterChainUpdate(ctx, sendingCtx); } final Connection c = ctx.getConnection(); - HttpContext.newInstance(ctx, c, c, c); + System.out.println("*** CONNECTION: " + c); + if (!Utils.isSpdyConnection(c)) { + HttpContext.newInstance(ctx, c, c, c); + } else { + SpdySession session = SpdySession.get(c); + final Lock lock = session.getNewClientStreamLock(); + try { + lock.lock(); + SpdyStream stream = session.openStream( + requestPacketLocal, + session.getNextLocalStreamId(), + 0, 0, 0, false, !requestPacketLocal.isExpectContent()); + HttpContext.newInstance(ctx, stream, stream, stream); + } finally { + lock.unlock(); + } + + } HttpTxContext.set(ctx, httpTxContext); return sendRequest(sendingCtx, request, requestPacketLocal); From dd2cc874df827332798818003f8bfc56d67377ae Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 11:28:04 +0200 Subject: [PATCH 0138/2389] Drop Netty 3 support, move Spnego into api, close #316 --- .../filter/ResponseFilter.java | 2 +- .../listener/TransferCompletionHandler.java | 62 +- .../asynchttpclient}/spnego/SpnegoEngine.java | 45 +- .../spnego/SpnegoTokenGenerator.java | 2 +- .../async/SimpleAsyncHttpClientTest.java | 85 +- .../filters/AsyncHttpClientFilter.java | 4 +- providers/netty/pom.xml | 41 +- .../providers/netty/BodyChunkedInput.java | 76 - .../providers/netty/BodyFileRegion.java | 57 - .../providers/netty}/Callback.java | 4 +- .../providers/netty}/Constants.java | 2 +- .../providers/netty}/DiscardEvent.java | 2 +- .../netty/FeedableBodyGenerator.java | 119 - .../netty/NettyAsyncHttpProvider.java | 2329 +---------------- .../netty/NettyAsyncHttpProviderConfig.java | 79 +- .../providers/netty/NettyConnectListener.java | 153 -- .../providers/netty/NettyConnectionsPool.java | 294 --- .../providers/netty/NettyResponse.java | 121 - .../providers/netty/NettyResponseFuture.java | 515 ---- .../providers/netty/NettyWebSocket.java | 236 -- .../providers/netty/Protocol.java | 27 - .../providers/netty/ResponseBodyPart.java | 134 - .../providers/netty/ResponseHeaders.java | 74 - .../providers/netty/ResponseStatus.java | 75 - .../providers/netty/WebSocketUtil.java | 72 - .../providers/netty/channel}/Channels.java | 176 +- .../netty/channel}/NettyConnectionsPool.java | 4 +- .../netty/channel/NonConnectionsPool.java} | 35 +- .../providers/netty/future}/FutureReaper.java | 9 +- .../netty/future}/NettyResponseFuture.java | 6 +- .../netty/future}/NettyResponseFutures.java | 2 +- .../providers/netty/handler/HttpProtocol.java | 450 ++++ .../netty/handler/NettyChannelHandler.java | 199 ++ .../providers/netty/handler/Protocol.java | 137 + .../netty/handler/WebSocketProtocol.java | 221 ++ .../netty/request}/BodyChunkedInput.java | 2 +- .../netty/request}/BodyFileRegion.java | 2 +- .../netty/request}/FeedableBodyGenerator.java | 2 +- .../netty/request}/NettyConnectListener.java | 23 +- .../netty/request}/NettyRequestSender.java | 298 ++- .../netty/request}/NettyRequests.java | 37 +- .../netty/request}/ProgressListener.java | 36 +- .../netty/response}/NettyResponse.java | 2 +- .../netty/response}/ResponseBodyPart.java | 4 +- .../netty/response}/ResponseHeaders.java | 2 +- .../netty/response}/ResponseStatus.java | 2 +- .../providers/netty/spnego/SpnegoEngine.java | 172 -- .../providers/netty}/util/ByteBufUtil.java | 2 +- .../netty/util/ChannelBufferUtil.java | 35 - .../netty/util/CleanupChannelGroup.java | 34 +- .../providers/netty}/util/HttpUtil.java | 2 +- .../providers/netty/ws}/NettyWebSocket.java | 130 +- .../providers/netty/ws}/WebSocketUtil.java | 2 +- .../netty/NettyAsyncHttpProviderTest.java | 23 - .../netty/NettyAsyncProviderBasicTest.java | 8 +- .../netty/NettyAsyncProviderPipelineTest.java | 58 +- .../netty/NettyAsyncResponseTest.java | 21 +- .../providers/netty/NettyAuthTimeoutTest.java | 1 - .../providers/netty/NettyBasicAuthTest.java | 7 - .../netty/NettyConnectionPoolTest.java | 7 +- .../netty/NettyMultipartUploadTest.java | 2 - .../netty/NettyPerRequestTimeoutTest.java | 2 +- .../providers/netty/NettyProviderUtil.java | 11 +- .../NettyRequestThrottleTimeoutTest.java | 23 +- .../netty/RetryNonBlockingIssue.java | 11 +- .../netty/websocket/NettyRedirectTest.java | 2 - .../netty/websocket/NettyTextMessageTest.java | 2 - providers/netty4/pom.xml | 51 - .../netty4/NettyAsyncHttpProvider.java | 94 - .../netty4/NettyAsyncHttpProviderConfig.java | 227 -- .../providers/netty4/NettyChannelHandler.java | 873 ------ .../providers/netty4/OptimizedFileRegion.java | 68 - .../providers/netty4/Protocol.java | 24 - .../providers/netty4/ThreadLocalBoolean.java | 19 - .../netty4/spnego/SpnegoTokenGenerator.java | 55 - .../netty4/util/CleanupChannelGroup.java | 110 - .../netty4/NettyAsyncHttpProviderTest.java | 25 - .../netty4/NettyAsyncProviderBasicTest.java | 36 - .../NettyAsyncProviderPipelineTest.java | 89 - .../netty4/NettyAsyncResponseTest.java | 94 - .../netty4/NettyAsyncStreamHandlerTest.java | 25 - .../netty4/NettyAsyncStreamLifecycleTest.java | 24 - .../netty4/NettyAuthTimeoutTest.java | 27 - .../providers/netty4/NettyBasicAuthTest.java | 31 - .../providers/netty4/NettyBasicHttpsTest.java | 25 - .../providers/netty4/NettyBodyChunkTest.java | 25 - .../NettyBodyDeferringAsyncHandlerTest.java | 26 - .../netty4/NettyByteBufferCapacityTest.java | 25 - .../providers/netty4/NettyChunkingTest.java | 12 - .../netty4/NettyComplexClientTest.java | 25 - .../netty4/NettyConnectionPoolTest.java | 115 - .../providers/netty4/NettyDigestAuthTest.java | 24 - .../providers/netty4/NettyEmptyBodyTest.java | 25 - .../netty4/NettyErrorResponseTest.java | 25 - .../netty4/NettyExpect100ContinueTest.java | 25 - .../netty4/NettyFilePartLargeFileTest.java | 24 - .../providers/netty4/NettyFilterTest.java | 24 - .../netty4/NettyFollowingThreadTest.java | 25 - .../providers/netty4/NettyHead302Test.java | 25 - .../netty4/NettyHostnameVerifierTest.java | 25 - .../netty4/NettyHttpToHttpsRedirectTest.java | 24 - .../netty4/NettyIdleStateHandlerTest.java | 24 - .../netty4/NettyInputStreamTest.java | 24 - .../netty4/NettyListenableFutureTest.java | 26 - .../netty4/NettyMaxConnectionsInThreads.java | 23 - .../netty4/NettyMaxTotalConnectionTest.java | 24 - .../netty4/NettyMultipartUploadTest.java | 29 - .../netty4/NettyMultipleHeaderTest.java | 24 - .../netty4/NettyNoNullResponseTest.java | 24 - .../NettyNonAsciiContentLengthTest.java | 25 - .../netty4/NettyParamEncodingTest.java | 24 - .../NettyPerRequestRelative302Test.java | 24 - .../netty4/NettyPerRequestTimeoutTest.java | 33 - .../netty4/NettyPostRedirectGetTest.java | 27 - .../providers/netty4/NettyPostWithQSTest.java | 24 - .../providers/netty4/NettyProxyTest.java | 25 - .../netty4/NettyProxyTunnellingTest.java | 29 - .../netty4/NettyPutLargeFileTest.java | 24 - .../netty4/NettyQueryParametersTest.java | 24 - .../providers/netty4/NettyRC10KTest.java | 24 - .../NettyRedirectConnectionUsageTest.java | 24 - .../netty4/NettyRelative302Test.java | 25 - .../providers/netty4/NettyRemoteSiteTest.java | 28 - .../NettyRequestThrottleTimeoutTest.java | 135 - .../netty4/NettyRetryRequestTest.java | 28 - .../NettySimpleAsyncHttpClientTest.java | 35 - .../netty4/NettyTransferListenerTest.java | 24 - .../netty4/NettyWebDavBasicTest.java | 24 - .../netty4/NettyZeroCopyFileTest.java | 24 - .../netty4/RetryNonBlockingIssue.java | 266 -- .../websocket/NettyByteMessageTest.java | 25 - .../NettyCloseCodeReasonMsgTest.java | 27 - .../netty4/websocket/NettyRedirectTest.java | 26 - .../websocket/NettyTextMessageTest.java | 25 - providers/netty4/src/test/resources/300k.png | Bin 265495 -> 0 bytes .../src/test/resources/SimpleTextFile.txt | 1 - .../netty4/src/test/resources/client.keystore | Bin 1277 -> 0 bytes .../netty4/src/test/resources/gzip.txt.gz | Bin 47 -> 0 bytes .../src/test/resources/logback-test.xml | 13 - .../src/test/resources/realm.properties | 1 - .../src/test/resources/ssltest-cacerts.jks | Bin 29888 -> 0 bytes .../src/test/resources/ssltest-keystore.jks | Bin 1445 -> 0 bytes .../netty4/src/test/resources/textfile.txt | 1 - .../netty4/src/test/resources/textfile2.txt | 1 - providers/pom.xml | 1 - 145 files changed, 1727 insertions(+), 8673 deletions(-) rename {providers/netty4/src/main/java/org/asynchttpclient/providers/netty4 => api/src/main/java/org/asynchttpclient}/spnego/SpnegoEngine.java (84%) rename {providers/netty/src/main/java/org/asynchttpclient/providers/netty => api/src/main/java/org/asynchttpclient}/spnego/SpnegoTokenGenerator.java (97%) delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyFileRegion.java rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty}/Callback.java (72%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty}/Constants.java (86%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty}/DiscardEvent.java (66%) delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/FeedableBodyGenerator.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponse.java delete mode 100755 providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/Protocol.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseHeaders.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseStatus.java delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/WebSocketUtil.java rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/channel}/Channels.java (84%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/channel}/NettyConnectionsPool.java (98%) rename providers/{netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java => netty/src/main/java/org/asynchttpclient/providers/netty/channel/NonConnectionsPool.java} (50%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/future}/FutureReaper.java (91%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/future}/NettyResponseFuture.java (98%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/future}/NettyResponseFutures.java (98%) create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/BodyChunkedInput.java (97%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/BodyFileRegion.java (97%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/FeedableBodyGenerator.java (98%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/NettyConnectListener.java (87%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/NettyRequestSender.java (64%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/NettyRequests.java (92%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/request}/ProgressListener.java (70%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/response}/NettyResponse.java (98%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/response}/ResponseBodyPart.java (95%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/response}/ResponseHeaders.java (97%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/response}/ResponseStatus.java (98%) delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoEngine.java rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty}/util/ByteBufUtil.java (95%) delete mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ChannelBufferUtil.java rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty}/util/HttpUtil.java (94%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/ws}/NettyWebSocket.java (71%) rename providers/{netty4/src/main/java/org/asynchttpclient/providers/netty4 => netty/src/main/java/org/asynchttpclient/providers/netty/ws}/WebSocketUtil.java (98%) delete mode 100644 providers/netty4/pom.xml delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java delete mode 100644 providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java delete mode 100644 providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java delete mode 100644 providers/netty4/src/test/resources/300k.png delete mode 100644 providers/netty4/src/test/resources/SimpleTextFile.txt delete mode 100644 providers/netty4/src/test/resources/client.keystore delete mode 100644 providers/netty4/src/test/resources/gzip.txt.gz delete mode 100644 providers/netty4/src/test/resources/logback-test.xml delete mode 100644 providers/netty4/src/test/resources/realm.properties delete mode 100644 providers/netty4/src/test/resources/ssltest-cacerts.jks delete mode 100644 providers/netty4/src/test/resources/ssltest-keystore.jks delete mode 100644 providers/netty4/src/test/resources/textfile.txt delete mode 100644 providers/netty4/src/test/resources/textfile2.txt diff --git a/api/src/main/java/org/asynchttpclient/filter/ResponseFilter.java b/api/src/main/java/org/asynchttpclient/filter/ResponseFilter.java index 8c26bcca9a..cdad3ce23c 100644 --- a/api/src/main/java/org/asynchttpclient/filter/ResponseFilter.java +++ b/api/src/main/java/org/asynchttpclient/filter/ResponseFilter.java @@ -15,7 +15,7 @@ /** * A Filter interface that gets invoked before making the processing of the response bytes. {@link ResponseFilter} are invoked * before the actual response's status code get processed. That means authorization, proxy authentication and redirects - * processing hasn't occured when {@link ResponseFilter} gets invoked. + * processing hasn't occurred when {@link ResponseFilter} gets invoked. */ public interface ResponseFilter { diff --git a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java index ff7417be3b..94a5888af5 100644 --- a/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java +++ b/api/src/main/java/org/asynchttpclient/listener/TransferCompletionHandler.java @@ -13,7 +13,6 @@ package org.asynchttpclient.listener; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicLong; import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; @@ -42,7 +41,7 @@ * public void onBytesReceived(ByteBuffer buffer) { * } *

- * public void onBytesSent(ByteBuffer buffer) { + * public void onBytesSent(long amount, long current, long total) { * } *

* public void onRequestResponseCompleted() { @@ -61,9 +60,7 @@ public class TransferCompletionHandler extends AsyncCompletionHandlerBase { private final static Logger logger = LoggerFactory.getLogger(TransferCompletionHandler.class); private final ConcurrentLinkedQueue listeners = new ConcurrentLinkedQueue(); private final boolean accumulateResponseBytes; - private TransferAdapter transferAdapter; - private AtomicLong bytesTransferred = new AtomicLong(0); - private AtomicLong totalBytesToTransfer = new AtomicLong(-1); + private FluentCaseInsensitiveStringsMap headers; /** * Create a TransferCompletionHandler that will not accumulate bytes. The resulting {@link org.asynchttpclient.Response#getResponseBody()}, @@ -109,13 +106,13 @@ public TransferCompletionHandler removeTransferListener(TransferListener t) { } /** - * Associate a {@link TransferCompletionHandler.TransferAdapter} with this listener. + * Set headers to this listener. * - * @param transferAdapter - * {@link TransferAdapter} + * @param headers + * {@link FluentCaseInsensitiveStringsMap} */ - public void transferAdapter(TransferAdapter transferAdapter) { - this.transferAdapter = transferAdapter; + public void headers(FluentCaseInsensitiveStringsMap headers) { + this.headers = headers; } @Override @@ -136,49 +133,20 @@ public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Excep @Override public Response onCompleted(Response response) throws Exception { - if (bytesTransferred.get() > 0L) { - // onContentWriteCompleted hasn't been notified, it would have been set to -1L (async race) - onContentWriteCompleted(); - } fireOnEnd(); return response; } @Override public STATE onHeaderWriteCompleted() { - if (transferAdapter != null) { - fireOnHeadersSent(transferAdapter.getHeaders()); - } - return STATE.CONTINUE; - } - - @Override - public STATE onContentWriteCompleted() { - // onContentWriteProgress might not have been called on last write - long transferred = bytesTransferred.getAndSet(-1L); - long expected = totalBytesToTransfer.get(); - - if (expected <= 0L && transferAdapter != null) { - FluentCaseInsensitiveStringsMap headers = transferAdapter.getHeaders(); - String contentLengthString = headers.getFirstValue("Content-Length"); - if (contentLengthString != null) - expected = Long.valueOf(contentLengthString); - } - - if (expected > 0L && transferred != expected) { - fireOnBytesSent(expected - transferred, expected, expected); + if (headers != null) { + fireOnHeadersSent(headers); } - return STATE.CONTINUE; } @Override public STATE onContentWriteProgress(long amount, long current, long total) { - bytesTransferred.addAndGet(amount); - - if (total > 0L) - totalBytesToTransfer.set(total); - fireOnBytesSent(amount, current, total); return STATE.CONTINUE; } @@ -247,16 +215,4 @@ private void fireOnThrowable(Throwable t) { } } } - - public static class TransferAdapter { - private final FluentCaseInsensitiveStringsMap headers; - - public TransferAdapter(FluentCaseInsensitiveStringsMap headers) { - this.headers = headers; - } - - public FluentCaseInsensitiveStringsMap getHeaders() { - return headers; - } - } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java b/api/src/main/java/org/asynchttpclient/spnego/SpnegoEngine.java similarity index 84% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java rename to api/src/main/java/org/asynchttpclient/spnego/SpnegoEngine.java index eeeb83365f..aa42c011aa 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoEngine.java +++ b/api/src/main/java/org/asynchttpclient/spnego/SpnegoEngine.java @@ -35,7 +35,7 @@ * . */ -package org.asynchttpclient.providers.netty4.spnego; +package org.asynchttpclient.spnego; import org.asynchttpclient.util.Base64; import org.ietf.jgss.GSSContext; @@ -49,9 +49,8 @@ import java.io.IOException; /** - * SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) authentication - * scheme. - * + * SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) authentication scheme. + * * @since 4.1 */ public class SpnegoEngine { @@ -70,8 +69,9 @@ public SpnegoEngine(final SpnegoTokenGenerator spnegoGenerator) { public SpnegoEngine() { this(null); } - + private static SpnegoEngine instance; + public static SpnegoEngine instance() { if (instance == null) instance = new SpnegoEngine(); @@ -85,17 +85,16 @@ public String generateToken(String server) throws Throwable { try { log.debug("init {}", server); - /* Using the SPNEGO OID is the correct method. - * Kerberos v5 works for IIS but not JBoss. Unwrapping - * the initial token when using SPNEGO OID looks like what is - * described here... - * + /* + * Using the SPNEGO OID is the correct method. Kerberos v5 works for IIS but not JBoss. Unwrapping the initial token when using SPNEGO OID looks like what is described + * here... + * * http://msdn.microsoft.com/en-us/library/ms995330.aspx - * + * * Another helpful URL... - * + * * http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tsec_SPNEGO_token.html - * + * * Unfortunately SPNEGO is JRE >=1.6. */ @@ -106,9 +105,7 @@ public String generateToken(String server) throws Throwable { try { GSSManager manager = GSSManager.getInstance(); GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE); - gssContext = manager.createContext( - serverName.canonicalize(negotiationOid), negotiationOid, null, - GSSContext.DEFAULT_LIFETIME); + gssContext = manager.createContext(serverName.canonicalize(negotiationOid), negotiationOid, null, GSSContext.DEFAULT_LIFETIME); gssContext.requestMutualAuth(true); gssContext.requestCredDeleg(true); } catch (GSSException ex) { @@ -124,14 +121,12 @@ public String generateToken(String server) throws Throwable { } if (tryKerberos) { - /* Kerberos v5 GSS-API mechanism defined in RFC 1964.*/ + /* Kerberos v5 GSS-API mechanism defined in RFC 1964. */ log.debug("Using Kerberos MECH {}", KERBEROS_OID); negotiationOid = new Oid(KERBEROS_OID); GSSManager manager = GSSManager.getInstance(); GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE); - gssContext = manager.createContext( - serverName.canonicalize(negotiationOid), negotiationOid, null, - GSSContext.DEFAULT_LIFETIME); + gssContext = manager.createContext(serverName.canonicalize(negotiationOid), negotiationOid, null, GSSContext.DEFAULT_LIFETIME); gssContext.requestMutualAuth(true); gssContext.requestCredDeleg(true); } @@ -147,8 +142,7 @@ public String generateToken(String server) throws Throwable { } /* - * IIS accepts Kerberos and SPNEGO tokens. Some other servers Jboss, Glassfish? - * seem to only accept SPNEGO. Below wraps Kerberos into SPNEGO token. + * IIS accepts Kerberos and SPNEGO tokens. Some other servers Jboss, Glassfish? seem to only accept SPNEGO. Below wraps Kerberos into SPNEGO token. */ if (spnegoGenerator != null && negotiationOid.toString().equals(KERBEROS_OID)) { token = spnegoGenerator.generateSpnegoDERObject(token); @@ -162,14 +156,11 @@ public String generateToken(String server) throws Throwable { return tokenstr; } catch (GSSException gsse) { log.error("generateToken", gsse); - if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL - || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED) + if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED) throw new Exception(gsse.getMessage(), gsse); if (gsse.getMajor() == GSSException.NO_CRED) throw new Exception(gsse.getMessage(), gsse); - if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN - || gsse.getMajor() == GSSException.DUPLICATE_TOKEN - || gsse.getMajor() == GSSException.OLD_TOKEN) + if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN || gsse.getMajor() == GSSException.DUPLICATE_TOKEN || gsse.getMajor() == GSSException.OLD_TOKEN) throw new Exception(gsse.getMessage(), gsse); // other error throw new Exception(gsse.getMessage()); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoTokenGenerator.java b/api/src/main/java/org/asynchttpclient/spnego/SpnegoTokenGenerator.java similarity index 97% rename from providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoTokenGenerator.java rename to api/src/main/java/org/asynchttpclient/spnego/SpnegoTokenGenerator.java index 20d6dcc1ad..ead1c19335 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoTokenGenerator.java +++ b/api/src/main/java/org/asynchttpclient/spnego/SpnegoTokenGenerator.java @@ -36,7 +36,7 @@ * */ -package org.asynchttpclient.providers.netty.spnego; +package org.asynchttpclient.spnego; import java.io.IOException; diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java index ef0dfacf51..49a340fde9 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncHttpClientTest.java @@ -18,6 +18,9 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.Future; import org.asynchttpclient.ByteArrayPart; @@ -40,11 +43,11 @@ public abstract class SimpleAsyncHttpClientTest extends AbstractBasicTest { @Test(groups = { "standalone", "default_provider" }) public void inpuStreamBodyConsumerTest() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100) + .setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes()))); - System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(response.getResponseBody(), MY_MESSAGE); @@ -56,12 +59,12 @@ public void inpuStreamBodyConsumerTest() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void stringBuilderBodyConsumerTest() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100) + .setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { StringBuilder s = new StringBuilder(); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new AppendableBodyConsumer(s)); - System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(s.toString(), MY_MESSAGE); @@ -73,12 +76,12 @@ public void stringBuilderBodyConsumerTest() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void byteArrayOutputStreamBodyConsumerTest() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100) + .setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 60 * 1000).setUrl(getTargetUrl()).setHeader("Content-Type", "text/html").build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); - System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); @@ -95,7 +98,6 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Exception { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.post(new InputStreamBodyGenerator(new ByteArrayInputStream(MY_MESSAGE.getBytes())), new OutputStreamBodyConsumer(o)); - System.out.println("waiting for response"); Response response = future.get(); assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); @@ -109,7 +111,8 @@ public void requestByteArrayOutputStreamBodyConsumerTest() throws Exception { */ @Test(groups = { "standalone", "default_provider" }, enabled = true) public void testPutZeroBytesFileTest() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100).setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain") + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setIdleConnectionInPoolTimeoutInMs(100) + .setMaximumConnectionsTotal(50).setRequestTimeoutInMs(5 * 1000).setUrl(getTargetUrl() + "/testPutZeroBytesFileTest.txt").setHeader("Content-Type", "text/plain") .build(); try { File tmpfile = File.createTempFile("testPutZeroBytesFile", ".tmp"); @@ -164,37 +167,66 @@ public void testDeriveOverrideURL() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testSimpleTransferListener() throws Exception { + final List errors = Collections.synchronizedList(new ArrayList()); + SimpleAHCTransferListener listener = new SimpleAHCTransferListener() { public void onStatus(String url, int statusCode, String statusText) { - assertEquals(statusCode, 200); - assertEquals(url, getTargetUrl()); + try { + assertEquals(statusCode, 200); + assertEquals(url, getTargetUrl()); + } catch (Error e) { + errors.add(e); + throw e; + } } public void onHeaders(String url, HeaderMap headers) { - assertEquals(url, getTargetUrl()); - assertNotNull(headers); - assertTrue(!headers.isEmpty()); - assertEquals(headers.getFirstValue("X-Custom"), "custom"); + try { + assertEquals(url, getTargetUrl()); + assertNotNull(headers); + assertTrue(!headers.isEmpty()); + assertEquals(headers.getFirstValue("X-Custom"), "custom"); + } catch (Error e) { + errors.add(e); + throw e; + } } public void onCompleted(String url, int statusCode, String statusText) { - assertEquals(statusCode, 200); - assertEquals(url, getTargetUrl()); + try { + assertEquals(statusCode, 200); + assertEquals(url, getTargetUrl()); + } catch (Error e) { + errors.add(e); + throw e; + } } public void onBytesSent(String url, long amount, long current, long total) { - assertEquals(url, getTargetUrl()); - assertEquals(total, MY_MESSAGE.getBytes().length); + try { + assertEquals(url, getTargetUrl()); + // FIXME Netty bug, see https://github.com/netty/netty/issues/1855 +// assertEquals(total, MY_MESSAGE.getBytes().length); + } catch (Error e) { + errors.add(e); + throw e; + } } public void onBytesReceived(String url, long amount, long current, long total) { - assertEquals(url, getTargetUrl()); - assertEquals(total, -1); + try { + assertEquals(url, getTargetUrl()); + assertEquals(total, -1); + } catch (Error e) { + errors.add(e); + throw e; + } } }; - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).setHeader("Custom", "custom").setListener(listener).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl()).setHeader("Custom", "custom") + .setListener(listener).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); @@ -204,6 +236,14 @@ public void onBytesReceived(String url, long amount, long current, long total) { Future future = client.post(generator, consumer); Response response = future.get(); + + if (!errors.isEmpty()) { + for (Error e : errors) { + e.printStackTrace(); + } + throw errors.get(0); + } + assertEquals(response.getStatusCode(), 200); assertEquals(o.toString(), MY_MESSAGE); } finally { @@ -220,7 +260,8 @@ public void testNullUrl() throws Exception { } catch (NullPointerException ex) { fail(); } finally { - if (client != null) client.close(); + if (client != null) + client.close(); } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index d2724f5925..0cd609ad8f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -25,7 +25,6 @@ import org.asynchttpclient.Response; import org.asynchttpclient.UpgradeHandler; import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.providers.grizzly.GrizzlyResponseFuture; import org.asynchttpclient.providers.grizzly.HttpTxContext; @@ -395,8 +394,7 @@ private static void initTransferCompletionHandler(final Request request, if (h instanceof TransferCompletionHandler) { final FluentCaseInsensitiveStringsMap map = new FluentCaseInsensitiveStringsMap(request.getHeaders()); - TransferCompletionHandler.class.cast(h) - .transferAdapter(new TransferAdapter(map)); + TransferCompletionHandler.class.cast(h).headers(map); } } diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 1e1cf573c8..8905736367 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -1,6 +1,5 @@ - + org.asynchttpclient async-http-client-providers-parent @@ -8,16 +7,44 @@ 4.0.0 async-http-client-netty-provider - Asynchronous Http Client Netty Provider + Asynchronous Http Client Netty 4 Provider - The Async Http Client Netty Provider. + The Async Http Client Netty 4 Provider. + + + sonatype-releases + https://oss.sonatype.org/content/repositories/releases + + true + + + false + + + + sonatype-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + false + + + true + + + + io.netty - netty - 3.7.0.Final + netty-all + 4.0.10.Final-SNAPSHOT + + + org.javassist + javassist + 3.18.0-GA diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java deleted file mode 100644 index 8c260cb25b..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyChunkedInput.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.Body; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.handler.stream.ChunkedInput; - -import java.nio.ByteBuffer; - -/** - * Adapts a {@link Body} to Netty's {@link ChunkedInput}. - */ -class BodyChunkedInput implements ChunkedInput { - - private static final int DEFAULT_CHUNK_SIZE = 8 * 1024; - - private final Body body; - private final int contentLength; - private final int chunkSize; - - private boolean endOfInput; - - public BodyChunkedInput(Body body) { - if (body == null) { - throw new IllegalArgumentException("no body specified"); - } - this.body = body; - contentLength = (int) body.getContentLength(); - if (contentLength <= 0) - chunkSize = DEFAULT_CHUNK_SIZE; - else - chunkSize = Math.min(contentLength, DEFAULT_CHUNK_SIZE); - } - - public boolean hasNextChunk() throws Exception { - // unused - throw new UnsupportedOperationException(); - } - - public Object nextChunk() throws Exception { - if (endOfInput) { - return null; - } else { - ByteBuffer buffer = ByteBuffer.allocate(chunkSize); - long r = body.read(buffer); - if (r < 0L) { - endOfInput = true; - return null; - } else { - endOfInput = r == contentLength || r < chunkSize && contentLength > 0; - buffer.flip(); - return ChannelBuffers.wrappedBuffer(buffer); - } - } - } - - public boolean isEndOfInput() throws Exception { - // called by ChunkedWriteHandler AFTER nextChunk - return endOfInput; - } - - public void close() throws Exception { - body.close(); - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyFileRegion.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyFileRegion.java deleted file mode 100644 index 68a271a4da..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/BodyFileRegion.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.RandomAccessBody; -import org.jboss.netty.channel.FileRegion; - -import java.io.IOException; -import java.nio.channels.WritableByteChannel; - -/** - * Adapts a {@link RandomAccessBody} to Netty's {@link FileRegion}. - */ -class BodyFileRegion - implements FileRegion { - - private final RandomAccessBody body; - - public BodyFileRegion(RandomAccessBody body) { - if (body == null) { - throw new IllegalArgumentException("no body specified"); - } - this.body = body; - } - - public long getPosition() { - return 0; - } - - public long getCount() { - return body.getContentLength(); - } - - public long transferTo(WritableByteChannel target, long position) - throws IOException { - return body.transferTo(position, Long.MAX_VALUE, target); - } - - public void releaseExternalResources() { - try { - body.close(); - } catch (IOException e) { - // we tried - } - } - -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Callback.java similarity index 72% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/Callback.java index 477f55feae..277b424e13 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Callback.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Callback.java @@ -1,4 +1,6 @@ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty; + +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; public abstract class Callback { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Constants.java similarity index 86% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/Constants.java index 1565673ff1..ede1d05e27 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Constants.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Constants.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty; import java.nio.charset.Charset; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/DiscardEvent.java similarity index 66% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/DiscardEvent.java index 6796d5bbc7..f18c40f962 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/DiscardEvent.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/DiscardEvent.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty; // Simple marker for stopping publishing bytes. public enum DiscardEvent { diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/FeedableBodyGenerator.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/FeedableBodyGenerator.java deleted file mode 100644 index 2c121c46bb..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/FeedableBodyGenerator.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicInteger; - -import org.asynchttpclient.Body; -import org.asynchttpclient.BodyGenerator; - -/** - * {@link BodyGenerator} which may return just part of the payload at the time - * handler is requesting it. If it happens - PartialBodyGenerator becomes responsible - * for finishing payload transferring asynchronously. - */ -public class FeedableBodyGenerator implements BodyGenerator { - private final static byte[] END_PADDING = "\r\n".getBytes(); - private final static byte[] ZERO = "0".getBytes(); - private final Queue queue = new ConcurrentLinkedQueue(); - private final AtomicInteger queueSize = new AtomicInteger(); - private FeedListener listener; - - @Override - public Body createBody() throws IOException { - return new PushBody(); - } - - public void feed(final ByteBuffer buffer, final boolean isLast) throws IOException { - queue.offer(new BodyPart(buffer, isLast)); - queueSize.incrementAndGet(); - if (listener != null) { - listener.onContentAdded(); - } - } - - public static interface FeedListener { - public void onContentAdded(); - } - - public void setListener(FeedListener listener) { - this.listener = listener; - } - - private final class PushBody implements Body { - private final int ONGOING = 0; - private final int CLOSING = 1; - private final int FINISHED = 2; - - private int finishState = 0; - - @Override - public long getContentLength() { - return -1; - } - - @Override - public long read(final ByteBuffer buffer) throws IOException { - BodyPart nextPart = queue.peek(); - if (nextPart == null) { - // Nothing in the queue - switch (finishState) { - case ONGOING: - return 0; - case CLOSING: - buffer.put(ZERO); - buffer.put(END_PADDING); - finishState = FINISHED; - return buffer.position(); - case FINISHED: - buffer.put(END_PADDING); - return -1; - } - } - int capacity = buffer.remaining() - 10; // be safe (we'll have to add size, ending, etc.) - int size = Math.min(nextPart.buffer.remaining(), capacity); - buffer.put(Integer.toHexString(size).getBytes()); - buffer.put(END_PADDING); - for (int i=0; i < size; i++) { - buffer.put(nextPart.buffer.get()); - } - buffer.put(END_PADDING); - if (!nextPart.buffer.hasRemaining()) { - if (nextPart.isLast) { - finishState = CLOSING; - } - queue.remove(); - } - return size; - } - - @Override - public void close() throws IOException { - } - - } - - private final static class BodyPart { - private final boolean isLast; - private final ByteBuffer buffer; - - public BodyPart(final ByteBuffer buffer, final boolean isLast) { - this.buffer = buffer; - this.isLast = isLast; - } - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index e6f97d738d..60656ffad2 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -15,2342 +15,73 @@ */ package org.asynchttpclient.providers.netty; +import java.io.IOException; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHandler.STATE; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.Body; -import org.asynchttpclient.BodyGenerator; -import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ConnectionsPool; -import org.asynchttpclient.Cookie; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseBodyPart; import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.MaxRedirectException; -import org.asynchttpclient.ProgressAsyncHandler; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.RandomAccessBody; -import org.asynchttpclient.Realm; import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.ResponseFilter; -import org.asynchttpclient.generators.InputStreamBodyGenerator; -import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; -import org.asynchttpclient.multipart.MultipartBody; -import org.asynchttpclient.multipart.MultipartRequestEntity; -import org.asynchttpclient.ntlm.NTLMEngine; -import org.asynchttpclient.ntlm.NTLMEngineException; -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieEncoder; -import org.asynchttpclient.providers.netty.FeedableBodyGenerator.FeedListener; -import org.asynchttpclient.providers.netty.spnego.SpnegoEngine; -import org.asynchttpclient.providers.netty.util.CleanupChannelGroup; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.util.AuthenticatorUtils; -import org.asynchttpclient.util.ProxyUtils; -import org.asynchttpclient.util.SslUtils; -import org.asynchttpclient.util.UTF8UrlEncoder; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.jboss.netty.bootstrap.ClientBootstrap; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.ChannelFutureProgressListener; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.ChannelStateEvent; -import org.jboss.netty.channel.DefaultChannelFuture; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.FileRegion; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.socket.ClientSocketChannelFactory; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; -import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; -import org.jboss.netty.handler.codec.PrematureChannelClosureException; -import org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer; -import org.jboss.netty.handler.codec.http.DefaultHttpRequest; -import org.jboss.netty.handler.codec.http.HttpChunk; -import org.jboss.netty.handler.codec.http.HttpChunkTrailer; -import org.jboss.netty.handler.codec.http.HttpClientCodec; -import org.jboss.netty.handler.codec.http.HttpContentCompressor; -import org.jboss.netty.handler.codec.http.HttpContentDecompressor; -import org.jboss.netty.handler.codec.http.HttpHeaders; -import org.jboss.netty.handler.codec.http.HttpMethod; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpRequestEncoder; -import org.jboss.netty.handler.codec.http.HttpResponse; -import org.jboss.netty.handler.codec.http.HttpResponseDecoder; -import org.jboss.netty.handler.codec.http.HttpVersion; -import org.jboss.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder; -import org.jboss.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder; -import org.jboss.netty.handler.codec.http.websocketx.WebSocketFrame; -import org.jboss.netty.handler.ssl.SslHandler; -import org.jboss.netty.handler.stream.ChunkedFile; -import org.jboss.netty.handler.stream.ChunkedWriteHandler; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.handler.NettyChannelHandler; +import org.asynchttpclient.providers.netty.request.NettyRequestSender; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.net.ssl.SSLEngine; - -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.net.ConnectException; -import java.net.InetSocketAddress; -import java.net.MalformedURLException; -import java.net.URI; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.FileChannel; -import java.nio.channels.WritableByteChannel; -import java.nio.charset.Charset; -import java.security.GeneralSecurityException; -import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Map.Entry; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.RejectedExecutionException; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; -import static org.asynchttpclient.util.DateUtil.millisTime; -import static org.asynchttpclient.util.MiscUtil.isNonEmpty; -import static org.jboss.netty.channel.Channels.pipeline; - -public class NettyAsyncHttpProvider extends SimpleChannelUpstreamHandler implements AsyncHttpProvider { - private final static String HTTP_HANDLER = "httpHandler"; - protected final static String SSL_HANDLER = "sslHandler"; - private final static String HTTPS = "https"; - private final static String HTTP = "http"; - private static final String WEBSOCKET = "ws"; - private static final String WEBSOCKET_SSL = "wss"; +public class NettyAsyncHttpProvider implements AsyncHttpProvider { - private final static Logger log = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); - private final static Charset UTF8 = Charset.forName("UTF-8"); + private static final Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); - private final ClientBootstrap plainBootstrap; - private final ClientBootstrap secureBootstrap; - private final ClientBootstrap webSocketBootstrap; - private final ClientBootstrap secureWebSocketBootstrap; - private final static int MAX_BUFFERED_BYTES = 8192; private final AsyncHttpClientConfig config; - private final AtomicBoolean isClose = new AtomicBoolean(false); - private final ClientSocketChannelFactory socketChannelFactory; - private final boolean allowReleaseSocketChannelFactory; - - private final ChannelGroup openChannels = new CleanupChannelGroup("asyncHttpClient") { - @Override - public boolean remove(Object o) { - boolean removed = super.remove(o); - if (removed && trackConnections) { - freeConnections.release(); - } - return removed; - } - }; - private final ConnectionsPool connectionsPool; - private Semaphore freeConnections = null; private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; - private boolean executeConnectAsync = true; - public static final ThreadLocal IN_IO_THREAD = new ThreadLocalBoolean(); - private final boolean trackConnections; - private final boolean useRawUrl; - private final static NTLMEngine ntlmEngine = new NTLMEngine(); - private static SpnegoEngine spnegoEngine = null; - private final Protocol httpProtocol = new HttpProtocol(); - private final Protocol webSocketProtocol = new WebSocketProtocol(); - private final boolean managedExecutorService; - private ExecutorService service; - - private static boolean isNTLM(List auth) { - return isNonEmpty(auth) && auth.get(0).startsWith("NTLM"); - } + private final AtomicBoolean closed = new AtomicBoolean(false); + private final Channels channels; + private final NettyRequestSender requestSender; + private final NettyChannelHandler channelHandler; public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { - if (config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig) { - asyncHttpProviderConfig = NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()); - } else { - asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); - } - service = config.executorService(); - managedExecutorService = (service == null); - if (service == null) { - service = AsyncHttpProviderUtils.createDefaultExecutorService(); - } - - if (asyncHttpProviderConfig.isUseBlockingIO()) { - socketChannelFactory = new OioClientSocketChannelFactory(service); - this.allowReleaseSocketChannelFactory = true; - } else { - // check if external NioClientSocketChannelFactory is defined - NioClientSocketChannelFactory scf = asyncHttpProviderConfig.getSocketChannelFactory(); - if (scf != null) { - this.socketChannelFactory = scf; - - // cannot allow releasing shared channel factory - this.allowReleaseSocketChannelFactory = false; - } else { - ExecutorService e = asyncHttpProviderConfig.getBossExecutorService(); - if (e == null) { - e = Executors.newCachedThreadPool(); - } - int numWorkers = config.getIoThreadMultiplier() * Runtime.getRuntime().availableProcessors(); - log.debug("Number of application's worker threads is {}", numWorkers); - socketChannelFactory = new NioClientSocketChannelFactory(e, service, numWorkers); - this.allowReleaseSocketChannelFactory = true; - } - } - plainBootstrap = new ClientBootstrap(socketChannelFactory); - secureBootstrap = new ClientBootstrap(socketChannelFactory); - webSocketBootstrap = new ClientBootstrap(socketChannelFactory); - secureWebSocketBootstrap = new ClientBootstrap(socketChannelFactory); this.config = config; + asyncHttpProviderConfig = config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig ? // + NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()) + : new NettyAsyncHttpProviderConfig(); - configureNetty(); - - // This is dangerous as we can't catch a wrong typed ConnectionsPool - ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); - if (cp == null && config.getAllowPoolingConnection()) { - cp = new NettyConnectionsPool(this); - } else if (cp == null) { - cp = new NonConnectionsPool(); - } - this.connectionsPool = cp; - - if (config.getMaxTotalConnections() != -1) { - trackConnections = true; - freeConnections = new Semaphore(config.getMaxTotalConnections()); - } else { - trackConnections = false; - } - - useRawUrl = config.isUseRawUrl(); + channels = new Channels(config, asyncHttpProviderConfig); + requestSender = new NettyRequestSender(closed, config, channels); + channelHandler = new NettyChannelHandler(config, requestSender, channels, closed); + channels.configure(channelHandler); } @Override public String toString() { - return String.format("NettyAsyncHttpProvider:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections() - freeConnections.availablePermits(), openChannels.toString(), connectionsPool.toString()); - } - - void configureNetty() { - if (asyncHttpProviderConfig != null) { - for (Entry entry : asyncHttpProviderConfig.propertiesSet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - plainBootstrap.setOption(key, value); - webSocketBootstrap.setOption(key, value); - secureBootstrap.setOption(key, value); - secureWebSocketBootstrap.setOption(key, value); - } - } - - plainBootstrap.setPipelineFactory(createPlainPipelineFactory()); - DefaultChannelFuture.setUseDeadLockChecker(false); - - if (asyncHttpProviderConfig != null) { - executeConnectAsync = config.isAsyncConnectMode(); - if (!executeConnectAsync) { - DefaultChannelFuture.setUseDeadLockChecker(true); - } - } - - webSocketBootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - /* @Override */ - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipeline(); - pipeline.addLast("http-decoder", new HttpResponseDecoder()); - pipeline.addLast("http-encoder", new HttpRequestEncoder()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - return pipeline; - } - }); - } - - protected HttpClientCodec newHttpClientCodec() { - if (asyncHttpProviderConfig != null) { - return new HttpClientCodec(asyncHttpProviderConfig.getMaxInitialLineLength(), asyncHttpProviderConfig.getMaxHeaderSize(), asyncHttpProviderConfig.getMaxChunkSize(), false); - - } else { - return new HttpClientCodec(); - } - } - - protected ChannelPipelineFactory createPlainPipelineFactory() { - return new ChannelPipelineFactory() { - - /* @Override */ - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipeline(); - - pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); - - if (config.getRequestCompressionLevel() > 0) { - pipeline.addLast("deflater", new HttpContentCompressor(config.getRequestCompressionLevel())); - } - - if (config.isCompressionEnabled()) { - pipeline.addLast("inflater", new HttpContentDecompressor()); - } - pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - return pipeline; - } - }; - } - - void constructSSLPipeline(final NettyConnectListener cl) { - - secureBootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - /* @Override */ - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - abort(cl.future(), ex); - } - - pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); - - if (config.isCompressionEnabled()) { - pipeline.addLast("inflater", new HttpContentDecompressor()); - } - pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - return pipeline; - } - }); - - secureWebSocketBootstrap.setPipelineFactory(new ChannelPipelineFactory() { - - /* @Override */ - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - abort(cl.future(), ex); - } - - pipeline.addLast("http-decoder", new HttpResponseDecoder()); - pipeline.addLast("http-encoder", new HttpRequestEncoder()); - pipeline.addLast("httpProcessor", NettyAsyncHttpProvider.this); - - return pipeline; - } - }); - } - - private Channel lookupInCache(URI uri, ConnectionPoolKeyStrategy connectionPoolKeyStrategy) { - final Channel channel = connectionsPool.poll(connectionPoolKeyStrategy.getKey(uri)); - - if (channel != null) { - log.debug("Using cached Channel {}\n for uri {}\n", channel, uri); - - try { - // Always make sure the channel who got cached support the proper protocol. It could - // only occurs when a HttpMethod.CONNECT is used against a proxy that require upgrading from http to - // https. - return verifyChannelPipeline(channel, uri.getScheme()); - } catch (Exception ex) { - log.debug(ex.getMessage(), ex); - } - } - return null; - } - - private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException { - SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine(); - if (sslEngine == null) { - sslEngine = SslUtils.getSSLEngine(); - } - return sslEngine; - } - - private Channel verifyChannelPipeline(Channel channel, String scheme) throws IOException, GeneralSecurityException { - - if (channel.getPipeline().get(SSL_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { - channel.getPipeline().remove(SSL_HANDLER); - } else if (channel.getPipeline().get(HTTP_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { - return channel; - } else if (channel.getPipeline().get(SSL_HANDLER) == null && isSecure(scheme)) { - channel.getPipeline().addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); - } - return channel; - } - - protected final void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture future, final HttpRequest nettyRequest) { - try { - /** - * If the channel is dead because it was pooled and the remote server decided to close it, we just let it go and the closeChannel do it's work. - */ - if (!channel.isOpen() || !channel.isConnected()) { - return; - } - - Body body = null; - if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { - BodyGenerator bg = future.getRequest().getBodyGenerator(); - if (bg != null) { - // Netty issue with chunking. - if (bg instanceof InputStreamBodyGenerator) { - InputStreamBodyGenerator.class.cast(bg).patchNettyChunkingIssue(true); - } - - try { - body = bg.createBody(); - } catch (IOException ex) { - throw new IllegalStateException(ex); - } - long length = body.getContentLength(); - if (length >= 0) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, length); - } else { - nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); - } - } else if (future.getRequest().getParts() != null) { - String contentType = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_TYPE); - String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH); - body = new MultipartBody(future.getRequest().getParts(), contentType, length); - } - } - - if (future.getAsyncHandler() instanceof TransferCompletionHandler) { - - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - for (String s : future.getNettyRequest().getHeaderNames()) { - for (String header : future.getNettyRequest().getHeaders(s)) { - h.add(s, header); - } - } - - TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new TransferAdapter(h)); - } - - // Leave it to true. - if (future.getAndSetWriteHeaders(true)) { - try { - channel.write(nettyRequest).addListener(new ProgressListener(true, future.getAsyncHandler(), future)); - } catch (Throwable cause) { - log.debug(cause.getMessage(), cause); - try { - channel.close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } - } - - if (future.getAndSetWriteBody(true)) { - if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) { - - if (future.getRequest().getFile() != null) { - final File file = future.getRequest().getFile(); - long fileLength = 0; - final RandomAccessFile raf = new RandomAccessFile(file, "r"); - - try { - fileLength = raf.length(); - - ChannelFuture writeFuture; - if (channel.getPipeline().get(SslHandler.class) != null) { - writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, MAX_BUFFERED_BYTES)); - } else { - final FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); - writeFuture = channel.write(region); - } - writeFuture.addListener(new ProgressListener(false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelFuture cf) { - try { - raf.close(); - } catch (IOException e) { - log.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - } catch (IOException ex) { - if (raf != null) { - try { - raf.close(); - } catch (IOException e) { - } - } - throw ex; - } - } else if (body != null) { - - ChannelFuture writeFuture; - if (channel.getPipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) { - BodyFileRegion bodyFileRegion = new BodyFileRegion((RandomAccessBody) body); - writeFuture = channel.write(bodyFileRegion); - } else { - BodyChunkedInput bodyChunkedInput = new BodyChunkedInput(body); - BodyGenerator bg = future.getRequest().getBodyGenerator(); - if (bg instanceof FeedableBodyGenerator) { - ((FeedableBodyGenerator) bg).setListener(new FeedListener() { - @Override - public void onContentAdded() { - channel.getPipeline().get(ChunkedWriteHandler.class).resumeTransfer(); - } - }); - } - writeFuture = channel.write(bodyChunkedInput); - } - - final Body b = body; - writeFuture.addListener(new ProgressListener(false, future.getAsyncHandler(), future) { - public void operationComplete(ChannelFuture cf) { - try { - b.close(); - } catch (IOException e) { - log.warn("Failed to close request body: {}", e.getMessage(), e); - } - super.operationComplete(cf); - } - }); - } - } - } - } catch (Throwable ioe) { - try { - channel.close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - } - - try { - future.touch(); - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, future.getRequest()); - int schedulePeriod = requestTimeout != -1 ? (config.getIdleConnectionTimeoutInMs() != -1 ? Math.min(requestTimeout, config.getIdleConnectionTimeoutInMs()) : requestTimeout) : config.getIdleConnectionTimeoutInMs(); - - if (schedulePeriod != -1 && !future.isDone() && !future.isCancelled()) { - ReaperFuture reaperFuture = new ReaperFuture(future); - Future scheduledFuture = config.reaper().scheduleAtFixedRate(reaperFuture, 0, schedulePeriod, TimeUnit.MILLISECONDS); - reaperFuture.setScheduledFuture(scheduledFuture); - future.setReaperFuture(reaperFuture); - } - } catch (RejectedExecutionException ex) { - abort(future, ex); - } - - } - - protected final static HttpRequest buildRequest(AsyncHttpClientConfig config, Request request, URI uri, boolean allowConnect, ChannelBuffer buffer, ProxyServer proxyServer) throws IOException { - - String method = request.getMethod(); - if (allowConnect && proxyServer != null && isSecure(uri)) { - method = HttpMethod.CONNECT.toString(); - } - return construct(config, request, new HttpMethod(method), uri, buffer, proxyServer); - } - - private static SpnegoEngine getSpnegoEngine() { - if (spnegoEngine == null) - spnegoEngine = new SpnegoEngine(); - return spnegoEngine; - } - - private static HttpRequest construct(AsyncHttpClientConfig config, Request request, HttpMethod m, URI uri, ChannelBuffer buffer, ProxyServer proxyServer) throws IOException { - - String host = null; - boolean webSocket = isWebSocket(uri); - - if (request.getVirtualHost() != null) { - host = request.getVirtualHost(); - } else { - host = AsyncHttpProviderUtils.getHost(uri); - } - - HttpRequest nettyRequest; - if (m.equals(HttpMethod.CONNECT)) { - nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_0, m, AsyncHttpProviderUtils.getAuthority(uri)); - } else { - String path = null; - if (proxyServer != null && !(isSecure(uri) && config.isUseRelativeURIsWithSSLProxies())) - path = uri.toString(); - else if (uri.getRawQuery() != null) - path = uri.getRawPath() + "?" + uri.getRawQuery(); - else - path = uri.getRawPath(); - nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, m, path); - } - - if (webSocket) { - nettyRequest.addHeader(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET); - nettyRequest.addHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.UPGRADE); - nettyRequest.addHeader(HttpHeaders.Names.ORIGIN, "http://" + uri.getHost() + ":" + (uri.getPort() == -1 ? isSecure(uri.getScheme()) ? 443 : 80 : uri.getPort())); - nettyRequest.addHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY, WebSocketUtil.getKey()); - nettyRequest.addHeader(HttpHeaders.Names.SEC_WEBSOCKET_VERSION, "13"); - } - - if (host != null) { - if (request.getVirtualHost() != null || uri.getPort() == -1) { - nettyRequest.setHeader(HttpHeaders.Names.HOST, host); - } else { - nettyRequest.setHeader(HttpHeaders.Names.HOST, host + ":" + uri.getPort()); - } - } else { - host = "127.0.0.1"; - } - - if (!m.equals(HttpMethod.CONNECT)) { - FluentCaseInsensitiveStringsMap h = request.getHeaders(); - if (h != null) { - for (Entry> header : h) { - String name = header.getKey(); - if (!HttpHeaders.Names.HOST.equalsIgnoreCase(name)) { - for (String value : header.getValue()) { - nettyRequest.addHeader(name, value); - } - } - } - } - - if (config.isCompressionEnabled()) { - nettyRequest.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); - } - } else { - List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (isNTLM(auth)) { - nettyRequest.addHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, auth.get(0)); - } - } - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - if (realm != null && realm.getUsePreemptiveAuth()) { - - String domain = realm.getNtlmDomain(); - if (proxyServer != null && proxyServer.getNtlmDomain() != null) { - domain = proxyServer.getNtlmDomain(); - } - - String authHost = realm.getNtlmHost(); - if (proxyServer != null && proxyServer.getHost() != null) { - host = proxyServer.getHost(); - } - - switch (realm.getAuthScheme()) { - case BASIC: - nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION, AuthenticatorUtils.computeBasicAuthentication(realm)); - break; - case DIGEST: - if (isNonEmpty(realm.getNonce())) { - try { - nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION, AuthenticatorUtils.computeDigestAuthentication(realm)); - } catch (NoSuchAlgorithmException e) { - throw new SecurityException(e); - } - } - break; - case NTLM: - try { - String msg = ntlmEngine.generateType1Msg("NTLM " + domain, authHost); - nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION, "NTLM " + msg); - } catch (NTLMEngineException e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - break; - case KERBEROS: - case SPNEGO: - String challengeHeader = null; - String server = proxyServer == null ? host : proxyServer.getHost(); - try { - challengeHeader = getSpnegoEngine().generateToken(server); - } catch (Throwable e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - nettyRequest.setHeader(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); - break; - case NONE: - break; - default: - throw new IllegalStateException("Invalid Authentication " + realm); - } - } - - if (!webSocket && !request.getHeaders().containsKey(HttpHeaders.Names.CONNECTION)) { - nettyRequest.setHeader(HttpHeaders.Names.CONNECTION, AsyncHttpProviderUtils.keepAliveHeaderValue(config)); - } - - if (proxyServer != null) { - if (!request.getHeaders().containsKey("Proxy-Connection")) { - nettyRequest.setHeader("Proxy-Connection", AsyncHttpProviderUtils.keepAliveHeaderValue(config)); - } - - if (proxyServer.getPrincipal() != null) { - if (isNonEmpty(proxyServer.getNtlmDomain())) { - - List auth = request.getHeaders().get(HttpHeaders.Names.PROXY_AUTHORIZATION); - if (!isNTLM(auth)) { - try { - String msg = ntlmEngine.generateType1Msg(proxyServer.getNtlmDomain(), proxyServer.getHost()); - nettyRequest.setHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + msg); - } catch (NTLMEngineException e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; - } - } - } else { - nettyRequest.setHeader(HttpHeaders.Names.PROXY_AUTHORIZATION, AuthenticatorUtils.computeBasicAuthentication(proxyServer)); - } - } - } - - // Add default accept headers. - if (request.getHeaders().getFirstValue(HttpHeaders.Names.ACCEPT) == null) { - nettyRequest.setHeader(HttpHeaders.Names.ACCEPT, "*/*"); - } - - String userAgentHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.USER_AGENT); - if (userAgentHeader != null) { - nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, userAgentHeader); - } else if (config.getUserAgent() != null) { - nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, config.getUserAgent()); - } else { - nettyRequest.setHeader(HttpHeaders.Names.USER_AGENT, AsyncHttpProviderUtils.constructUserAgent(NettyAsyncHttpProvider.class, config)); - } - - if (!m.equals(HttpMethod.CONNECT)) { - if (isNonEmpty(request.getCookies())) { - nettyRequest.setHeader(HttpHeaders.Names.COOKIE, CookieEncoder.encodeClientSide(request.getCookies(), config.isRfc6265CookieEncoding())); - } - - String reqType = request.getMethod(); - if (!"HEAD".equals(reqType) && !"OPTION".equals(reqType) && !"TRACE".equals(reqType)) { - - String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : request.getBodyEncoding(); - - // We already have processed the body. - if (buffer != null && buffer.writerIndex() != 0) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.writerIndex()); - nettyRequest.setContent(buffer); - } else if (request.getByteData() != null) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(request.getByteData().length)); - nettyRequest.setContent(ChannelBuffers.wrappedBuffer(request.getByteData())); - } else if (request.getStringData() != null) { - byte[] bytes = request.getStringData().getBytes(bodyCharset); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(bytes.length)); - nettyRequest.setContent(ChannelBuffers.wrappedBuffer(bytes)); - } else if (request.getStreamData() != null) { - int[] lengthWrapper = new int[1]; - // FIXME should be streaming instead! - byte[] bytes = AsyncHttpProviderUtils.readFully(request.getStreamData(), lengthWrapper); - int length = lengthWrapper[0]; - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(length)); - nettyRequest.setContent(ChannelBuffers.wrappedBuffer(bytes, 0, length)); - } else if (isNonEmpty(request.getParams())) { - StringBuilder sb = new StringBuilder(); - for (final Entry> paramEntry : request.getParams()) { - final String key = paramEntry.getKey(); - for (final String value : paramEntry.getValue()) { - if (sb.length() > 0) { - sb.append("&"); - } - UTF8UrlEncoder.appendEncoded(sb, key); - sb.append("="); - UTF8UrlEncoder.appendEncoded(sb, value); - } - } - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(sb.length())); - nettyRequest.setContent(ChannelBuffers.wrappedBuffer(sb.toString().getBytes(bodyCharset))); - - if (!request.getHeaders().containsKey(HttpHeaders.Names.CONTENT_TYPE)) { - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); - } - - } else if (request.getParts() != null) { - MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); - - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(mre.getContentLength())); - - } else if (request.getFile() != null) { - File file = request.getFile(); - if (!file.isFile()) { - throw new IOException(String.format("File %s is not a file or doesn't exist", file.getAbsolutePath())); - } - nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH, file.length()); - } - } - } - return nettyRequest; + return String.format("NettyAsyncHttpProvider4:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections() + - channels.freeConnections.availablePermits(), channels.openChannels.toString(), channels.connectionsPool.toString()); } + @Override public void close() { - isClose.set(true); + closed.set(true); try { - connectionsPool.destroy(); - openChannels.close(); - - for (Channel channel : openChannels) { - ChannelHandlerContext ctx = channel.getPipeline().getContext(NettyAsyncHttpProvider.class); - if (ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - future.setReaperFuture(null); - } - } - - if (managedExecutorService) { - service.shutdown(); - } + channels.close(); config.reaper().shutdown(); - if (this.allowReleaseSocketChannelFactory) { - socketChannelFactory.releaseExternalResources(); - plainBootstrap.releaseExternalResources(); - secureBootstrap.releaseExternalResources(); - webSocketBootstrap.releaseExternalResources(); - secureWebSocketBootstrap.releaseExternalResources(); - } } catch (Throwable t) { - log.warn("Unexpected error on close", t); + LOGGER.warn("Unexpected error on close", t); } } - /* @Override */ - + @Override public Response prepareResponse(final HttpResponseStatus status, final HttpResponseHeaders headers, final List bodyParts) { - return new NettyResponse(status, headers, bodyParts); - } - - /* @Override */ - - public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { - return doConnect(request, asyncHandler, null, true, executeConnectAsync, false); - } - - private void execute(final Request request, final NettyResponseFuture f, boolean useCache, boolean asyncConnect, boolean reclaimCache) throws IOException { - doConnect(request, f.getAsyncHandler(), f, useCache, asyncConnect, reclaimCache); - } - - private ListenableFuture doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture f, boolean useCache, boolean asyncConnect, boolean reclaimCache) throws IOException { - - if (isClose.get()) { - throw new IOException("Closed"); - } - - if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) { - throw new IOException("WebSocket method must be a GET"); - } - - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - boolean useProxy = proxyServer != null; - URI uri; - if (useRawUrl) { - uri = request.getRawURI(); - } else { - uri = request.getURI(); - } - Channel channel = null; - - if (useCache) { - if (f != null && f.reuseChannel() && f.channel() != null) { - channel = f.channel(); - } else { - URI connectionKeyUri = useProxy ? proxyServer.getURI() : uri; - channel = lookupInCache(connectionKeyUri, request.getConnectionPoolKeyStrategy()); - } - } - - ChannelBuffer bufferedBytes = null; - if (f != null && f.getRequest().getFile() == null && !f.getNettyRequest().getMethod().getName().equals(HttpMethod.CONNECT.getName())) { - bufferedBytes = f.getNettyRequest().getContent(); - } - - boolean useSSl = isSecure(uri) && !useProxy; - if (channel != null && channel.isOpen() && channel.isConnected()) { - HttpRequest nettyRequest = null; - - if (f == null) { - nettyRequest = buildRequest(config, request, uri, false, bufferedBytes, proxyServer); - f = newFuture(uri, request, asyncHandler, nettyRequest, config, this, proxyServer); - } else { - nettyRequest = buildRequest(config, request, uri, f.isConnectAllowed(), bufferedBytes, proxyServer); - f.setNettyRequest(nettyRequest); - } - f.setState(NettyResponseFuture.STATE.POOLED); - f.attachChannel(channel, false); - - log.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest); - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(f); - - try { - writeRequest(channel, config, f, nettyRequest); - } catch (Exception ex) { - log.debug("writeRequest failure", ex); - if (useSSl && ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) { - log.debug("SSLEngine failure", ex); - f = null; - } else { - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("doConnect.writeRequest()", t); - } - IOException ioe = new IOException(ex.getMessage()); - ioe.initCause(ex); - throw ioe; - } - } - return f; - } - - // Do not throw an exception when we need an extra connection for a redirect. - if (!reclaimCache && !connectionsPool.canCacheConnection()) { - IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("!connectionsPool.canCacheConnection()", t); - } - throw ex; - } - - boolean acquiredConnection = false; - - if (trackConnections) { - if (!reclaimCache) { - if (!freeConnections.tryAcquire()) { - IOException ex = new IOException("Too many connections " + config.getMaxTotalConnections()); - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - log.warn("!connectionsPool.canCacheConnection()", t); - } - throw ex; - } else { - acquiredConnection = true; - } - } - } - - NettyConnectListener c = new NettyConnectListener.Builder(config, request, asyncHandler, f, this, bufferedBytes).build(uri); - boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost()); - - if (useSSl) { - constructSSLPipeline(c); - } - - ChannelFuture channelFuture; - ClientBootstrap bootstrap = request.getUrl().startsWith(WEBSOCKET) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap : plainBootstrap); - bootstrap.setOption("connectTimeoutMillis", config.getConnectionTimeoutInMs()); - - try { - InetSocketAddress remoteAddress; - if (request.getInetAddress() != null) { - remoteAddress = new InetSocketAddress(request.getInetAddress(), AsyncHttpProviderUtils.getPort(uri)); - } else if (proxyServer == null || avoidProxy) { - remoteAddress = new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)); - } else { - remoteAddress = new InetSocketAddress(proxyServer.getHost(), proxyServer.getPort()); - } - - if (request.getLocalAddress() != null) { - channelFuture = bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); - } else { - channelFuture = bootstrap.connect(remoteAddress); - } - - } catch (Throwable t) { - if (acquiredConnection) { - freeConnections.release(); - } - abort(c.future(), t.getCause() == null ? t : t.getCause()); - return c.future(); - } - - boolean directInvokation = !(IN_IO_THREAD.get() && DefaultChannelFuture.isUseDeadLockChecker()); - - if (directInvokation && !asyncConnect && request.getFile() == null) { - int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; - if (!channelFuture.awaitUninterruptibly(timeOut, TimeUnit.MILLISECONDS)) { - if (acquiredConnection) { - freeConnections.release(); - } - channelFuture.cancel(); - abort(c.future(), new ConnectException(String.format("Connect operation to %s timeout %s", uri, timeOut))); - } - - try { - c.operationComplete(channelFuture); - } catch (Exception e) { - if (acquiredConnection) { - freeConnections.release(); - } - IOException ioe = new IOException(e.getMessage()); - ioe.initCause(e); - try { - asyncHandler.onThrowable(ioe); - } catch (Throwable t) { - log.warn("c.operationComplete()", t); - } - throw ioe; - } - } else { - channelFuture.addListener(c); - } - - log.debug("\nNon cached request \n{}\n\nusing Channel \n{}\n", c.future().getNettyRequest(), channelFuture.getChannel()); - - if (!c.future().isCancelled() || !c.future().isDone()) { - openChannels.add(channelFuture.getChannel()); - c.future().attachChannel(channelFuture.getChannel(), false); - } - return c.future(); - } - - private void closeChannel(final ChannelHandlerContext ctx) { - connectionsPool.removeAll(ctx.getChannel()); - finishChannel(ctx); - } - - private void finishChannel(final ChannelHandlerContext ctx) { - ctx.setAttachment(new DiscardEvent()); - - // The channel may have already been removed if a timeout occurred, and this method may be called just after. - if (ctx.getChannel() == null) { - return; - } - - log.debug("Closing Channel {} ", ctx.getChannel()); - - try { - ctx.getChannel().close(); - } catch (Throwable t) { - log.debug("Error closing a connection", t); - } - - if (ctx.getChannel() != null) { - openChannels.remove(ctx.getChannel()); - } - + throw new UnsupportedOperationException("Mocked, should be refactored"); } @Override - public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception { - // call super to reset the read timeout - super.messageReceived(ctx, e); - IN_IO_THREAD.set(Boolean.TRUE); - if (ctx.getAttachment() == null) { - log.debug("ChannelHandlerContext wasn't having any attachment"); - } - - if (ctx.getAttachment() instanceof DiscardEvent) { - return; - } else if (ctx.getAttachment() instanceof AsyncCallable) { - if (e.getMessage() instanceof HttpChunk) { - HttpChunk chunk = (HttpChunk) e.getMessage(); - if (chunk.isLast()) { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ac.call(); - } else { - return; - } - } else { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ac.call(); - } - ctx.setAttachment(new DiscardEvent()); - return; - } else if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { - try { - ctx.getChannel().close(); - } catch (Throwable t) { - log.trace("Closing an orphan channel {}", ctx.getChannel()); - } - return; - } - - Protocol p = (ctx.getPipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.handle(ctx, e); - } - - private Realm kerberosChallenge(List proxyAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, NettyResponseFuture future) throws NTLMEngineException { - - URI uri = request.getURI(); - String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost(); - String server = proxyServer == null ? host : proxyServer.getHost(); - try { - String challengeHeader = getSpnegoEngine().generateToken(server); - headers.remove(HttpHeaders.Names.AUTHORIZATION); - headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); - - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - return realmBuilder.setUri(uri.getRawPath()).setMethodName(request.getMethod()).setScheme(Realm.AuthScheme.KERBEROS).build(); - } catch (Throwable throwable) { - if (isNTLM(proxyAuth)) { - return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); - } - abort(future, throwable); - return null; - } - } - - private void addType3NTLMAuthorizationHeader(List auth, FluentCaseInsensitiveStringsMap headers, String username, String password, String domain, String workstation) - throws NTLMEngineException { - headers.remove(HttpHeaders.Names.AUTHORIZATION); - - if (isNTLM(auth)) { - String serverChallenge = auth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = ntlmEngine.generateType3Msg(username, password, domain, workstation, serverChallenge); - - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - } - } - - private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, NettyResponseFuture future) throws NTLMEngineException { - - boolean useRealm = (proxyServer == null && realm != null); - - String ntlmDomain = useRealm ? realm.getNtlmDomain() : proxyServer.getNtlmDomain(); - String ntlmHost = useRealm ? realm.getNtlmHost() : proxyServer.getHost(); - String principal = useRealm ? realm.getPrincipal() : proxyServer.getPrincipal(); - String password = useRealm ? realm.getPassword() : proxyServer.getPassword(); - - Realm newRealm; - if (realm != null && !realm.isNtlmMessageType2Received()) { - String challengeHeader = ntlmEngine.generateType1Msg(ntlmDomain, ntlmHost); - - URI uri = request.getURI(); - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(uri.getRawPath()).setMethodName(request.getMethod()).setNtlmMessageType2Received(true).build(); - future.getAndSetAuth(false); - } else { - addType3NTLMAuthorizationHeader(wwwAuth, headers, principal, password, ntlmDomain, ntlmHost); - - Realm.RealmBuilder realmBuilder; - Realm.AuthScheme authScheme; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - authScheme = realm.getAuthScheme(); - } else { - realmBuilder = new Realm.RealmBuilder(); - authScheme = Realm.AuthScheme.NTLM; - } - newRealm = realmBuilder.setScheme(authScheme).setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); - } - - return newRealm; - } - - private Realm ntlmProxyChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, NettyResponseFuture future) throws NTLMEngineException { - future.getAndSetAuth(false); - headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); - - addType3NTLMAuthorizationHeader(wwwAuth, headers, proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost()); - - Realm newRealm; - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - newRealm = realmBuilder// .setScheme(realm.getAuthScheme()) - .setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); - - return newRealm; - } - - private String getPoolKey(NettyResponseFuture future) throws MalformedURLException { - URI uri = future.getProxyServer() != null ? future.getProxyServer().getURI() : future.getURI(); - return future.getConnectionPoolKeyStrategy().getKey(uri); - } - - private void drainChannel(final ChannelHandlerContext ctx, final NettyResponseFuture future) { - ctx.setAttachment(new AsyncCallable(future) { - public Object call() throws Exception { - if (future.isKeepAlive() && ctx.getChannel().isReadable() && connectionsPool.offer(getPoolKey(future), ctx.getChannel())) { - return null; - } - - finishChannel(ctx); - return null; - } - - @Override - public String toString() { - return "Draining task for channel " + ctx.getChannel(); - } - }); - } - - private FilterContext handleIoException(FilterContext fc, NettyResponseFuture future) { - for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - } - return fc; - } - - private void replayRequest(final NettyResponseFuture future, FilterContext fc, HttpResponse response, ChannelHandlerContext ctx) throws IOException { - final Request newRequest = fc.getRequest(); - future.setAsyncHandler(fc.getAsyncHandler()); - future.setState(NettyResponseFuture.STATE.NEW); - future.touch(); - - log.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); - drainChannel(ctx, future); - nextRequest(newRequest, future); - return; - } - - private List getAuthorizationToken(List> list, String headerAuth) { - ArrayList l = new ArrayList(); - for (Entry e : list) { - if (e.getKey().equalsIgnoreCase(headerAuth)) { - l.add(e.getValue().trim()); - } - } - return l; - } - - private void nextRequest(final Request request, final NettyResponseFuture future) throws IOException { - nextRequest(request, future, true); - } - - private void nextRequest(final Request request, final NettyResponseFuture future, final boolean useCache) throws IOException { - execute(request, future, useCache, true, true); - } - - private void abort(NettyResponseFuture future, Throwable t) { - Channel channel = future.channel(); - if (channel != null && openChannels.contains(channel)) { - closeChannel(channel.getPipeline().getContext(NettyAsyncHttpProvider.class)); - openChannels.remove(channel); - } - - if (!future.isCancelled() && !future.isDone()) { - log.debug("Aborting Future {}\n", future); - log.debug(t.getMessage(), t); - } - - future.abort(t); - } - - private void upgradeProtocol(ChannelPipeline p, String scheme) throws IOException, GeneralSecurityException { - if (p.get(HTTP_HANDLER) != null) { - p.remove(HTTP_HANDLER); - } - - if (isSecure(scheme)) { - if (p.get(SSL_HANDLER) == null) { - p.addFirst(HTTP_HANDLER, newHttpClientCodec()); - p.addFirst(SSL_HANDLER, new SslHandler(createSSLEngine())); - } else { - p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec()); - } - - } else { - p.addFirst(HTTP_HANDLER, newHttpClientCodec()); - } - } - - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - - if (isClose.get()) { - return; - } - - connectionsPool.removeAll(ctx.getChannel()); - try { - super.channelClosed(ctx, e); - } catch (Exception ex) { - log.trace("super.channelClosed", ex); - } - - log.debug("Channel Closed: {} with attachment {}", e.getChannel(), ctx.getAttachment()); - - if (ctx.getAttachment() instanceof AsyncCallable) { - AsyncCallable ac = (AsyncCallable) ctx.getAttachment(); - ctx.setAttachment(ac.future()); - ac.call(); - return; - } - - if (ctx.getAttachment() instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - future.touch(); - - if (!config.getIOExceptionFilters().isEmpty()) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest() && !future.cannotBeReplay()) { - replayRequest(future, fc, null, ctx); - return; - } - } - - Protocol p = (ctx.getPipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onClose(ctx, e); - - if (future != null && !future.isDone() && !future.isCancelled()) { - if (remotelyClosed(ctx.getChannel(), future)) { - abort(future, new IOException("Remotely Closed")); - } - } else { - closeChannel(ctx); - } - } - } - - protected boolean remotelyClosed(Channel channel, NettyResponseFuture future) { - - if (isClose.get()) { - return true; - } - - connectionsPool.removeAll(channel); - - if (future == null) { - Object attachment = channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); - if (attachment instanceof NettyResponseFuture) - future = (NettyResponseFuture) attachment; - } - - if (future == null || future.cannotBeReplay()) { - log.debug("Unable to recover future {}\n", future); - return true; - } - - future.setState(NettyResponseFuture.STATE.RECONNECTED); - future.getAndSetStatusReceived(false); - - log.debug("Trying to recover request {}\n", future.getNettyRequest()); - - try { - nextRequest(future.getRequest(), future); - return false; - } catch (IOException iox) { - future.setState(NettyResponseFuture.STATE.CLOSED); - future.abort(iox); - log.error("Remotely Closed, unable to recover", iox); - } - return true; - } - - private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { - // We need to make sure everything is OK before adding the connection back to the pool. - try { - future.done(); - } catch (Throwable t) { - // Never propagate exception once we know we are done. - log.debug(t.getMessage(), t); - } - - if (!future.isKeepAlive() || !ctx.getChannel().isReadable()) { - closeChannel(ctx); - } - } - - private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { - if (lastValidChunk && future.isKeepAlive()) { - drainChannel(ctx, future); - } else { - if (future.isKeepAlive() && ctx.getChannel().isReadable() && connectionsPool.offer(getPoolKey(future), ctx.getChannel())) { - markAsDone(future, ctx); - return; - } - finishChannel(ctx); - } - markAsDone(future, ctx); - } - - private final boolean updateStatusAndInterrupt(AsyncHandler handler, HttpResponseStatus c) throws Exception { - return handler.onStatusReceived(c) != STATE.CONTINUE; - } - - private final boolean updateHeadersAndInterrupt(AsyncHandler handler, HttpResponseHeaders c) throws Exception { - return handler.onHeadersReceived(c) != STATE.CONTINUE; - } - - private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { - boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; - if (c.closeUnderlyingConnection()) { - future.setKeepAlive(false); - } - return state; - } - - // Simple marker for stopping publishing bytes. - - final static class DiscardEvent { - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - Channel channel = e.getChannel(); - Throwable cause = e.getCause(); - NettyResponseFuture future = null; - - if (e.getCause() instanceof PrematureChannelClosureException) { - return; - } - - if (log.isDebugEnabled()) { - log.debug("Unexpected I/O exception on channel {}", channel, cause); - } - - try { - - if (cause instanceof ClosedChannelException) { - return; - } - - if (ctx.getAttachment() instanceof NettyResponseFuture) { - future = (NettyResponseFuture) ctx.getAttachment(); - future.attachChannel(null, false); - future.touch(); - - if (cause instanceof IOException) { - - if (!config.getIOExceptionFilters().isEmpty()) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(new IOException("Channel Closed")).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest()) { - replayRequest(future, fc, null, ctx); - return; - } - } else { - // Close the channel so the recovering can occurs. - try { - ctx.getChannel().close(); - } catch (Throwable t) { - ; // Swallow. - } - return; - } - } - - if (abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) { - log.debug("Trying to recover from dead Channel: {}", channel); - return; - } - } else if (ctx.getAttachment() instanceof AsyncCallable) { - future = ((AsyncCallable) ctx.getAttachment()).future(); - } - } catch (Throwable t) { - cause = t; - } - - if (future != null) { - try { - log.debug("Was unable to recover Future: {}", future); - abort(future, cause); - } catch (Throwable t) { - log.error(t.getMessage(), t); - } - } - - Protocol p = (ctx.getPipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onError(ctx, e); - - closeChannel(ctx); - ctx.sendUpstream(e); - } - - protected static boolean abortOnConnectCloseException(Throwable cause) { - try { - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketChannelImpl") && element.getMethodName().equals("checkConnect")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnConnectCloseException(cause.getCause()); - } - - } catch (Throwable t) { - } - return false; - } - - protected static boolean abortOnDisconnectException(Throwable cause) { - try { - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("org.jboss.netty.handler.ssl.SslHandler") && element.getMethodName().equals("channelDisconnected")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnConnectCloseException(cause.getCause()); - } - - } catch (Throwable t) { - } - return false; - } - - protected static boolean abortOnReadCloseException(Throwable cause) { - - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") && element.getMethodName().equals("read")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnReadCloseException(cause.getCause()); - } - - return false; - } - - protected static boolean abortOnWriteCloseException(Throwable cause) { - - for (StackTraceElement element : cause.getStackTrace()) { - if (element.getClassName().equals("sun.nio.ch.SocketDispatcher") && element.getMethodName().equals("write")) { - return true; - } - } - - if (cause.getCause() != null) { - return abortOnReadCloseException(cause.getCause()); - } - - return false; - } - - private final static int getPredefinedContentLength(Request request, HttpRequest r) { - int length = (int) request.getContentLength(); - if (length == -1 && r.getHeader(HttpHeaders.Names.CONTENT_LENGTH) != null) { - length = Integer.valueOf(r.getHeader(HttpHeaders.Names.CONTENT_LENGTH)); - } - - return length; - } - - public static NettyResponseFuture newFuture(URI uri, Request request, AsyncHandler asyncHandler, HttpRequest nettyRequest, AsyncHttpClientConfig config, NettyAsyncHttpProvider provider, ProxyServer proxyServer) { - - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); - NettyResponseFuture f = new NettyResponseFuture(uri,// - request,// - asyncHandler,// - nettyRequest,// - requestTimeout,// - config.getIdleConnectionTimeoutInMs(),// - provider,// - request.getConnectionPoolKeyStrategy(),// - proxyServer); - - String expectHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT); - if (expectHeader != null && expectHeader.equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) { - f.getAndSetWriteBody(false); - } - return f; - } - - private class ProgressListener implements ChannelFutureProgressListener { - - private final boolean notifyHeaders; - private final AsyncHandler asyncHandler; - private final NettyResponseFuture future; - - public ProgressListener(boolean notifyHeaders, AsyncHandler asyncHandler, NettyResponseFuture future) { - this.notifyHeaders = notifyHeaders; - this.asyncHandler = asyncHandler; - this.future = future; - } - - public void operationComplete(ChannelFuture cf) { - // The write operation failed. If the channel was cached, it means it got asynchronously closed. - // Let's retry a second time. - Throwable cause = cf.getCause(); - if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) { - - if (cause instanceof IllegalStateException) { - log.debug(cause.getMessage(), cause); - try { - cf.getChannel().close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } - - if (cause instanceof ClosedChannelException || abortOnReadCloseException(cause) || abortOnWriteCloseException(cause)) { - - if (log.isDebugEnabled()) { - log.debug(cf.getCause() == null ? "" : cf.getCause().getMessage(), cf.getCause()); - } - - try { - cf.getChannel().close(); - } catch (RuntimeException ex) { - log.debug(ex.getMessage(), ex); - } - return; - } else { - future.abort(cause); - } - return; - } - future.touch(); - - /** - * We need to make sure we aren't in the middle of an authorization process before publishing events as we will re-publish again the same event after the authorization, causing unpredictable behavior. - */ - Realm realm = future.getRequest().getRealm() != null ? future.getRequest().getRealm() : NettyAsyncHttpProvider.this.getConfig().getRealm(); - boolean startPublishing = future.isInAuth() || realm == null || realm.getUsePreemptiveAuth() == true; - - if (startPublishing && asyncHandler instanceof ProgressAsyncHandler) { - if (notifyHeaders) { - ProgressAsyncHandler.class.cast(asyncHandler).onHeaderWriteCompleted(); - } else { - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteCompleted(); - } - } - } - - public void operationProgressed(ChannelFuture cf, long amount, long current, long total) { - future.touch(); - if (asyncHandler instanceof ProgressAsyncHandler) { - ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(amount, current, total); - } - } - } - - /** - * Because some implementation of the ThreadSchedulingService do not clean up cancel task until they try to run them, we wrap the task with the future so the when the NettyResponseFuture cancel the reaper future this wrapper will release the references to the channel and the - * nettyResponseFuture immediately. Otherwise, the memory referenced this way will only be released after the request timeout period which can be arbitrary long. - */ - private final class ReaperFuture implements Future, Runnable { - private Future scheduledFuture; - private NettyResponseFuture nettyResponseFuture; - - public ReaperFuture(NettyResponseFuture nettyResponseFuture) { - this.nettyResponseFuture = nettyResponseFuture; - } - - public void setScheduledFuture(Future scheduledFuture) { - this.scheduledFuture = scheduledFuture; - } - - /** - * @Override - */ - public boolean cancel(boolean mayInterruptIfRunning) { - nettyResponseFuture = null; - return scheduledFuture.cancel(mayInterruptIfRunning); - } - - /** - * @Override - */ - public Object get() throws InterruptedException, ExecutionException { - return scheduledFuture.get(); - } - - /** - * @Override - */ - public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - return scheduledFuture.get(timeout, unit); - } - - /** - * @Override - */ - public boolean isCancelled() { - return scheduledFuture.isCancelled(); - } - - /** - * @Override - */ - public boolean isDone() { - return scheduledFuture.isDone(); - } - - private void expire(String message) { - log.debug("{} for {}", message, nettyResponseFuture); - abort(nettyResponseFuture, new TimeoutException(message)); - nettyResponseFuture = null; - } - - /** - * @Override - */ - public synchronized void run() { - if (isClose.get()) { - cancel(true); - return; - } - - boolean futureDone = nettyResponseFuture.isDone(); - boolean futureCanceled = nettyResponseFuture.isCancelled(); - - if (nettyResponseFuture != null && !futureDone && !futureCanceled) { - long now = millisTime(); - if (nettyResponseFuture.hasRequestTimedOut(now)) { - long age = now - nettyResponseFuture.getStart(); - expire("Request reached time out of " + nettyResponseFuture.getRequestTimeoutInMs() + " ms after " + age + " ms"); - } else if (nettyResponseFuture.hasConnectionIdleTimedOut(now)) { - long age = now - nettyResponseFuture.getStart(); - expire("Request reached idle time out of " + nettyResponseFuture.getIdleConnectionTimeoutInMs() + " ms after " + age + " ms"); - } - - } else if (nettyResponseFuture == null || futureDone || futureCanceled) { - cancel(true); - } - } - } - - private abstract class AsyncCallable implements Callable { - - private final NettyResponseFuture future; - - public AsyncCallable(NettyResponseFuture future) { - this.future = future; - } - - abstract public Object call() throws Exception; - - public NettyResponseFuture future() { - return future; - } - } - - public static class ThreadLocalBoolean extends ThreadLocal { - - private final boolean defaultValue; - - public ThreadLocalBoolean() { - this(false); - } - - public ThreadLocalBoolean(boolean defaultValue) { - this.defaultValue = defaultValue; - } - - @Override - protected Boolean initialValue() { - return defaultValue ? Boolean.TRUE : Boolean.FALSE; - } - } - - public static class OptimizedFileRegion implements FileRegion { - - private final FileChannel file; - private final RandomAccessFile raf; - private final long position; - private final long count; - private long byteWritten; - - public OptimizedFileRegion(RandomAccessFile raf, long position, long count) { - this.raf = raf; - this.file = raf.getChannel(); - this.position = position; - this.count = count; - } - - public long getPosition() { - return position; - } - - public long getCount() { - return count; - } - - public long transferTo(WritableByteChannel target, long position) throws IOException { - long count = this.count - position; - if (count < 0 || position < 0) { - throw new IllegalArgumentException("position out of range: " + position + " (expected: 0 - " + (this.count - 1) + ")"); - } - if (count == 0) { - return 0L; - } - - long bw = file.transferTo(this.position + position, count, target); - byteWritten += bw; - if (byteWritten == raf.length()) { - releaseExternalResources(); - } - return bw; - } - - public void releaseExternalResources() { - try { - file.close(); - } catch (IOException e) { - log.warn("Failed to close a file.", e); - } - - try { - raf.close(); - } catch (IOException e) { - log.warn("Failed to close a file.", e); - } - } - } - - protected AsyncHttpClientConfig getConfig() { - return config; - } - - private static class NonConnectionsPool implements ConnectionsPool { - - public boolean offer(String uri, Channel connection) { - return false; - } - - public Channel poll(String uri) { - return null; - } - - public boolean removeAll(Channel connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - } - } - - private static final boolean validateWebSocketRequest(Request request, AsyncHandler asyncHandler) { - if (request.getMethod() != "GET" || !(asyncHandler instanceof WebSocketUpgradeHandler)) { - return false; - } - return true; - } - - private boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { - - int statusCode = response.getStatus().getCode(); - boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); - if (redirectEnabled && (statusCode == 302 || statusCode == 301 || statusCode == 303 || statusCode == 307)) { - - if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { - // We must allow 401 handling again. - future.getAndSetAuth(false); - - String location = response.getHeader(HttpHeaders.Names.LOCATION); - URI uri = AsyncHttpProviderUtils.getRedirectUri(future.getURI(), location); - boolean stripQueryString = config.isRemoveQueryParamOnRedirect(); - if (!uri.toString().equals(future.getURI().toString())) { - final RequestBuilder nBuilder = stripQueryString ? new RequestBuilder(future.getRequest()).setQueryParameters(null) : new RequestBuilder(future.getRequest()); - - if (!(statusCode < 302 || statusCode > 303) && !(statusCode == 302 && config.isStrict302Handling())) { - nBuilder.setMethod("GET"); - } - final boolean initialConnectionKeepAlive = future.isKeepAlive(); - final String initialPoolKey = getPoolKey(future); - future.setURI(uri); - String newUrl = uri.toString(); - if (request.getUrl().startsWith(WEBSOCKET)) { - newUrl = newUrl.replace(HTTP, WEBSOCKET); - } - - log.debug("Redirecting to {}", newUrl); - for (String cookieStr : future.getHttpResponse().getHeaders(HttpHeaders.Names.SET_COOKIE)) { - for (Cookie c : CookieDecoder.decode(cookieStr)) { - nBuilder.addOrReplaceCookie(c); - } - } - - for (String cookieStr : future.getHttpResponse().getHeaders(HttpHeaders.Names.SET_COOKIE2)) { - for (Cookie c : CookieDecoder.decode(cookieStr)) { - nBuilder.addOrReplaceCookie(c); - } - } - - AsyncCallable ac = new AsyncCallable(future) { - public Object call() throws Exception { - if (initialConnectionKeepAlive && ctx.getChannel().isReadable() && connectionsPool.offer(initialPoolKey, ctx.getChannel())) { - return null; - } - finishChannel(ctx); - return null; - } - }; - - if (response.isChunked()) { - // We must make sure there is no bytes left before executing the next request. - ctx.setAttachment(ac); - } else { - ac.call(); - } - nextRequest(nBuilder.setUrl(newUrl).build(), future); - return true; - } - } else { - throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); - } - } - return false; - } - - private final class HttpProtocol implements Protocol { - // @Override - public void handle(final ChannelHandlerContext ctx, final MessageEvent e) throws Exception { - final NettyResponseFuture future = (NettyResponseFuture) ctx.getAttachment(); - future.touch(); - - // The connect timeout occured. - if (future.isCancelled() || future.isDone()) { - finishChannel(ctx); - return; - } - - HttpRequest nettyRequest = future.getNettyRequest(); - AsyncHandler handler = future.getAsyncHandler(); - Request request = future.getRequest(); - ProxyServer proxyServer = future.getProxyServer(); - HttpResponse response = null; - try { - if (e.getMessage() instanceof HttpResponse) { - response = (HttpResponse) e.getMessage(); - - log.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); - - // Required if there is some trailing headers. - future.setHttpResponse(response); - - int statusCode = response.getStatus().getCode(); - - String ka = response.getHeader(HttpHeaders.Names.CONNECTION); - future.setKeepAlive(ka == null || !ka.toLowerCase(Locale.ENGLISH).equals("close")); - - List wwwAuth = getAuthorizationToken(response.getHeaders(), HttpHeaders.Names.WWW_AUTHENTICATE); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - HttpResponseStatus status = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response, NettyAsyncHttpProvider.this); - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(request).responseStatus(status).responseHeaders(responseHeaders).build(); - - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - } - - // The handler may have been wrapped. - handler = fc.getAsyncHandler(); - future.setAsyncHandler(handler); - - // The request has changed - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - - Realm newRealm = null; - final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); - final RequestBuilder builder = new RequestBuilder(future.getRequest()); - - // if (realm != null && !future.getURI().getPath().equalsIgnoreCase(realm.getUri())) { - // builder.setUrl(future.getURI().toString()); - // } - - if (statusCode == 401 && realm != null && !wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { - - future.setState(NettyResponseFuture.STATE.NEW); - // NTLM - if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || (wwwAuth.contains("Negotiate")))) { - newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (wwwAuth.contains("Negotiate")) { - newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) - return; - } else { - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()).setMethodName(request.getMethod()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); - } - - final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); - - log.debug("Sending authentication to {}", request.getUrl()); - AsyncCallable ac = new AsyncCallable(future) { - public Object call() throws Exception { - drainChannel(ctx, future); - nextRequest(builder.setHeaders(headers).setRealm(nr).build(), future); - return null; - } - }; - - if (future.isKeepAlive() && response.isChunked()) { - // We must make sure there is no bytes left before executing the next request. - ctx.setAttachment(ac); - } else { - ac.call(); - } - return; - } - - if (statusCode == 100) { - future.getAndSetWriteHeaders(false); - future.getAndSetWriteBody(true); - writeRequest(ctx.getChannel(), config, future, nettyRequest); - return; - } - - List proxyAuth = getAuthorizationToken(response.getHeaders(), HttpHeaders.Names.PROXY_AUTHENTICATE); - if (statusCode == 407 && realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { - - log.debug("Sending proxy authentication to {}", request.getUrl()); - - future.setState(NettyResponseFuture.STATE.NEW); - - if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || (proxyAuth.contains("Negotiate")))) { - newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (proxyAuth.contains("Negotiate")) { - newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) - return; - } else { - newRealm = future.getRequest().getRealm(); - } - - Request req = builder.setHeaders(headers).setRealm(newRealm).build(); - future.setReuseChannel(true); - future.setConnectAllowed(true); - nextRequest(req, future); - return; - } - - if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) && statusCode == 200) { - - log.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); - - if (future.isKeepAlive()) { - future.attachChannel(ctx.getChannel(), true); - } - - try { - log.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); - upgradeProtocol(ctx.getChannel().getPipeline(), request.getURI().getScheme()); - } catch (Throwable ex) { - abort(future, ex); - } - Request req = builder.build(); - future.setReuseChannel(true); - future.setConnectAllowed(false); - nextRequest(req, future); - return; - } - - if (redirect(request, future, response, ctx)) - return; - - if (!future.getAndSetStatusReceived(true) && updateStatusAndInterrupt(handler, status)) { - finishUpdate(future, ctx, response.isChunked()); - return; - } else if (updateHeadersAndInterrupt(handler, responseHeaders)) { - finishUpdate(future, ctx, response.isChunked()); - return; - } else if (!response.isChunked()) { - if (response.getContent().readableBytes() != 0) { - updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), response, NettyAsyncHttpProvider.this, true)); - } - finishUpdate(future, ctx, false); - return; - } - - if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) { - updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), response, NettyAsyncHttpProvider.this, true)); - markAsDone(future, ctx); - drainChannel(ctx, future); - } - - } else if (e.getMessage() instanceof HttpChunk) { - HttpChunk chunk = (HttpChunk) e.getMessage(); - - if (handler != null) { - if (chunk.isLast() || updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), null, NettyAsyncHttpProvider.this, chunk, chunk.isLast()))) { - if (chunk instanceof DefaultHttpChunkTrailer) { - updateHeadersAndInterrupt(handler, new ResponseHeaders(future.getURI(), future.getHttpResponse(), NettyAsyncHttpProvider.this, (HttpChunkTrailer) chunk)); - } - finishUpdate(future, ctx, !chunk.isLast()); - } - } - } - } catch (Exception t) { - if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty()) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(IOException.class.cast(t)).build(); - fc = handleIoException(fc, future); - - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - } - - try { - abort(future, t); - } finally { - finishUpdate(future, ctx, false); - throw t; - } - } - } - - // @Override - public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { - } - - // @Override - public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { - } - } - - private final class WebSocketProtocol implements Protocol { - private static final byte OPCODE_CONT = 0x0; - private static final byte OPCODE_TEXT = 0x1; - private static final byte OPCODE_BINARY = 0x2; - private static final byte OPCODE_UNKNOWN = -1; - protected byte pendingOpcode = OPCODE_UNKNOWN; - - // We don't need to synchronize as replacing the "ws-decoder" will process using the same thread. - private void invokeOnSucces(ChannelHandlerContext ctx, WebSocketUpgradeHandler h) { - if (!h.touchSuccess()) { - try { - h.onSuccess(new NettyWebSocket(ctx.getChannel())); - } catch (Exception ex) { - NettyAsyncHttpProvider.log.warn("onSuccess unexexpected exception", ex); - } - } - } - - // @Override - public void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - NettyResponseFuture future = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler()); - Request request = future.getRequest(); - - if (e.getMessage() instanceof HttpResponse) { - HttpResponse response = (HttpResponse) e.getMessage(); - - HttpResponseStatus s = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response, NettyAsyncHttpProvider.this); - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(h).request(request).responseStatus(s).responseHeaders(responseHeaders).build(); - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - abort(future, efe); - } - - } - - // The handler may have been wrapped. - future.setAsyncHandler(fc.getAsyncHandler()); - - // The request has changed - if (fc.replayRequest()) { - replayRequest(future, fc, response, ctx); - return; - } - - future.setHttpResponse(response); - if (redirect(request, future, response, ctx)) - return; - - final org.jboss.netty.handler.codec.http.HttpResponseStatus status = new org.jboss.netty.handler.codec.http.HttpResponseStatus(101, "Web Socket Protocol Handshake"); - - final boolean validStatus = response.getStatus().equals(status); - final boolean validUpgrade = response.getHeader(HttpHeaders.Names.UPGRADE) != null; - String c = response.getHeader(HttpHeaders.Names.CONNECTION); - if (c == null) { - c = response.getHeader(HttpHeaders.Names.CONNECTION.toLowerCase(Locale.ENGLISH)); - } - - final boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); - - s = new ResponseStatus(future.getURI(), response, NettyAsyncHttpProvider.this); - final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; - - final boolean headerOK = h.onHeadersReceived(responseHeaders) == STATE.CONTINUE; - if (!headerOK || !validStatus || !validUpgrade || !validConnection || !statusReceived) { - abort(future, new IOException("Invalid handshake response")); - return; - } - - String accept = response.getHeader(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT); - String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().getHeader(HttpHeaders.Names.SEC_WEBSOCKET_KEY)); - if (accept == null || !accept.equals(key)) { - throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); - } - - ctx.getPipeline().replace("http-encoder", "ws-encoder", new WebSocket08FrameEncoder(true)); - ctx.getPipeline().get(HttpResponseDecoder.class).replace("ws-decoder", new WebSocket08FrameDecoder(false, false)); - - invokeOnSucces(ctx, h); - future.done(); - } else if (e.getMessage() instanceof WebSocketFrame) { - - invokeOnSucces(ctx, h); - - final WebSocketFrame frame = (WebSocketFrame) e.getMessage(); - - if (frame instanceof TextWebSocketFrame) { - pendingOpcode = OPCODE_TEXT; - } else if (frame instanceof BinaryWebSocketFrame) { - pendingOpcode = OPCODE_BINARY; - } - - HttpChunk webSocketChunk = new HttpChunk() { - private ChannelBuffer content; - - // @Override - public boolean isLast() { - return false; - } - - // @Override - public ChannelBuffer getContent() { - return content; - } - - // @Override - public void setContent(ChannelBuffer content) { - this.content = content; - } - }; - - if (frame.getBinaryData() != null) { - webSocketChunk.setContent(ChannelBuffers.wrappedBuffer(frame.getBinaryData())); - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), null, NettyAsyncHttpProvider.this, webSocketChunk, true); - h.onBodyPartReceived(rp); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - if (webSocket != null) { - if (pendingOpcode == OPCODE_BINARY) { - webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); - } else { - webSocket.onTextFragment(frame.getBinaryData().toString(UTF8), frame.isFinalFragment()); - } - - if (frame instanceof CloseWebSocketFrame) { - try { - ctx.setAttachment(DiscardEvent.class); - webSocket.onClose(CloseWebSocketFrame.class.cast(frame).getStatusCode(), CloseWebSocketFrame.class.cast(frame).getReasonText()); - } catch (Throwable t) { - // Swallow any exception that may comes from a Netty version released before 3.4.0 - log.trace("", t); - } - } - } else { - log.debug("UpgradeHandler returned a null NettyWebSocket "); - } - } - } else { - log.error("Invalid attachment {}", ctx.getAttachment()); - } - } - - // @Override - public void onError(ChannelHandlerContext ctx, ExceptionEvent e) { - try { - log.warn("onError {}", e); - if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { - return; - } - - NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - if (webSocket != null) { - webSocket.onError(e.getCause()); - webSocket.close(); - } - } catch (Throwable t) { - log.error("onError", t); - } - } - - // @Override - public void onClose(ChannelHandlerContext ctx, ChannelStateEvent e) { - log.trace("onClose {}", e); - if (!(ctx.getAttachment() instanceof NettyResponseFuture)) { - return; - } - - try { - NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(ctx.getAttachment()); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - if (!(ctx.getAttachment() instanceof DiscardEvent)) - webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent)."); - } catch (Throwable t) { - log.error("onError", t); - } - } - } - - private static boolean isWebSocket(URI uri) { - return WEBSOCKET.equalsIgnoreCase(uri.getScheme()) || WEBSOCKET_SSL.equalsIgnoreCase(uri.getScheme()); - } - - private static boolean isSecure(String scheme) { - return HTTPS.equalsIgnoreCase(scheme) || WEBSOCKET_SSL.equalsIgnoreCase(scheme); - } - - private static boolean isSecure(URI uri) { - return isSecure(uri.getScheme()); + public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { + return requestSender.sendRequest(request, asyncHandler, null, asyncHttpProviderConfig.isAsyncConnect(), false); } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java index d184b19aa7..210f1dc8a9 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java @@ -16,16 +16,17 @@ */ package org.asynchttpclient.providers.netty; +import io.netty.channel.Channel; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; + import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutorService; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +import org.asynchttpclient.AsyncHttpProviderConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.asynchttpclient.AsyncHttpProviderConfig; /** * This class can be used to pass Netty's internal configuration options. See Netty documentation for more information. @@ -40,14 +41,19 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig properties = new HashMap(); @@ -96,7 +102,7 @@ public NettyAsyncHttpProviderConfig() { */ public NettyAsyncHttpProviderConfig addProperty(String name, Object value) { - if (name.equals(REUSE_ADDRESS) && value == Boolean.TRUE && System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win")) { + if (name.equals(REUSE_ADDRESS) && value == Boolean.TRUE && System.getProperty("os.name").toLowerCase().contains("win")) { LOGGER.warn("Can't enable {} on Windows", REUSE_ADDRESS); } else { properties.put(name, value); @@ -142,20 +148,20 @@ public void setUseBlockingIO(boolean useBlockingIO) { this.useBlockingIO = useBlockingIO; } - public NioClientSocketChannelFactory getSocketChannelFactory() { - return socketChannelFactory; + public EventLoopGroup getEventLoopGroup() { + return eventLoopGroup; } - public void setSocketChannelFactory(NioClientSocketChannelFactory socketChannelFactory) { - this.socketChannelFactory = socketChannelFactory; + public void setEventLoopGroup(EventLoopGroup eventLoopGroup) { + this.eventLoopGroup = eventLoopGroup; } - public ExecutorService getBossExecutorService() { - return bossExecutorService; + public boolean isAsyncConnect() { + return asyncConnect; } - public void setBossExecutorService(ExecutorService bossExecutorService) { - this.bossExecutorService = bossExecutorService; + public void setAsyncConnect(boolean asyncConnect) { + this.asyncConnect = asyncConnect; } public int getMaxInitialLineLength() { @@ -181,4 +187,41 @@ public int getMaxChunkSize() { public void setMaxChunkSize(int maxChunkSize) { this.maxChunkSize = maxChunkSize; } + + public AdditionalChannelInitializer getHttpAdditionalChannelInitializer() { + return httpAdditionalChannelInitializer; + } + + public void setHttpAdditionalChannelInitializer(AdditionalChannelInitializer httpAdditionalChannelInitializer) { + this.httpAdditionalChannelInitializer = httpAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getWsAdditionalChannelInitializer() { + return wsAdditionalChannelInitializer; + } + + public void setWsAdditionalChannelInitializer(AdditionalChannelInitializer wsAdditionalChannelInitializer) { + this.wsAdditionalChannelInitializer = wsAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getHttpsAdditionalChannelInitializer() { + return httpsAdditionalChannelInitializer; + } + + public void setHttpsAdditionalChannelInitializer(AdditionalChannelInitializer httpsAdditionalChannelInitializer) { + this.httpsAdditionalChannelInitializer = httpsAdditionalChannelInitializer; + } + + public AdditionalChannelInitializer getWssAdditionalChannelInitializer() { + return wssAdditionalChannelInitializer; + } + + public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssAdditionalChannelInitializer) { + this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer; + } + + public static interface AdditionalChannelInitializer { + + void initChannel(Channel ch) throws Exception; + } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java deleted file mode 100644 index 0d090275fb..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectListener.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - * - */ -package org.asynchttpclient.providers.netty; - -import java.io.IOException; -import java.net.ConnectException; -import java.net.URI; -import java.nio.channels.ClosedChannelException; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.net.ssl.HostnameVerifier; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.ChannelFutureListener; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.ssl.SslHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Request; -import org.asynchttpclient.util.ProxyUtils; - - -/** - * Non Blocking connect. - */ -final class NettyConnectListener implements ChannelFutureListener { - private final static Logger logger = LoggerFactory.getLogger(NettyConnectListener.class); - private final AsyncHttpClientConfig config; - private final NettyResponseFuture future; - private final HttpRequest nettyRequest; - private final AtomicBoolean handshakeDone = new AtomicBoolean(false); - - private NettyConnectListener(AsyncHttpClientConfig config, - NettyResponseFuture future, - HttpRequest nettyRequest) { - this.config = config; - this.future = future; - this.nettyRequest = nettyRequest; - } - - public NettyResponseFuture future() { - return future; - } - - public final void operationComplete(ChannelFuture f) throws Exception { - if (f.isSuccess()) { - Channel channel = f.getChannel(); - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(future); - SslHandler sslHandler = (SslHandler) channel.getPipeline().get(NettyAsyncHttpProvider.SSL_HANDLER); - if (!handshakeDone.getAndSet(true) && (sslHandler != null)) { - ((SslHandler) channel.getPipeline().get(NettyAsyncHttpProvider.SSL_HANDLER)).handshake().addListener(this); - return; - } - - HostnameVerifier v = config.getHostnameVerifier(); - if (sslHandler != null) { - if (!v.verify(future.getURI().getHost(), sslHandler.getEngine().getSession())) { - ConnectException exception = new ConnectException("HostnameVerifier exception."); - future.abort(exception); - throw exception; - } - } - - future.provider().writeRequest(f.getChannel(), config, future, nettyRequest); - } else { - Throwable cause = f.getCause(); - - logger.debug("Trying to recover a dead cached channel {} with a retry value of {} ", f.getChannel(), future.canRetry()); - if (future.canRetry() && cause != null && (NettyAsyncHttpProvider.abortOnDisconnectException(cause) - || cause instanceof ClosedChannelException - || future.getState() != NettyResponseFuture.STATE.NEW)) { - - logger.debug("Retrying {} ", nettyRequest); - if (future.provider().remotelyClosed(f.getChannel(), future)) { - return; - } - } - - logger.debug("Failed to recover from exception: {} with channel {}", cause, f.getChannel()); - - boolean printCause = f.getCause() != null && cause.getMessage() != null; - ConnectException e = new ConnectException(printCause ? cause.getMessage() + " to " + future.getURI().toString() : future.getURI().toString()); - if (cause != null) { - e.initCause(cause); - } - future.abort(e); - } - } - - public static class Builder { - private final AsyncHttpClientConfig config; - - private final Request request; - private final AsyncHandler asyncHandler; - private NettyResponseFuture future; - private final NettyAsyncHttpProvider provider; - private final ChannelBuffer buffer; - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler, - NettyAsyncHttpProvider provider, ChannelBuffer buffer) { - - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = null; - this.provider = provider; - this.buffer = buffer; - } - - public Builder(AsyncHttpClientConfig config, Request request, AsyncHandler asyncHandler, - NettyResponseFuture future, NettyAsyncHttpProvider provider, ChannelBuffer buffer) { - - this.config = config; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = future; - this.provider = provider; - this.buffer = buffer; - } - - public NettyConnectListener build(final URI uri) throws IOException { - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - HttpRequest nettyRequest = NettyAsyncHttpProvider.buildRequest(config, request, uri, true, buffer, proxyServer); - if (future == null) { - future = NettyAsyncHttpProvider.newFuture(uri, request, asyncHandler, nettyRequest, config, provider, proxyServer); - } else { - future.setNettyRequest(nettyRequest); - future.setRequest(request); - } - return new NettyConnectListener(config, future, nettyRequest); - } - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java deleted file mode 100644 index 96b273f879..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyConnectionsPool.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import static org.asynchttpclient.util.DateUtil.millisTime; -import org.asynchttpclient.ConnectionsPool; -import org.jboss.netty.channel.Channel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.atomic.AtomicBoolean; - -/** - * A simple implementation of {@link org.asynchttpclient.ConnectionsPool} based on a {@link java.util.concurrent.ConcurrentHashMap} - */ -public class NettyConnectionsPool implements ConnectionsPool { - - private final static Logger log = LoggerFactory.getLogger(NettyConnectionsPool.class); - private final ConcurrentHashMap> connectionsPool = new ConcurrentHashMap>(); - private final ConcurrentHashMap channel2IdleChannel = new ConcurrentHashMap(); - private final ConcurrentHashMap channel2CreationDate = new ConcurrentHashMap(); - private final AtomicBoolean isClosed = new AtomicBoolean(false); - private final Timer idleConnectionDetector; - private final boolean sslConnectionPoolEnabled; - private final int maxTotalConnections; - private final int maxConnectionPerHost; - private final int maxConnectionLifeTimeInMs; - private final long maxIdleTime; - - public NettyConnectionsPool(NettyAsyncHttpProvider provider) { - this(provider.getConfig().getMaxTotalConnections(), provider.getConfig().getMaxConnectionPerHost(), provider.getConfig().getIdleConnectionInPoolTimeoutInMs(), provider.getConfig().isSslConnectionPoolEnabled(), provider.getConfig().getMaxConnectionLifeTimeInMs(), new Timer(true)); - } - - public NettyConnectionsPool(int maxTotalConnections, int maxConnectionPerHost, long maxIdleTime, boolean sslConnectionPoolEnabled, int maxConnectionLifeTimeInMs, Timer idleConnectionDetector) { - this.maxTotalConnections = maxTotalConnections; - this.maxConnectionPerHost = maxConnectionPerHost; - this.sslConnectionPoolEnabled = sslConnectionPoolEnabled; - this.maxIdleTime = maxIdleTime; - this.maxConnectionLifeTimeInMs = maxConnectionLifeTimeInMs; - this.idleConnectionDetector = idleConnectionDetector; - this.idleConnectionDetector.schedule(new IdleChannelDetector(), maxIdleTime, maxIdleTime); - } - - private static class IdleChannel { - final String uri; - final Channel channel; - final long start; - - IdleChannel(String uri, Channel channel) { - this.uri = uri; - this.channel = channel; - this.start = millisTime(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof IdleChannel)) return false; - - IdleChannel that = (IdleChannel) o; - - if (channel != null ? !channel.equals(that.channel) : that.channel != null) return false; - - return true; - } - - @Override - public int hashCode() { - return channel != null ? channel.hashCode() : 0; - } - } - - private class IdleChannelDetector extends TimerTask { - @Override - public void run() { - try { - if (isClosed.get()) return; - - if (log.isDebugEnabled()) { - Set keys = connectionsPool.keySet(); - - for (String s : keys) { - log.debug("Entry count for : {} : {}", s, connectionsPool.get(s).size()); - } - } - - List channelsInTimeout = new ArrayList(); - long currentTime = millisTime(); - - for (IdleChannel idleChannel : channel2IdleChannel.values()) { - long age = currentTime - idleChannel.start; - if (age > maxIdleTime) { - - log.debug("Adding Candidate Idle Channel {}", idleChannel.channel); - - // store in an unsynchronized list to minimize the impact on the ConcurrentHashMap. - channelsInTimeout.add(idleChannel); - } - } - long endConcurrentLoop = millisTime(); - - for (IdleChannel idleChannel : channelsInTimeout) { - Object attachment = idleChannel.channel.getPipeline().getContext(NettyAsyncHttpProvider.class).getAttachment(); - if (attachment != null) { - if (attachment instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) attachment; - - if (!future.isDone() && !future.isCancelled()) { - log.debug("Future not in appropriate state %s\n", future); - continue; - } - } - } - - if (remove(idleChannel)) { - log.debug("Closing Idle Channel {}", idleChannel.channel); - close(idleChannel.channel); - } - } - - if (log.isTraceEnabled()) { - int openChannels = 0; - for (ConcurrentLinkedQueue hostChannels: connectionsPool.values()) { - openChannels += hostChannels.size(); - } - log.trace(String.format("%d channel open, %d idle channels closed (times: 1st-loop=%d, 2nd-loop=%d).\n", - openChannels, channelsInTimeout.size(), endConcurrentLoop - currentTime, millisTime() - endConcurrentLoop)); - } - } catch (Throwable t) { - log.error("uncaught exception!", t); - } - } - } - - /** - * {@inheritDoc} - */ - public boolean offer(String uri, Channel channel) { - if (isClosed.get()) return false; - - if (!sslConnectionPoolEnabled && uri.startsWith("https")) { - return false; - } - - Long createTime = channel2CreationDate.get(channel); - if (createTime == null){ - channel2CreationDate.putIfAbsent(channel, millisTime()); - } - else if (maxConnectionLifeTimeInMs != -1 && (createTime + maxConnectionLifeTimeInMs) < millisTime() ) { - log.debug("Channel {} expired", channel); - return false; - } - - log.debug("Adding uri: {} for channel {}", uri, channel); - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(new NettyAsyncHttpProvider.DiscardEvent()); - - ConcurrentLinkedQueue idleConnectionForHost = connectionsPool.get(uri); - if (idleConnectionForHost == null) { - ConcurrentLinkedQueue newPool = new ConcurrentLinkedQueue(); - idleConnectionForHost = connectionsPool.putIfAbsent(uri, newPool); - if (idleConnectionForHost == null) idleConnectionForHost = newPool; - } - - boolean added; - int size = idleConnectionForHost.size(); - if (maxConnectionPerHost == -1 || size < maxConnectionPerHost) { - IdleChannel idleChannel = new IdleChannel(uri, channel); - synchronized (idleConnectionForHost) { - added = idleConnectionForHost.add(idleChannel); - - if (channel2IdleChannel.put(channel, idleChannel) != null) { - log.error("Channel {} already exists in the connections pool!", channel); - } - } - } else { - log.debug("Maximum number of requests per host reached {} for {}", maxConnectionPerHost, uri); - added = false; - } - return added; - } - - /** - * {@inheritDoc} - */ - public Channel poll(String uri) { - if (!sslConnectionPoolEnabled && uri.startsWith("https")) { - return null; - } - - IdleChannel idleChannel = null; - ConcurrentLinkedQueue idleConnectionForHost = connectionsPool.get(uri); - if (idleConnectionForHost != null) { - boolean poolEmpty = false; - while (!poolEmpty && idleChannel == null) { - if (idleConnectionForHost.size() > 0) { - synchronized (idleConnectionForHost) { - idleChannel = idleConnectionForHost.poll(); - if (idleChannel != null) { - channel2IdleChannel.remove(idleChannel.channel); - } - } - } - - if (idleChannel == null) { - poolEmpty = true; - } else if (!idleChannel.channel.isConnected() || !idleChannel.channel.isOpen()) { - idleChannel = null; - log.trace("Channel not connected or not opened!"); - } - } - } - return idleChannel != null ? idleChannel.channel : null; - } - - private boolean remove(IdleChannel pooledChannel) { - if (pooledChannel == null || isClosed.get()) return false; - - boolean isRemoved = false; - ConcurrentLinkedQueue pooledConnectionForHost = connectionsPool.get(pooledChannel.uri); - if (pooledConnectionForHost != null) { - isRemoved = pooledConnectionForHost.remove(pooledChannel); - } - isRemoved |= channel2IdleChannel.remove(pooledChannel.channel) != null; - return isRemoved; - } - - /** - * {@inheritDoc} - */ - public boolean removeAll(Channel channel) { - channel2CreationDate.remove(channel); - return !isClosed.get() && remove(channel2IdleChannel.get(channel)); - } - - /** - * {@inheritDoc} - */ - public boolean canCacheConnection() { - if (!isClosed.get() && maxTotalConnections != -1 && channel2IdleChannel.size() >= maxTotalConnections) { - return false; - } else { - return true; - } - } - - /** - * {@inheritDoc} - */ - public void destroy() { - if (isClosed.getAndSet(true)) return; - - // stop timer - idleConnectionDetector.cancel(); - idleConnectionDetector.purge(); - - for (Channel channel : channel2IdleChannel.keySet()) { - close(channel); - } - connectionsPool.clear(); - channel2IdleChannel.clear(); - channel2CreationDate.clear(); - } - - private void close(Channel channel) { - try { - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(new NettyAsyncHttpProvider.DiscardEvent()); - channel2CreationDate.remove(channel); - channel.close(); - } catch (Throwable t) { - // noop - } - } - - public final String toString() { - return String.format("NettyConnectionPool: {pool-size: %d}", channel2IdleChannel.size()); - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponse.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponse.java deleted file mode 100644 index 81b520fbc6..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponse.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferInputStream; -import org.jboss.netty.buffer.ChannelBuffers; - -import org.asynchttpclient.Cookie; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.providers.ResponseBase; -import org.asynchttpclient.providers.netty.util.ChannelBufferUtil; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; - -/** - * Wrapper around the {@link org.asynchttpclient.Response} API. - */ -public class NettyResponse extends ResponseBase { - - public NettyResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts) { - super(status, headers, bodyParts); - } - - /* @Override */ - public String getResponseBodyExcerpt(int maxLength) throws IOException { - return getResponseBodyExcerpt(maxLength, null); - } - - public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException { - // should be fine; except that it may split multi-byte chars (last char may become '?') - charset = calculateCharset(charset); - byte[] b = AsyncHttpProviderUtils.contentToBytes(bodyParts, maxLength); - return new String(b, charset); - } - - protected List buildCookies() { - List cookies = new ArrayList(); - for (Map.Entry> header : headers.getHeaders().entrySet()) { - if (header.getKey().equalsIgnoreCase("Set-Cookie")) { - // TODO: ask for parsed header - List v = header.getValue(); - for (String value : v) { - cookies.addAll(CookieDecoder.decode(value)); - } - } - } - return Collections.unmodifiableList(cookies); - } - - /* @Override */ - public byte[] getResponseBodyAsBytes() throws IOException { - return ChannelBufferUtil.channelBuffer2bytes(getResponseBodyAsChannelBuffer()); - } - - /* @Override */ - public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { - return getResponseBodyAsChannelBuffer().toByteBuffer(); - } - - /* @Override */ - public String getResponseBody() throws IOException { - return getResponseBody(null); - } - - /* @Override */ - public String getResponseBody(String charset) throws IOException { - return getResponseBodyAsChannelBuffer().toString(Charset.forName(calculateCharset(charset))); - } - - /* @Override */ - public InputStream getResponseBodyAsStream() throws IOException { - return new ChannelBufferInputStream(getResponseBodyAsChannelBuffer()); - } - - public ChannelBuffer getResponseBodyAsChannelBuffer() throws IOException { - ChannelBuffer b = null; - switch (bodyParts.size()) { - case 0: - b = ChannelBuffers.EMPTY_BUFFER; - break; - case 1: - b = ResponseBodyPart.class.cast(bodyParts.get(0)).getChannelBuffer(); - break; - default: - ChannelBuffer[] channelBuffers = new ChannelBuffer[bodyParts.size()]; - for (int i = 0; i < bodyParts.size(); i++) { - channelBuffers[i] = ResponseBodyPart.class.cast(bodyParts.get(i)).getChannelBuffer(); - } - b = ChannelBuffers.wrappedBuffer(channelBuffers); - } - - return b; - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java deleted file mode 100755 index a5e75f4c32..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyResponseFuture.java +++ /dev/null @@ -1,515 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty; - -import static org.asynchttpclient.util.DateUtil.millisTime; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.ConnectionPoolKeyStrategy; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Request; -import org.asynchttpclient.listenable.AbstractListenableFuture; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.handler.codec.http.HttpRequest; -import org.jboss.netty.handler.codec.http.HttpResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.MalformedURLException; -import java.net.URI; -import java.util.concurrent.CancellationException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - -/** - * A {@link Future} that can be used to track when an asynchronous HTTP request has been fully processed. - * - * @param - */ -public final class NettyResponseFuture extends AbstractListenableFuture { - - private final static Logger logger = LoggerFactory.getLogger(NettyResponseFuture.class); - public final static String MAX_RETRY = "org.asynchttpclient.providers.netty.maxRetry"; - - enum STATE { - NEW, POOLED, RECONNECTED, CLOSED, - } - - private final CountDownLatch latch = new CountDownLatch(1); - private final AtomicBoolean isDone = new AtomicBoolean(false); - private final AtomicBoolean isCancelled = new AtomicBoolean(false); - private AsyncHandler asyncHandler; - private final int requestTimeoutInMs; - private final int idleConnectionTimeoutInMs; - private Request request; - private HttpRequest nettyRequest; - private final AtomicReference content = new AtomicReference(); - private URI uri; - private boolean keepAlive = true; - private HttpResponse httpResponse; - private final AtomicReference exEx = new AtomicReference(); - private final AtomicInteger redirectCount = new AtomicInteger(); - private volatile Future reaperFuture; - private final AtomicBoolean inAuth = new AtomicBoolean(false); - private final AtomicBoolean statusReceived = new AtomicBoolean(false); - private final AtomicLong touch = new AtomicLong(millisTime()); - private final long start = millisTime(); - private final NettyAsyncHttpProvider asyncHttpProvider; - private final AtomicReference state = new AtomicReference(STATE.NEW); - private final AtomicBoolean contentProcessed = new AtomicBoolean(false); - private Channel channel; - private boolean reuseChannel = false; - private final AtomicInteger currentRetry = new AtomicInteger(0); - private final int maxRetry; - private boolean writeHeaders; - private boolean writeBody; - private final AtomicBoolean throwableCalled = new AtomicBoolean(false); - private boolean allowConnect = false; - private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy; - private final ProxyServer proxyServer; - - public NettyResponseFuture(URI uri,// - Request request,// - AsyncHandler asyncHandler,// - HttpRequest nettyRequest,// - int requestTimeoutInMs,// - int idleConnectionTimeoutInMs,// - NettyAsyncHttpProvider asyncHttpProvider,// - ConnectionPoolKeyStrategy connectionPoolKeyStrategy,// - ProxyServer proxyServer) { - - this.asyncHandler = asyncHandler; - this.requestTimeoutInMs = requestTimeoutInMs; - this.idleConnectionTimeoutInMs = idleConnectionTimeoutInMs; - this.request = request; - this.nettyRequest = nettyRequest; - this.uri = uri; - this.asyncHttpProvider = asyncHttpProvider; - this.connectionPoolKeyStrategy = connectionPoolKeyStrategy; - this.proxyServer = proxyServer; - - if (System.getProperty(MAX_RETRY) != null) { - maxRetry = Integer.valueOf(System.getProperty(MAX_RETRY)); - } else { - maxRetry = asyncHttpProvider.getConfig().getMaxRequestRetry(); - } - writeHeaders = true; - writeBody = true; - } - - protected URI getURI() throws MalformedURLException { - return uri; - } - - protected void setURI(URI uri) { - this.uri = uri; - } - - public ConnectionPoolKeyStrategy getConnectionPoolKeyStrategy() { - return connectionPoolKeyStrategy; - } - - public ProxyServer getProxyServer() { - return proxyServer; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean isDone() { - return isDone.get(); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean isCancelled() { - return isCancelled.get(); - } - - void setAsyncHandler(AsyncHandler asyncHandler) { - this.asyncHandler = asyncHandler; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean cancel(boolean force) { - cancelReaper(); - - if (isCancelled.get()) - return false; - - try { - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(new NettyAsyncHttpProvider.DiscardEvent()); - channel.close(); - } catch (Throwable t) { - // Ignore - } - if (!throwableCalled.getAndSet(true)) { - try { - asyncHandler.onThrowable(new CancellationException()); - } catch (Throwable t) { - logger.warn("cancel", t); - } - } - latch.countDown(); - isCancelled.set(true); - runListeners(); - return true; - } - - /** - * Is the Future still valid - * - * @return true if response has expired and should be terminated. - */ - public boolean hasExpired() { - long now = millisTime(); - return hasConnectionIdleTimedOut(now) || hasRequestTimedOut(now); - } - - public boolean hasConnectionIdleTimedOut(long now) { - return idleConnectionTimeoutInMs != -1 && (now - touch.get()) >= idleConnectionTimeoutInMs; - } - - public boolean hasRequestTimedOut(long now) { - return requestTimeoutInMs != -1 && (now - start) >= requestTimeoutInMs; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public V get() throws InterruptedException, ExecutionException { - try { - return get(requestTimeoutInMs, TimeUnit.MILLISECONDS); - } catch (TimeoutException e) { - cancelReaper(); - throw new ExecutionException(e); - } - } - - void cancelReaper() { - if (reaperFuture != null) { - reaperFuture.cancel(false); - } - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, ExecutionException { - if (!isDone() && !isCancelled()) { - boolean expired = false; - if (l == -1) { - latch.await(); - } else { - expired = !latch.await(l, tu); - } - - if (expired) { - isCancelled.set(true); - try { - channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(new NettyAsyncHttpProvider.DiscardEvent()); - channel.close(); - } catch (Throwable t) { - // Ignore - } - TimeoutException te = new TimeoutException(String.format("No response received after %s %s", l, tu.name().toLowerCase())); - if (!throwableCalled.getAndSet(true)) { - try { - asyncHandler.onThrowable(te); - } catch (Throwable t) { - logger.debug("asyncHandler.onThrowable", t); - } - cancelReaper(); - throw new ExecutionException(te); - } - } - isDone.set(true); - - ExecutionException e = exEx.getAndSet(null); - if (e != null) { - throw e; - } - } - return getContent(); - } - - V getContent() throws ExecutionException { - ExecutionException e = exEx.getAndSet(null); - if (e != null) { - throw e; - } - - V update = content.get(); - // No more retry - currentRetry.set(maxRetry); - if (exEx.get() == null && !contentProcessed.getAndSet(true)) { - try { - update = asyncHandler.onCompleted(); - } catch (Throwable ex) { - if (!throwableCalled.getAndSet(true)) { - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - logger.debug("asyncHandler.onThrowable", t); - } - cancelReaper(); - throw new RuntimeException(ex); - } - } - content.compareAndSet(null, update); - } - return update; - } - - public final void done() { - - try { - cancelReaper(); - - if (exEx.get() != null) { - return; - } - getContent(); - isDone.set(true); - } catch (ExecutionException t) { - return; - } catch (RuntimeException t) { - Throwable exception = t.getCause() != null ? t.getCause() : t; - exEx.compareAndSet(null, new ExecutionException(exception)); - - } finally { - latch.countDown(); - } - - runListeners(); - } - - public final void abort(final Throwable t) { - cancelReaper(); - - if (isDone.get() || isCancelled.get()) - return; - - exEx.compareAndSet(null, new ExecutionException(t)); - if (!throwableCalled.getAndSet(true)) { - try { - asyncHandler.onThrowable(t); - } catch (Throwable te) { - logger.debug("asyncHandler.onThrowable", te); - } finally { - isCancelled.set(true); - } - } - latch.countDown(); - runListeners(); - } - - public void content(V v) { - content.set(v); - } - - protected final Request getRequest() { - return request; - } - - public final HttpRequest getNettyRequest() { - return nettyRequest; - } - - protected final void setNettyRequest(HttpRequest nettyRequest) { - this.nettyRequest = nettyRequest; - } - - protected final AsyncHandler getAsyncHandler() { - return asyncHandler; - } - - protected final boolean isKeepAlive() { - return keepAlive; - } - - protected final void setKeepAlive(final boolean keepAlive) { - this.keepAlive = keepAlive; - } - - protected final HttpResponse getHttpResponse() { - return httpResponse; - } - - protected final void setHttpResponse(final HttpResponse httpResponse) { - this.httpResponse = httpResponse; - } - - protected int incrementAndGetCurrentRedirectCount() { - return redirectCount.incrementAndGet(); - } - - protected void setReaperFuture(Future reaperFuture) { - cancelReaper(); - this.reaperFuture = reaperFuture; - } - - protected boolean isInAuth() { - return inAuth.get(); - } - - protected boolean getAndSetAuth(boolean inDigestAuth) { - return inAuth.getAndSet(inDigestAuth); - } - - protected STATE getState() { - return state.get(); - } - - protected void setState(STATE state) { - this.state.set(state); - } - - public boolean getAndSetStatusReceived(boolean sr) { - return statusReceived.getAndSet(sr); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public void touch() { - touch.set(millisTime()); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean getAndSetWriteHeaders(boolean writeHeaders) { - boolean b = this.writeHeaders; - this.writeHeaders = writeHeaders; - return b; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean getAndSetWriteBody(boolean writeBody) { - boolean b = this.writeBody; - this.writeBody = writeBody; - return b; - } - - protected NettyAsyncHttpProvider provider() { - return asyncHttpProvider; - } - - protected void attachChannel(Channel channel) { - this.channel = channel; - } - - public void setReuseChannel(boolean reuseChannel) { - this.reuseChannel = reuseChannel; - } - - public boolean isConnectAllowed() { - return allowConnect; - } - - public void setConnectAllowed(boolean allowConnect) { - this.allowConnect = allowConnect; - } - - protected void attachChannel(Channel channel, boolean reuseChannel) { - this.channel = channel; - this.reuseChannel = reuseChannel; - } - - protected Channel channel() { - return channel; - } - - protected boolean reuseChannel() { - return reuseChannel; - } - - protected boolean canRetry() { - if (currentRetry.incrementAndGet() > maxRetry) { - return false; - } - return true; - } - - public void setRequest(Request request) { - this.request = request; - } - - /** - * Return true if the {@link Future} cannot be recovered. There is some scenario where a connection can be closed by an unexpected IOException, and in some situation we can - * recover from that exception. - * - * @return true if that {@link Future} cannot be recovered. - */ - public boolean cannotBeReplay() { - return isDone() || !canRetry() || isCancelled() || (channel() != null && channel().isOpen() && uri.getScheme().compareToIgnoreCase("https") != 0) || isInAuth(); - } - - public long getStart() { - return start; - } - - public long getRequestTimeoutInMs() { - return requestTimeoutInMs; - } - - public long getIdleConnectionTimeoutInMs() { - return idleConnectionTimeoutInMs; - } - - @Override - public String toString() { - return "NettyResponseFuture{" + // - "currentRetry=" + currentRetry + // - ",\n\tisDone=" + isDone + // - ",\n\tisCancelled=" + isCancelled + // - ",\n\tasyncHandler=" + asyncHandler + // - ",\n\trequestTimeoutInMs=" + requestTimeoutInMs + // - ",\n\tnettyRequest=" + nettyRequest + // - ",\n\tcontent=" + content + // - ",\n\turi=" + uri + // - ",\n\tkeepAlive=" + keepAlive + // - ",\n\thttpResponse=" + httpResponse + // - ",\n\texEx=" + exEx + // - ",\n\tredirectCount=" + redirectCount + // - ",\n\treaperFuture=" + reaperFuture + // - ",\n\tinAuth=" + inAuth + // - ",\n\tstatusReceived=" + statusReceived + // - ",\n\ttouch=" + touch + // - '}'; - } - -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java deleted file mode 100644 index 38c08df1a3..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyWebSocket.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.websocket.WebSocket; -import org.asynchttpclient.websocket.WebSocketByteListener; -import org.asynchttpclient.websocket.WebSocketCloseCodeReasonListener; -import org.asynchttpclient.websocket.WebSocketListener; -import org.asynchttpclient.websocket.WebSocketTextListener; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.PingWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.PongWebSocketFrame; -import org.jboss.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.ByteArrayOutputStream; -import java.util.concurrent.ConcurrentLinkedQueue; - -import static org.jboss.netty.buffer.ChannelBuffers.wrappedBuffer; - -public class NettyWebSocket implements WebSocket { - private final static Logger logger = LoggerFactory.getLogger(NettyWebSocket.class); - - private final Channel channel; - private final ConcurrentLinkedQueue listeners = new ConcurrentLinkedQueue(); - - private StringBuilder textBuffer; - private ByteArrayOutputStream byteBuffer; - private int maxBufferSize = 128000000; - - public NettyWebSocket(Channel channel) { - this.channel = channel; - } - - // @Override - public WebSocket sendMessage(byte[] message) { - channel.write(new BinaryWebSocketFrame(wrappedBuffer(message))); - return this; - } - - // @Override - public WebSocket stream(byte[] fragment, boolean last) { - throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); - } - - // @Override - public WebSocket stream(byte[] fragment, int offset, int len, boolean last) { - throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); - } - - // @Override - public WebSocket sendTextMessage(String message) { - channel.write(new TextWebSocketFrame(message)); - return this; - } - - // @Override - public WebSocket streamText(String fragment, boolean last) { - throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); - } - - // @Override - public WebSocket sendPing(byte[] payload) { - channel.write(new PingWebSocketFrame(wrappedBuffer(payload))); - return this; - } - - // @Override - public WebSocket sendPong(byte[] payload) { - channel.write(new PongWebSocketFrame(wrappedBuffer(payload))); - return this; - } - - // @Override - public WebSocket addWebSocketListener(WebSocketListener l) { - listeners.add(l); - return this; - } - - // @Override - public WebSocket removeWebSocketListener(WebSocketListener l) { - listeners.remove(l); - return this; - } - - public int getMaxBufferSize() { - return maxBufferSize; - } - - public void setMaxBufferSize(int bufferSize) { - maxBufferSize = bufferSize; - - if(maxBufferSize < 8192) - maxBufferSize = 8192; - } - - // @Override - public boolean isOpen() { - return channel.isOpen(); - } - - // @Override - public void close() { - onClose(); - listeners.clear(); - try { - channel.write(new CloseWebSocketFrame()); - channel.getCloseFuture().awaitUninterruptibly(); - } finally { - channel.close(); - } - } - - // @Override - public void close(int statusCode, String reason) { - onClose(statusCode, reason); - listeners.clear(); - try { - channel.write(new CloseWebSocketFrame(statusCode, reason)); - channel.getCloseFuture().awaitUninterruptibly(); - } finally { - channel.close(); - } - } - - protected void onBinaryFragment(byte[] message, boolean last) { - for (WebSocketListener l : listeners) { - if (l instanceof WebSocketByteListener) { - try { - WebSocketByteListener.class.cast(l).onFragment(message,last); - - if(byteBuffer == null) { - byteBuffer = new ByteArrayOutputStream(); - } - - byteBuffer.write(message); - - if(byteBuffer.size() > maxBufferSize) { - Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); - l.onError(e); - this.close(); - return; - } - - - if(last) { - WebSocketByteListener.class.cast(l).onMessage(byteBuffer.toByteArray()); - byteBuffer = null; - textBuffer = null; - } - } catch (Exception ex) { - l.onError(ex); - } - } - } - } - - protected void onTextFragment(String message, boolean last) { - for (WebSocketListener l : listeners) { - if (l instanceof WebSocketTextListener) { - try { - WebSocketTextListener.class.cast(l).onFragment(message,last); - - if(textBuffer == null) { - textBuffer = new StringBuilder(); - } - - textBuffer.append(message); - - if(textBuffer.length() > maxBufferSize) { - Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); - l.onError(e); - this.close(); - return; - } - - if(last) { - WebSocketTextListener.class.cast(l).onMessage(textBuffer.toString()); - byteBuffer = null; - textBuffer = null; - } - } catch (Exception ex) { - l.onError(ex); - } - } - } - } - - protected void onError(Throwable t) { - for (WebSocketListener l : listeners) { - try { - l.onError(t); - } catch (Throwable t2) { - logger.error("", t2); - } - - } - } - - protected void onClose() { - onClose(1000, "Normal closure; the connection successfully completed whatever purpose for which it was created."); - } - - protected void onClose(int code, String reason) { - for (WebSocketListener l : listeners) { - try { - if (l instanceof WebSocketCloseCodeReasonListener) { - WebSocketCloseCodeReasonListener.class.cast(l).onClose(this, code, reason); - } - l.onClose(this); - } catch (Throwable t) { - l.onError(t); - } - } - } - - @Override - public String toString() { - return "NettyWebSocket{" + - "channel=" + channel + - '}'; - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Protocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Protocol.java deleted file mode 100644 index f9d6f39eff..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/Protocol.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelStateEvent; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.MessageEvent; - -public interface Protocol { - - void handle(ChannelHandlerContext ctx, MessageEvent e) throws Exception; - - void onError(ChannelHandlerContext ctx, ExceptionEvent e); - - void onClose(ChannelHandlerContext ctx, ChannelStateEvent e); -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java deleted file mode 100644 index 7f138bbc36..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseBodyPart.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicReference; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.handler.codec.http.HttpChunk; -import org.jboss.netty.handler.codec.http.HttpResponse; - -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.providers.netty.util.ChannelBufferUtil; - -/** - * A callback class used when an HTTP response body is received. - */ -public class ResponseBodyPart extends HttpResponseBodyPart { - - private final HttpChunk chunk; - private final HttpResponse response; - private final AtomicReference bytes = new AtomicReference(null); - private final boolean isLast; - private boolean closeConnection = false; - - /** - * Constructor used for non-chunked GET requests and HEAD requests. - */ - // FIXME Why notify with a null chunk??? - public ResponseBodyPart(URI uri, HttpResponse response, AsyncHttpProvider provider, boolean last) { - this(uri, response, provider, null, last); - } - - public ResponseBodyPart(URI uri, HttpResponse response, AsyncHttpProvider provider, HttpChunk chunk, boolean last) { - super(uri, provider); - this.chunk = chunk; - this.response = response; - isLast = last; - } - - /** - * Return the response body's part bytes received. - * - * @return the response body's part bytes received. - */ - @Override - public byte[] getBodyPartBytes() { - byte[] bp = bytes.get(); - if (bp != null) { - return bp; - } - - byte[] rb = ChannelBufferUtil.channelBuffer2bytes(getChannelBuffer()); - bytes.set(rb); - return rb; - } - - @Override - public InputStream readBodyPartBytes() { - return new ByteArrayInputStream(getBodyPartBytes()); - } - - @Override - public int length() { - ChannelBuffer b = (chunk != null) ? chunk.getContent() : response.getContent(); - return b.readableBytes(); - } - - @Override - public int writeTo(OutputStream outputStream) throws IOException { - ChannelBuffer b = getChannelBuffer(); - int available = b.readableBytes(); - if (available > 0) { - b.getBytes(b.readerIndex(), outputStream, available); - } - return available; - } - - @Override - public ByteBuffer getBodyByteBuffer() { - return ByteBuffer.wrap(getBodyPartBytes()); - } - - public ChannelBuffer getChannelBuffer() { - return chunk != null ? chunk.getContent() : response.getContent(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isLast() { - return isLast; - } - - /** - * {@inheritDoc} - */ - @Override - public void markUnderlyingConnectionAsClosed() { - closeConnection = true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean closeUnderlyingConnection() { - return closeConnection; - } - - protected HttpChunk chunk() { - return chunk; - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseHeaders.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseHeaders.java deleted file mode 100644 index 971eadbf72..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseHeaders.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseHeaders; -import org.jboss.netty.handler.codec.http.HttpChunkTrailer; -import org.jboss.netty.handler.codec.http.HttpResponse; - -import java.net.URI; -import java.util.Map; - -/** - * A class that represent the HTTP headers. - */ -public class ResponseHeaders extends HttpResponseHeaders { - - private final HttpChunkTrailer trailingHeaders; - private final HttpResponse response; - private final FluentCaseInsensitiveStringsMap headers; - - public ResponseHeaders(URI uri, HttpResponse response, AsyncHttpProvider provider) { - super(uri, provider, false); - this.trailingHeaders = null; - this.response = response; - headers = computerHeaders(); - } - - public ResponseHeaders(URI uri, HttpResponse response, AsyncHttpProvider provider, HttpChunkTrailer traillingHeaders) { - super(uri, provider, true); - this.trailingHeaders = traillingHeaders; - this.response = response; - headers = computerHeaders(); - } - - private FluentCaseInsensitiveStringsMap computerHeaders() { - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - for (Map.Entry header: response.getHeaders()) { - h.add(header.getKey(), header.getValue()); - } - - if (trailingHeaders != null) { - for (Map.Entry header: trailingHeaders.getHeaders()) { - h.add(header.getKey(), header.getValue()); - } - } - - return h; - } - - /** - * Return the HTTP header - * - * @return an {@link org.asynchttpclient.FluentCaseInsensitiveStringsMap} - */ - @Override - public FluentCaseInsensitiveStringsMap getHeaders() { - return headers; - } -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseStatus.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseStatus.java deleted file mode 100644 index 4cec5faf8a..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ResponseStatus.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - * - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseStatus; -import org.jboss.netty.handler.codec.http.HttpResponse; - -import java.net.URI; - -/** - * A class that represent the HTTP response' status line (code + text) - */ -public class ResponseStatus extends HttpResponseStatus { - - private final HttpResponse response; - - public ResponseStatus(URI uri, HttpResponse response, AsyncHttpProvider provider) { - super(uri, provider); - this.response = response; - } - - /** - * Return the response status code - * - * @return the response status code - */ - public int getStatusCode() { - return response.getStatus().getCode(); - } - - /** - * Return the response status text - * - * @return the response status text - */ - public String getStatusText() { - return response.getStatus().getReasonPhrase(); - } - - @Override - public String getProtocolName() { - return response.getProtocolVersion().getProtocolName(); - } - - @Override - public int getProtocolMajorVersion() { - return response.getProtocolVersion().getMajorVersion(); - } - - @Override - public int getProtocolMinorVersion() { - return response.getProtocolVersion().getMinorVersion(); - } - - @Override - public String getProtocolText() { - return response.getProtocolVersion().getText(); - } - -} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/WebSocketUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/WebSocketUtil.java deleted file mode 100644 index 8aabcc9542..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/WebSocketUtil.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty; - -import org.asynchttpclient.util.Base64; - -import java.io.UnsupportedEncodingException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -public final class WebSocketUtil { - public static final String MAGIC_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - - public static String getKey() { - byte[] nonce = createRandomBytes(16); - return base64Encode(nonce); - } - - public static String getAcceptKey(String key) throws UnsupportedEncodingException { - String acceptSeed = key + MAGIC_GUID; - byte[] sha1 = sha1(acceptSeed.getBytes("US-ASCII")); - return base64Encode(sha1); - } - - public static byte[] md5(byte[] bytes) { - try { - MessageDigest md = MessageDigest.getInstance("MD5"); - return md.digest(bytes); - } catch (NoSuchAlgorithmException e) { - throw new InternalError("MD5 not supported on this platform"); - } - } - - public static byte[] sha1(byte[] bytes) { - try { - MessageDigest md = MessageDigest.getInstance("SHA1"); - return md.digest(bytes); - } catch (NoSuchAlgorithmException e) { - throw new InternalError("SHA-1 not supported on this platform"); - } - } - - public static String base64Encode(byte[] bytes) { - return Base64.encode(bytes); - } - - public static byte[] createRandomBytes(int size) { - byte[] bytes = new byte[size]; - - for (int i = 0; i < size; i++) { - bytes[i] = (byte) createRandomNumber(0, 255); - } - - return bytes; - } - - public static int createRandomNumber(int min, int max) { - return (int) (Math.random() * max + min); - } - -} - diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java similarity index 84% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java index b6ee69b065..84e73efb71 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java @@ -1,8 +1,21 @@ -package org.asynchttpclient.providers.netty4; - -import static org.asynchttpclient.providers.netty4.util.HttpUtil.HTTP; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.channel; + +import static org.asynchttpclient.providers.netty.util.HttpUtil.*; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -43,7 +56,12 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionPoolKeyStrategy; import org.asynchttpclient.ConnectionsPool; -import org.asynchttpclient.providers.netty4.util.CleanupChannelGroup; +import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.handler.NettyChannelHandler; +import org.asynchttpclient.providers.netty.util.CleanupChannelGroup; import org.asynchttpclient.util.SslUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -89,8 +107,6 @@ public boolean remove(Object o) { } }; - private NettyChannelHandler httpProcessor; - public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig asyncHttpProviderConfig) { this.config = config; @@ -170,26 +186,28 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig } } - // FIXME clean up - plainBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); - webSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); - secureBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); - secureWebSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectionTimeoutInMs()); + int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; + plainBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeOut); + webSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeOut); + secureBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeOut); + secureWebSocketBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeOut); + } - // FIXME What was the meaning of this and what is it still a matter with - // Netty4 - // DefaultChannelFuture.setUseDeadLockChecker(false); + private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException { + SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine(); + if (sslEngine == null) { + sslEngine = SslUtils.getSSLEngine(); + } + return sslEngine; } public void configure(final NettyChannelHandler httpProcessor) { - this.httpProcessor = httpProcessor; - - ChannelInitializer httpChannelInitializer = new ChannelInitializer() { + plainBootstrap.handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline()// - .addLast(HTTP_HANDLER, newHttpClientCodec()); + .addLast(HTTP_HANDLER, newHttpClientCodec()); if (config.getRequestCompressionLevel() > 0) { pipeline.addLast(DEFLATER_HANDLER, new HttpContentCompressor(config.getRequestCompressionLevel())); @@ -199,75 +217,41 @@ protected void initChannel(Channel ch) throws Exception { pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); } pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())// - .addLast(AHC_HANDLER, httpProcessor); + .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getHttpAdditionalChannelInitializer() != null) { asyncHttpProviderConfig.getHttpAdditionalChannelInitializer().initChannel(ch); } } - }; + }); - ChannelInitializer webSocketChannelInitializer = new ChannelInitializer() { + webSocketBootstrap.handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline()// - .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// - .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// - .addLast(AHC_HANDLER, httpProcessor); + .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// + .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getWsAdditionalChannelInitializer() != null) { asyncHttpProviderConfig.getWsAdditionalChannelInitializer().initChannel(ch); } } - }; - - plainBootstrap.handler(httpChannelInitializer); - webSocketBootstrap.handler(webSocketChannelInitializer); - } - - public Bootstrap getBootstrap(String url, boolean useSSl) { - Bootstrap bootstrap = url.startsWith(WEBSOCKET) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap : plainBootstrap); - - return bootstrap; - } - - public void close() { - connectionsPool.destroy(); - for (Channel channel : openChannels) { - Object attribute = getDefaultAttribute(channel); - if (attribute instanceof NettyResponseFuture) { - NettyResponseFuture future = (NettyResponseFuture) attribute; - future.setReaperFuture(null); - } - } - openChannels.close(); - if (allowReleaseEventLoopGroup) { - eventLoopGroup.shutdownGracefully(); - } - } - - void constructSSLPipeline(final NettyResponseFuture future) { + }); secureBootstrap.handler(new ChannelInitializer() { @Override protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - LOGGER.error("Channel {} could not add SslHandler {}", ch, ex); - abort(future, ex); - } - - pipeline.addLast(HTTP_HANDLER, newHttpClientCodec()); + ChannelPipeline pipeline = ch.pipeline()// + .addLast(SSL_HANDLER, new SslHandler(createSSLEngine()))// + .addLast(HTTP_HANDLER, newHttpClientCodec()); if (config.isCompressionEnabled()) { pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor()); } pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())// - .addLast(AHC_HANDLER, httpProcessor); + .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getHttpsAdditionalChannelInitializer() != null) { asyncHttpProviderConfig.getHttpsAdditionalChannelInitializer().initChannel(ch); @@ -279,18 +263,11 @@ protected void initChannel(Channel ch) throws Exception { @Override protected void initChannel(Channel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - - try { - pipeline.addLast(SSL_HANDLER, new SslHandler(createSSLEngine())); - } catch (Throwable ex) { - LOGGER.error("Channel {} could not add SslHandler {}", ch, ex); - abort(future, ex); - } - - pipeline.addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// - .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// - .addLast(AHC_HANDLER, httpProcessor); + ch.pipeline()// + .addLast(SSL_HANDLER, new SslHandler(createSSLEngine()))// + .addLast(HTTP_DECODER_HANDLER, new HttpResponseDecoder())// + .addLast(HTTP_ENCODER_HANDLER, new HttpRequestEncoder())// + .addLast(AHC_HANDLER, httpProcessor); if (asyncHttpProviderConfig.getWssAdditionalChannelInitializer() != null) { asyncHttpProviderConfig.getWssAdditionalChannelInitializer().initChannel(ch); @@ -299,15 +276,26 @@ protected void initChannel(Channel ch) throws Exception { }); } - private SSLEngine createSSLEngine() throws IOException, GeneralSecurityException { - SSLEngine sslEngine = config.getSSLEngineFactory().newSSLEngine(); - if (sslEngine == null) { - sslEngine = SslUtils.getSSLEngine(); + public Bootstrap getBootstrap(String url, boolean useSSl) { + return url.startsWith(WEBSOCKET) ? (useSSl ? secureWebSocketBootstrap : webSocketBootstrap) : (useSSl ? secureBootstrap : plainBootstrap); + } + + public void close() { + connectionsPool.destroy(); + for (Channel channel : openChannels) { + Object attribute = getDefaultAttribute(channel); + if (attribute instanceof NettyResponseFuture) { + NettyResponseFuture future = (NettyResponseFuture) attribute; + future.setReaperFuture(null); + } + } + openChannels.close(); + if (allowReleaseEventLoopGroup) { + eventLoopGroup.shutdownGracefully(); } - return sslEngine; } - // FIXME what for? + // some servers can use the same port for HTTP and HTTPS public Channel verifyChannelPipeline(Channel channel, String scheme) throws IOException, GeneralSecurityException { if (channel.pipeline().get(SSL_HANDLER) != null && HTTP.equalsIgnoreCase(scheme)) { @@ -507,26 +495,4 @@ public static void setDefaultAttribute(Channel channel, Object o) { public static void setDefaultAttribute(ChannelHandlerContext ctx, Object o) { ctx.attr(DEFAULT_ATTRIBUTE).set(o); } - - private static class NonConnectionsPool implements ConnectionsPool { - - public boolean offer(String uri, Channel connection) { - return false; - } - - public Channel poll(String uri) { - return null; - } - - public boolean removeAll(Channel connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - } - } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NettyConnectionsPool.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NettyConnectionsPool.java index 0da9e4a0cd..b9abe8c925 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectionsPool.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NettyConnectionsPool.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.channel; import static org.asynchttpclient.util.DateUtil.millisTime; import io.netty.channel.Channel; @@ -26,6 +26,8 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionsPool; +import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NonConnectionsPool.java similarity index 50% rename from providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NonConnectionsPool.java index d68cdb947d..c4a7961c76 100644 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProviderUtil.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/NonConnectionsPool.java @@ -1,5 +1,5 @@ /* - * Copyright 2010 Ning, Inc. + * Copyright 2010-2013 Ning, Inc. * * Ning 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 @@ -13,17 +13,30 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.channel; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; +import io.netty.channel.Channel; -public class NettyProviderUtil { +import org.asynchttpclient.ConnectionsPool; - public static AsyncHttpClient nettyProvider(AsyncHttpClientConfig config) { - if (config == null) { - config = new AsyncHttpClientConfig.Builder().build(); - } - return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config); +public class NonConnectionsPool implements ConnectionsPool { + + public boolean offer(String uri, Channel connection) { + return false; + } + + public Channel poll(String uri) { + return null; + } + + public boolean removeAll(Channel connection) { + return false; + } + + public boolean canCacheConnection() { + return true; + } + + public void destroy() { } -} +} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/FutureReaper.java similarity index 91% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/FutureReaper.java index 974e2bc618..550b9d135c 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FutureReaper.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/FutureReaper.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.future; import static org.asynchttpclient.util.DateUtil.millisTime; @@ -9,12 +9,17 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Because some implementation of the ThreadSchedulingService do not clean up cancel task until they try to run them, we wrap the task with the future so the when the NettyResponseFuture cancel the reaper future this wrapper will release the references to the channel and the * nettyResponseFuture immediately. Otherwise, the memory referenced this way will only be released after the request timeout period which can be arbitrary long. */ public final class FutureReaper implements Runnable { + + private static final Logger LOGGER = LoggerFactory.getLogger(FutureReaper.class); private final AtomicBoolean closed; private final Channels channels; @@ -70,7 +75,7 @@ public boolean isDone() { } private void expire(String message) { - NettyAsyncHttpProvider.LOGGER.debug("{} for {}", message, nettyResponseFuture); + LOGGER.debug("{} for {}", message, nettyResponseFuture); channels.abort(nettyResponseFuture, new TimeoutException(message)); nettyResponseFuture = null; } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java index 65fa6c714d..ff5790ca3a 100755 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.future; import static org.asynchttpclient.util.DateUtil.millisTime; import io.netty.channel.Channel; @@ -38,6 +38,8 @@ import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; import org.asynchttpclient.listenable.AbstractListenableFuture; +import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.channel.Channels; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -256,7 +258,7 @@ public V getContent() throws ExecutionException { currentRetry.set(maxRetry); if (exEx.get() == null && !contentProcessed.getAndSet(true)) { try { - update = (V) asyncHandler.onCompleted(); + update = asyncHandler.onCompleted(); } catch (Throwable ex) { if (!throwableCalled.getAndSet(true)) { try { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFutures.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFutures.java index 2d3d34f74b..3b87f48127 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponseFutures.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFutures.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.future; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpRequest; diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java new file mode 100644 index 0000000000..a5d689ac91 --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -0,0 +1,450 @@ +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.handler; + +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static org.asynchttpclient.providers.netty.util.HttpUtil.isNTLM; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.LastHttpContent; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicReference; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.AsyncHandler.STATE; +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.ResponseFilter; +import org.asynchttpclient.ntlm.NTLMEngine; +import org.asynchttpclient.ntlm.NTLMEngineException; +import org.asynchttpclient.spnego.SpnegoEngine; +import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.request.NettyRequestSender; +import org.asynchttpclient.providers.netty.response.ResponseBodyPart; +import org.asynchttpclient.providers.netty.response.ResponseHeaders; +import org.asynchttpclient.providers.netty.response.ResponseStatus; +import org.asynchttpclient.util.AsyncHttpProviderUtils; + +final class HttpProtocol extends Protocol { + + public HttpProtocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { + super(channels, config, requestSender); + } + + private Realm kerberosChallenge(List proxyAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + + URI uri = request.getURI(); + String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost(); + String server = proxyServer == null ? host : proxyServer.getHost(); + try { + String challengeHeader = SpnegoEngine.instance().generateToken(server); + headers.remove(HttpHeaders.Names.AUTHORIZATION); + headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); + + Realm.RealmBuilder realmBuilder; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + } else { + realmBuilder = new Realm.RealmBuilder(); + } + return realmBuilder.setUri(uri.getRawPath()).setMethodName(request.getMethod()).setScheme(Realm.AuthScheme.KERBEROS).build(); + } catch (Throwable throwable) { + if (isNTLM(proxyAuth)) { + return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); + } + channels.abort(future, throwable); + return null; + } + } + + private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + + boolean useRealm = (proxyServer == null && realm != null); + + String ntlmDomain = useRealm ? realm.getNtlmDomain() : proxyServer.getNtlmDomain(); + String ntlmHost = useRealm ? realm.getNtlmHost() : proxyServer.getHost(); + String principal = useRealm ? realm.getPrincipal() : proxyServer.getPrincipal(); + String password = useRealm ? realm.getPassword() : proxyServer.getPassword(); + + Realm newRealm; + if (realm != null && !realm.isNtlmMessageType2Received()) { + String challengeHeader = NTLMEngine.INSTANCE.generateType1Msg(ntlmDomain, ntlmHost); + + URI uri = request.getURI(); + headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); + newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(uri.getRawPath()).setMethodName(request.getMethod()) + .setNtlmMessageType2Received(true).build(); + future.getAndSetAuth(false); + } else { + addType3NTLMAuthorizationHeader(wwwAuth, headers, principal, password, ntlmDomain, ntlmHost); + + Realm.RealmBuilder realmBuilder; + Realm.AuthScheme authScheme; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + authScheme = realm.getAuthScheme(); + } else { + realmBuilder = new Realm.RealmBuilder(); + authScheme = Realm.AuthScheme.NTLM; + } + newRealm = realmBuilder.setScheme(authScheme).setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); + } + + return newRealm; + } + + private Realm ntlmProxyChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, + NettyResponseFuture future) throws NTLMEngineException { + future.getAndSetAuth(false); + headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); + + addType3NTLMAuthorizationHeader(wwwAuth, headers, proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost()); + + Realm newRealm; + Realm.RealmBuilder realmBuilder; + if (realm != null) { + realmBuilder = new Realm.RealmBuilder().clone(realm); + } else { + realmBuilder = new Realm.RealmBuilder(); + } + newRealm = realmBuilder// .setScheme(realm.getAuthScheme()) + .setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); + + return newRealm; + } + + private void addType3NTLMAuthorizationHeader(List auth, FluentCaseInsensitiveStringsMap headers, String username, String password, String domain, String workstation) + throws NTLMEngineException { + headers.remove(HttpHeaders.Names.AUTHORIZATION); + + if (isNTLM(auth)) { + String serverChallenge = auth.get(0).trim().substring("NTLM ".length()); + String challengeHeader = NTLMEngine.INSTANCE.generateType3Msg(username, password, domain, workstation, serverChallenge); + + headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); + } + } + + private List getAuthorizationToken(Iterable> list, String headerAuth) { + ArrayList l = new ArrayList(); + for (Entry e : list) { + if (e.getKey().equalsIgnoreCase(headerAuth)) { + l.add(e.getValue().trim()); + } + } + return l; + } + + private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { + if (lastValidChunk && future.isKeepAlive()) { + channels.drainChannel(ctx, future); + } else { + if (future.isKeepAlive() && ctx.channel().isActive() && channels.offerToPool(channels.getPoolKey(future), ctx.channel())) { + markAsDone(future, ctx); + return; + } + channels.finishChannel(ctx); + } + markAsDone(future, ctx); + } + + private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { + boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; + if (c.closeUnderlyingConnection()) { + future.setKeepAlive(false); + } + return state; + } + + private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { + // We need to make sure everything is OK before adding the + // connection back to the pool. + try { + future.done(); + } catch (Throwable t) { + // Never propagate exception once we know we are done. + NettyChannelHandler.LOGGER.debug(t.getMessage(), t); + } + + if (!future.isKeepAlive() || !ctx.channel().isActive()) { + channels.closeChannel(ctx); + } + } + + private boolean applyResponseFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, HttpResponseStatus status, + HttpResponseHeaders responseHeaders) throws IOException { + + AsyncHandler handler = future.getAsyncHandler(); + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(future.getRequest()).responseStatus(status).responseHeaders(responseHeaders) + .build(); + + for (ResponseFilter asyncFilter : config.getResponseFilters()) { + try { + fc = asyncFilter.filter(fc); + // FIXME Is it worth protecting against this? + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + // The handler may have been wrapped. + handler = fc.getAsyncHandler(); + future.setAsyncHandler(handler); + + // The request has changed + if (fc.replayRequest()) { + requestSender.replayRequest(future, fc, ctx); + return true; + } + return false; + } + + private boolean handleResponseAndExit(final ChannelHandlerContext ctx, final NettyResponseFuture future, AsyncHandler handler, HttpRequest nettyRequest, + ProxyServer proxyServer, HttpResponse response) throws Exception { + Request request = future.getRequest(); + int statusCode = response.getStatus().code(); + HttpResponseStatus status = new ResponseStatus(future.getURI(), response); + HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); + final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); + final RequestBuilder builder = new RequestBuilder(future.getRequest()); + Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); + + // store the original headers so we can re-send all them to + // the handler in case of trailing headers + future.setHttpResponse(response); + + future.setKeepAlive(!HttpHeaders.Values.CLOSE.equalsIgnoreCase(response.headers().get(HttpHeaders.Names.CONNECTION))); + + if (!config.getResponseFilters().isEmpty() && applyResponseFiltersAndReplayRequest(ctx, future, status, responseHeaders)) { + return true; + } + + // FIXME handle without returns + if (statusCode == UNAUTHORIZED.code() && realm != null) { + List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); + if (!wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + // NTLM + boolean negociate = wwwAuth.contains("Negotiate"); + if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || negociate)) { + newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + return true; + } + } else { + newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()).setMethodName(request.getMethod()) + .setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); + } + + final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); + + NettyChannelHandler.LOGGER.debug("Sending authentication to {}", request.getUrl()); + Callback callback = new Callback(future) { + public void call() throws Exception { + channels.drainChannel(ctx, future); + requestSender.sendNextRequest(builder.setHeaders(headers).setRealm(nr).build(), future); + } + }; + + if (future.isKeepAlive() && HttpHeaders.isTransferEncodingChunked(response)) { + // We must make sure there is no bytes left + // before executing the next request. + Channels.setDefaultAttribute(ctx, callback); + } else { + callback.call(); + } + + return true; + } + + } else if (statusCode == CONTINUE.code()) { + future.getAndSetWriteHeaders(false); + future.getAndSetWriteBody(true); + // FIXME why not reuse the channel? + requestSender.writeRequest(ctx.channel(), config, future); + return true; + + } else if (statusCode == PROXY_AUTHENTICATION_REQUIRED.code()) { + List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); + if (realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { + NettyChannelHandler.LOGGER.debug("Sending proxy authentication to {}", request.getUrl()); + + future.setState(NettyResponseFuture.STATE.NEW); + Realm newRealm = null; + + boolean negociate = proxyAuth.contains("Negotiate"); + if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || negociate)) { + newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); + // SPNEGO KERBEROS + } else if (negociate) { + newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); + if (newRealm == null) { + return true; + } + } else { + newRealm = future.getRequest().getRealm(); + } + + future.setReuseChannel(true); + future.setConnectAllowed(true); + requestSender.sendNextRequest(builder.setHeaders(headers).setRealm(newRealm).build(), future); + return true; + } + + } else if (statusCode == OK.code() && nettyRequest.getMethod() == HttpMethod.CONNECT) { + + NettyChannelHandler.LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); + + if (future.isKeepAlive()) { + future.attachChannel(ctx.channel(), true); + } + + try { + NettyChannelHandler.LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); + channels.upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); + } catch (Throwable ex) { + channels.abort(future, ex); + } + future.setReuseChannel(true); + future.setConnectAllowed(false); + requestSender.sendNextRequest(builder.build(), future); + return true; + + } + + if (redirect(request, future, response, ctx)) { + return true; + } + + if (!future.getAndSetStatusReceived(true) && (handler.onStatusReceived(status) != STATE.CONTINUE || handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE)) { + finishUpdate(future, ctx, HttpHeaders.isTransferEncodingChunked(response)); + return true; + } + + return false; + } + + @Override + public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture future, final Object e) throws Exception { + future.touch(); + + // The connect timeout occurred. + if (future.isCancelled() || future.isDone()) { + channels.finishChannel(ctx); + return; + } + + HttpRequest nettyRequest = future.getNettyRequest(); + AsyncHandler handler = future.getAsyncHandler(); + Request request = future.getRequest(); + ProxyServer proxyServer = future.getProxyServer(); + try { + if (e instanceof HttpResponse) { + HttpResponse response = (HttpResponse) e; + NettyChannelHandler.LOGGER.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); + future.getPendingResponse().set(response); + return; + } + + if (e instanceof HttpContent) { + + AtomicReference responseRef = future.getPendingResponse(); + HttpResponse response = responseRef.getAndSet(null); + if (handler != null) { + if (response != null && handleResponseAndExit(ctx, future, handler, nettyRequest, proxyServer, response)) { + return; + } + + HttpContent chunk = (HttpContent) e; + + boolean interrupt = false; + boolean last = chunk instanceof LastHttpContent; + + // FIXME + // Netty 3 provider is broken: in case of trailing headers, + // onHeadersReceived should be called before + // updateBodyAndInterrupt + if (last) { + LastHttpContent lastChunk = (LastHttpContent) chunk; + HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); + if (!trailingHeaders.isEmpty()) { + interrupt = handler.onHeadersReceived(new ResponseHeaders(future.getURI(), future.getHttpResponse().headers(), trailingHeaders)) != STATE.CONTINUE; + } + } + + if (!interrupt && chunk.content().readableBytes() > 0) { + // FIXME why + interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); + } + + if (interrupt || last) { + finishUpdate(future, ctx, !last); + } + } + } + } catch (Exception t) { + if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty() + && requestSender.applyIoExceptionFiltersAndReplayRequest(ctx, future, IOException.class.cast(t))) { + return; + } + + try { + channels.abort(future, t); + } finally { + finishUpdate(future, ctx, false); + throw t; + } + } + } + + @Override + public void onError(ChannelHandlerContext ctx, Throwable error) { + } + + @Override + public void onClose(ChannelHandlerContext ctx) { + } +} \ No newline at end of file diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java new file mode 100644 index 0000000000..fb47346455 --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java @@ -0,0 +1,199 @@ +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.handler; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.PrematureChannelClosureException; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.LastHttpContent; + +import java.io.IOException; +import java.nio.channels.ClosedChannelException; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.future.NettyResponseFutures; +import org.asynchttpclient.providers.netty.request.NettyRequestSender; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Sharable +public class NettyChannelHandler extends ChannelInboundHandlerAdapter { + + static final Logger LOGGER = LoggerFactory.getLogger(NettyChannelHandler.class); + + private final AsyncHttpClientConfig config; + private final NettyRequestSender requestSender; + private final Channels channels; + private final AtomicBoolean closed; + private final Protocol httpProtocol; + private final Protocol webSocketProtocol; + + public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requestSender, Channels channels, AtomicBoolean isClose) { + this.config = config; + this.requestSender = requestSender; + this.channels = channels; + this.closed = isClose; + httpProtocol = new HttpProtocol(channels, config, requestSender); + webSocketProtocol = new WebSocketProtocol(channels, config, requestSender); + } + + @Override + public void channelRead(final ChannelHandlerContext ctx, Object e) throws Exception { + + Object attribute = Channels.getDefaultAttribute(ctx); + + // FIXME is || !(e instanceof HttpContent) necessary? + if (attribute instanceof Callback && (e instanceof LastHttpContent /* || !(e instanceof HttpContent) */)) { + Callback ac = (Callback) attribute; + ac.call(); + Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + + } else if (attribute instanceof NettyResponseFuture) { + Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); + NettyResponseFuture future = (NettyResponseFuture) attribute; + + p.handle(ctx, future, e); + + } else if (attribute != DiscardEvent.INSTANCE) { + try { + LOGGER.trace("Closing an orphan channel {}", ctx.channel()); + ctx.channel().close(); + } catch (Throwable t) { + } + } + } + + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + + if (closed.get()) { + return; + } + + try { + super.channelInactive(ctx); + } catch (Exception ex) { + LOGGER.trace("super.channelClosed", ex); + } + + channels.removeFromPool(ctx); + Object attachment = Channels.getDefaultAttribute(ctx); + LOGGER.debug("Channel Closed: {} with attachment {}", ctx.channel(), attachment); + + if (attachment instanceof Callback) { + Callback callback = (Callback) attachment; + Channels.setDefaultAttribute(ctx, callback.future()); + callback.call(); + + } else if (attachment instanceof NettyResponseFuture) { + NettyResponseFuture future = NettyResponseFuture.class.cast(attachment); + future.touch(); + + if (!config.getIOExceptionFilters().isEmpty() && requestSender.applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { + return; + } + + Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); + p.onClose(ctx); + + if (future != null && !future.isDone() && !future.isCancelled()) { + if (!requestSender.retry(ctx.channel(), future)) { + channels.abort(future, new IOException("Remotely Closed")); + } + } else { + channels.closeChannel(ctx); + } + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { + Channel channel = ctx.channel(); + Throwable cause = e.getCause() != null ? e.getCause() : e; + NettyResponseFuture future = null; + + if (cause instanceof PrematureChannelClosureException) { + return; + } + + LOGGER.debug("Unexpected I/O exception on channel {}", channel, cause); + + try { + if (cause instanceof ClosedChannelException) { + return; + } + + Object attribute = Channels.getDefaultAttribute(ctx); + if (attribute instanceof NettyResponseFuture) { + future = (NettyResponseFuture) attribute; + future.attachChannel(null, false); + future.touch(); + + if (cause instanceof IOException) { + + // FIXME why drop the original exception and create a new + // one? + if (!config.getIOExceptionFilters().isEmpty()) { + if (requestSender.applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { + return; + } + } else { + // Close the channel so the recovering can occurs. + try { + ctx.channel().close(); + } catch (Throwable t) { + // Swallow. + } + return; + } + } + + if (NettyResponseFutures.abortOnReadCloseException(cause) || NettyResponseFutures.abortOnWriteCloseException(cause)) { + LOGGER.debug("Trying to recover from dead Channel: {}", channel); + return; + } + } else if (attribute instanceof Callback) { + future = Callback.class.cast(attribute).future(); + } + } catch (Throwable t) { + cause = t; + } + + if (future != null) { + try { + LOGGER.debug("Was unable to recover Future: {}", future); + channels.abort(future, cause); + } catch (Throwable t) { + LOGGER.error(t.getMessage(), t); + } + } + + Protocol protocol = ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol; + protocol.onError(ctx, e); + + channels.closeChannel(ctx); + // FIXME not really sure + // ctx.fireChannelRead(e); + ctx.close(); + } +} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java new file mode 100644 index 0000000000..dcd456f41d --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.asynchttpclient.providers.netty.handler; + +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import static org.asynchttpclient.providers.netty.util.HttpUtil.*; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpResponse; + +import java.net.URI; + +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.Cookie; +import org.asynchttpclient.MaxRedirectException; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; +import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.request.NettyRequestSender; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class Protocol { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + protected final Channels channels; + protected final AsyncHttpClientConfig config; + protected final NettyRequestSender requestSender; + + public Protocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { + this.channels = channels; + this.config = config; + this.requestSender = requestSender; + } + + public abstract void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception; + + public abstract void onError(ChannelHandlerContext ctx, Throwable error); + + public abstract void onClose(ChannelHandlerContext ctx); + + protected boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { + + io.netty.handler.codec.http.HttpResponseStatus status = response.getStatus(); + boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); + boolean isRedirectStatus = status.equals(MOVED_PERMANENTLY) || status.equals(FOUND) || status.equals(SEE_OTHER) || status.equals(TEMPORARY_REDIRECT); + if (redirectEnabled && isRedirectStatus) { + + if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { + // We must allow 401 handling again. + future.getAndSetAuth(false); + + String location = response.headers().get(HttpHeaders.Names.LOCATION); + URI uri = AsyncHttpProviderUtils.getRedirectUri(future.getURI(), location); + + if (!uri.toString().equals(future.getURI().toString())) { + final RequestBuilder nBuilder = new RequestBuilder(future.getRequest()); + if (config.isRemoveQueryParamOnRedirect()) { + nBuilder.setQueryParameters(null); + } + + // FIXME why not do that for 301 and 307 too? + if ((status.equals(FOUND) || status.equals(SEE_OTHER)) && !(status.equals(FOUND) && config.isStrict302Handling())) { + nBuilder.setMethod(HttpMethod.GET.name()); + } + + // in case of a redirect from HTTP to HTTPS, future attributes might change + final boolean initialConnectionKeepAlive = future.isKeepAlive(); + final String initialPoolKey = channels.getPoolKey(future); + + future.setURI(uri); + String newUrl = uri.toString(); + if (request.getUrl().startsWith(WEBSOCKET)) { + newUrl = newUrl.replace(HTTP, WEBSOCKET); + } + + logger.debug("Redirecting to {}", newUrl); + + for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE)) { + for (Cookie c : CookieDecoder.decode(cookieStr)) { + nBuilder.addOrReplaceCookie(c); + } + } + + for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE2)) { + for (Cookie c : CookieDecoder.decode(cookieStr)) { + nBuilder.addOrReplaceCookie(c); + } + } + + Callback callback = new Callback(future) { + public void call() throws Exception { + if (!(initialConnectionKeepAlive && ctx.channel().isActive() && channels.offerToPool(initialPoolKey, ctx.channel()))) { + channels.finishChannel(ctx); + } + } + }; + + if (HttpHeaders.isTransferEncodingChunked(response)) { + // We must make sure there is no bytes left before + // executing the next request. + // FIXME investigate this + Channels.setDefaultAttribute(ctx, callback); + } else { + // FIXME don't understand: this offers the connection to the pool, or even closes it, while the request has not been sent, right? + callback.call(); + } + + Request target = nBuilder.setUrl(newUrl).build(); + future.setRequest(target); + // FIXME why not reuse the channel is same host? + requestSender.sendNextRequest(target, future); + return true; + } + } else { + throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); + } + } + return false; + } +} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java new file mode 100644 index 0000000000..eee8b91515 --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java @@ -0,0 +1,221 @@ +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.handler; + +import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; +import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; +import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; +import io.netty.handler.codec.http.websocketx.WebSocketFrame; + +import java.io.IOException; + +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Request; +import org.asynchttpclient.AsyncHandler.STATE; +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.ResponseFilter; +import org.asynchttpclient.providers.netty.Constants; +import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.request.NettyRequestSender; +import org.asynchttpclient.providers.netty.response.ResponseBodyPart; +import org.asynchttpclient.providers.netty.response.ResponseHeaders; +import org.asynchttpclient.providers.netty.response.ResponseStatus; +import org.asynchttpclient.providers.netty.ws.NettyWebSocket; +import org.asynchttpclient.providers.netty.ws.WebSocketUtil; +import org.asynchttpclient.websocket.WebSocketUpgradeHandler; + +final class WebSocketProtocol extends Protocol { + + private static final byte OPCODE_TEXT = 0x1; + private static final byte OPCODE_BINARY = 0x2; + private static final byte OPCODE_UNKNOWN = -1; + protected byte pendingOpcode = OPCODE_UNKNOWN; + + public WebSocketProtocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { + super(channels, config, requestSender); + } + + // We don't need to synchronize as replacing the "ws-decoder" will + // process using the same thread. + private void invokeOnSucces(ChannelHandlerContext ctx, WebSocketUpgradeHandler h) { + if (!h.touchSuccess()) { + try { + h.onSuccess(new NettyWebSocket(ctx.channel())); + } catch (Exception ex) { + NettyChannelHandler.LOGGER.warn("onSuccess unexpected exception", ex); + } + } + } + + @Override + public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object e) throws Exception { + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler()); + Request request = future.getRequest(); + + if (e instanceof HttpResponse) { + HttpResponse response = (HttpResponse) e; + + HttpResponseStatus s = new ResponseStatus(future.getURI(), response); + HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); + + // FIXME there's a method for that IIRC + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(h).request(request).responseStatus(s).responseHeaders(responseHeaders).build(); + for (ResponseFilter asyncFilter : config.getResponseFilters()) { + try { + fc = asyncFilter.filter(fc); + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + // The handler may have been wrapped. + future.setAsyncHandler(fc.getAsyncHandler()); + + // The request has changed + if (fc.replayRequest()) { + requestSender.replayRequest(future, fc, ctx); + return; + } + + future.setHttpResponse(response); + if (redirect(request, future, response, ctx)) + return; + + boolean validStatus = response.getStatus().equals(SWITCHING_PROTOCOLS); + boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null; + String c = response.headers().get(HttpHeaders.Names.CONNECTION); + if (c == null) { + c = response.headers().get(HttpHeaders.Names.CONNECTION.toLowerCase()); + } + + boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); + + s = new ResponseStatus(future.getURI(), response); + final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; + + final boolean headerOK = h.onHeadersReceived(responseHeaders) == STATE.CONTINUE; + if (!headerOK || !validStatus || !validUpgrade || !validConnection || !statusReceived) { + channels.abort(future, new IOException("Invalid handshake response")); + return; + } + + String accept = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT); + String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().headers().get(HttpHeaders.Names.SEC_WEBSOCKET_KEY)); + if (accept == null || !accept.equals(key)) { + throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); + } + + Channels.upgradePipelineForWebSockets(ctx); + + invokeOnSucces(ctx, h); + future.done(); + + } else if (e instanceof WebSocketFrame) { + + final WebSocketFrame frame = (WebSocketFrame) e; + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + invokeOnSucces(ctx, h); + + if (webSocket != null) { + if (frame instanceof CloseWebSocketFrame) { + Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); + CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); + webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); + } else { + if (frame instanceof TextWebSocketFrame) { + pendingOpcode = OPCODE_TEXT; + } else if (frame instanceof BinaryWebSocketFrame) { + pendingOpcode = OPCODE_BINARY; + } + + if (frame.content() != null && frame.content().readableBytes() > 0) { + ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); + h.onBodyPartReceived(rp); + + if (pendingOpcode == OPCODE_BINARY) { + webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); + } else { + webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); + } + } + } + } else { + NettyChannelHandler.LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); + } + } else if (e instanceof LastHttpContent) { + // FIXME what to do with this kind of messages? + } else { + NettyChannelHandler.LOGGER.error("Invalid message {}", e); + } + } + + @Override + public void onError(ChannelHandlerContext ctx, Throwable e) { + try { + Object attribute = Channels.getDefaultAttribute(ctx); + NettyChannelHandler.LOGGER.warn("onError {}", e); + if (!(attribute instanceof NettyResponseFuture)) { + return; + } + + NettyResponseFuture nettyResponse = (NettyResponseFuture) attribute; + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); + + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + if (webSocket != null) { + webSocket.onError(e.getCause()); + webSocket.close(); + } + } catch (Throwable t) { + NettyChannelHandler.LOGGER.error("onError", t); + } + } + + @Override + public void onClose(ChannelHandlerContext ctx) { + NettyChannelHandler.LOGGER.trace("onClose {}"); + Object attribute = Channels.getDefaultAttribute(ctx); + if (!(attribute instanceof NettyResponseFuture)) { + return; + } + + try { + NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(attribute); + WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); + NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); + + // FIXME How could this test not succeed, attachment is a + // NettyResponseFuture???? + if (attribute != DiscardEvent.INSTANCE) + webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent)."); + } catch (Throwable t) { + NettyChannelHandler.LOGGER.error("onError", t); + } + } +} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyChunkedInput.java similarity index 97% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyChunkedInput.java index 22d6b15e92..0bfb24ca2f 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyChunkedInput.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyChunkedInput.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.request; import org.asynchttpclient.Body; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyFileRegion.java similarity index 97% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyFileRegion.java index 7a2db0bd79..3cd6664ebb 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/BodyFileRegion.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/BodyFileRegion.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.request; import io.netty.channel.FileRegion; import io.netty.util.AbstractReferenceCounted; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/FeedableBodyGenerator.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/FeedableBodyGenerator.java index 7bcd37442d..95f3e61024 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/FeedableBodyGenerator.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/FeedableBodyGenerator.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.request; import java.io.IOException; import java.nio.ByteBuffer; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyConnectListener.java similarity index 87% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyConnectListener.java index 052cf816a3..1135547e2d 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyConnectListener.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyConnectListener.java @@ -14,7 +14,7 @@ * under the License. * */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.request; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; @@ -27,12 +27,13 @@ import java.net.URI; import java.nio.channels.ClosedChannelException; -import javax.net.ssl.HostnameVerifier; - import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.future.NettyResponseFutures; import org.asynchttpclient.util.ProxyUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,24 +59,20 @@ public NettyResponseFuture future() { return future; } - private void onFutureSuccess(final Channel channel) throws Exception { + public void onFutureSuccess(final Channel channel) throws ConnectException { Channels.setDefaultAttribute(channel, future); SslHandler sslHandler = Channels.getSslHandler(channel); - if (sslHandler != null) { - // FIXME done on connect or on every request? - HostnameVerifier v = config.getHostnameVerifier(); - if (!v.verify(future.getURI().getHost(), sslHandler.engine().getSession())) { - ConnectException exception = new ConnectException("HostnameVerifier exception."); - future.abort(exception); - throw exception; - } + if (sslHandler != null && !config.getHostnameVerifier().verify(future.getURI().getHost(), sslHandler.engine().getSession())) { + ConnectException exception = new ConnectException("HostnameVerifier exception"); + future.abort(exception); + throw exception; } requestSender.writeRequest(channel, config, future); } - private void onFutureFailure(Channel channel, Throwable cause) throws Exception { + public void onFutureFailure(Channel channel, Throwable cause) { logger.debug("Trying to recover a dead cached channel {} with a retry value of {} ", channel, future.canRetry()); if (future.canRetry() && cause != null diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java similarity index 64% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java index 2f0ce718c1..8dd47cbae2 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java @@ -1,12 +1,27 @@ -package org.asynchttpclient.providers.netty4; - -import static org.asynchttpclient.providers.netty4.util.HttpUtil.WEBSOCKET; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.request; + +import static org.asynchttpclient.providers.netty.util.HttpUtil.*; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelProgressiveFuture; +import io.netty.channel.DefaultFileRegion; import io.netty.channel.FileRegion; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; @@ -33,17 +48,24 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Body; import org.asynchttpclient.BodyGenerator; +import org.asynchttpclient.ConnectionPoolKeyStrategy; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.RandomAccessBody; import org.asynchttpclient.Request; import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.IOExceptionFilter; import org.asynchttpclient.generators.InputStreamBodyGenerator; import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.listener.TransferCompletionHandler.TransferAdapter; import org.asynchttpclient.multipart.MultipartBody; -import org.asynchttpclient.providers.netty4.FeedableBodyGenerator.FeedListener; +import org.asynchttpclient.providers.netty.Constants; +import org.asynchttpclient.providers.netty.channel.Channels; +import org.asynchttpclient.providers.netty.future.FutureReaper; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.future.NettyResponseFutures; +import org.asynchttpclient.providers.netty.request.FeedableBodyGenerator.FeedListener; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.asynchttpclient.util.ProxyUtils; import org.asynchttpclient.websocket.WebSocketUpgradeHandler; @@ -84,7 +106,7 @@ public boolean retry(Channel channel, NettyResponseFuture future) { LOGGER.debug("Trying to recover request {}\n", future.getNettyRequest()); try { - execute(future.getRequest(), future); + sendNextRequest(future.getRequest(), future); success = true; } catch (IOException iox) { @@ -99,10 +121,32 @@ public boolean retry(Channel channel, NettyResponseFuture future) { return success; } - // FIXME Netty 3: only called from nextRequest, useCache, asyncConnect and - // reclaimCache always passed as true - public void execute(final Request request, final NettyResponseFuture f) throws IOException { - doConnect(request, f.getAsyncHandler(), f, true, true, true); + public boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, IOException e) throws IOException { + + boolean replayed = false; + + FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(e).build(); + for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { + try { + fc = asyncFilter.filter(fc); + if (fc == null) { + throw new NullPointerException("FilterContext is null"); + } + } catch (FilterException efe) { + channels.abort(future, efe); + } + } + + if (fc.replayRequest()) { + replayRequest(future, fc, ctx); + replayed = true; + } + return replayed; + } + + public void sendNextRequest(final Request request, final NettyResponseFuture f) throws IOException { + // FIXME Why is sendNextRequest always asyncConnect? + sendRequest(request, f.getAsyncHandler(), f, true, true); } // FIXME is this useful? Can't we do that when building the request? @@ -110,105 +154,124 @@ private final boolean validateWebSocketRequest(Request request, AsyncHandler return request.getMethod().equals(HttpMethod.GET.name()) && asyncHandler instanceof WebSocketUpgradeHandler; } - public ListenableFuture doConnect(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture future, boolean useCache, boolean asyncConnect, - boolean reclaimCache) throws IOException { + private Channel getCachedChannel(NettyResponseFuture future, URI uri, ConnectionPoolKeyStrategy poolKeyGen, ProxyServer proxyServer) { - if (closed.get()) { - throw new IOException("Closed"); - } - - if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) { - throw new IOException("WebSocket method must be a GET"); + if (future != null && future.reuseChannel() && future.channel() != null) { + return future.channel(); + } else { + URI connectionKeyUri = proxyServer != null ? proxyServer.getURI() : uri; + return channels.lookupInCache(connectionKeyUri, poolKeyGen); } + } - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - boolean useProxy = proxyServer != null; + private ListenableFuture sendRequestWithCachedChannel(Channel channel, Request request, URI uri, ProxyServer proxy, NettyResponseFuture future, + AsyncHandler asyncHandler) throws IOException { + HttpRequest nettyRequest = null; - URI uri; - if (config.isUseRawUrl()) { - uri = request.getRawURI(); + if (future == null) { + nettyRequest = NettyRequests.newNettyRequest(config, request, uri, false, proxy); + future = NettyResponseFutures.newNettyResponseFuture(uri, request, asyncHandler, nettyRequest, config, proxy); } else { - uri = request.getURI(); + nettyRequest = NettyRequests.newNettyRequest(config, request, uri, future.isConnectAllowed(), proxy); + future.setNettyRequest(nettyRequest); } - Channel channel = null; + future.setState(NettyResponseFuture.STATE.POOLED); + future.attachChannel(channel, false); + + LOGGER.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest); + Channels.setDefaultAttribute(channel, future); - if (useCache) { - if (future != null && future.reuseChannel() && future.channel() != null) { - channel = future.channel(); + try { + writeRequest(channel, config, future); + } catch (Exception ex) { + LOGGER.debug("writeRequest failure", ex); + if (ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) { + LOGGER.debug("SSLEngine failure", ex); + future = null; } else { - URI connectionKeyUri = useProxy ? proxyServer.getURI() : uri; - channel = channels.lookupInCache(connectionKeyUri, request.getConnectionPoolKeyStrategy()); + try { + asyncHandler.onThrowable(ex); + } catch (Throwable t) { + LOGGER.warn("doConnect.writeRequest()", t); + } + IOException ioe = new IOException(ex.getMessage()); + ioe.initCause(ex); + throw ioe; } } + return future; + } - boolean useSSl = isSecure(uri) && !useProxy; - if (channel != null && channel.isOpen() && channel.isActive()) { - HttpRequest nettyRequest = null; + private ChannelFuture connect(Request request, URI uri, ProxyServer proxy, Bootstrap bootstrap) { + InetSocketAddress remoteAddress; + if (request.getInetAddress() != null) { + remoteAddress = new InetSocketAddress(request.getInetAddress(), AsyncHttpProviderUtils.getPort(uri)); + } else if (proxy == null || ProxyUtils.avoidProxy(proxy, uri.getHost())) { + remoteAddress = new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)); + } else { + remoteAddress = new InetSocketAddress(proxy.getHost(), proxy.getPort()); + } - if (future == null) { - nettyRequest = NettyRequests.newNettyRequest(config, request, uri, false, proxyServer); - future = NettyResponseFutures.newNettyResponseFuture(uri, request, asyncHandler, nettyRequest, config, proxyServer); - } else { - nettyRequest = NettyRequests.newNettyRequest(config, request, uri, future.isConnectAllowed(), proxyServer); - future.setNettyRequest(nettyRequest); - } - future.setState(NettyResponseFuture.STATE.POOLED); - future.attachChannel(channel, false); + if (request.getLocalAddress() != null) { + return bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); + } else { + return bootstrap.connect(remoteAddress); + } + } - LOGGER.debug("\nUsing cached Channel {}\n for request \n{}\n", channel, nettyRequest); - Channels.setDefaultAttribute(channel, future); + private void performSyncConnect(ChannelFuture channelFuture, URI uri, boolean acquiredConnection, NettyConnectListener cl, AsyncHandler asyncHandler) throws IOException { - try { - writeRequest(channel, config, future); - } catch (Exception ex) { - LOGGER.debug("writeRequest failure", ex); - if (useSSl && ex.getMessage() != null && ex.getMessage().contains("SSLEngine")) { - LOGGER.debug("SSLEngine failure", ex); - future = null; - } else { - try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - LOGGER.warn("doConnect.writeRequest()", t); - } - IOException ioe = new IOException(ex.getMessage()); - ioe.initCause(ex); - throw ioe; - } + try { + channelFuture.syncUninterruptibly(); + } catch (Throwable t) { + if (t.getCause() != null) + t = t.getCause(); + + ConnectException ce = null; + if (t instanceof ConnectException) + ce = ConnectException.class.cast(t); + else + ce = new ConnectException(t.getMessage()); + + if (acquiredConnection) { + channels.releaseFreeConnections(); } - return future; + channelFuture.cancel(false); + channels.abort(cl.future(), ce); } - // Do not throw an exception when we need an extra connection for a - // redirect. - boolean acquiredConnection = !reclaimCache && channels.acquireConnection(asyncHandler); - - NettyConnectListener cl = new NettyConnectListener.Builder(config, this, request, asyncHandler, future).build(uri); + try { + cl.operationComplete(channelFuture); + } catch (Exception e) { + if (acquiredConnection) { + channels.releaseFreeConnections(); + } + IOException ioe = new IOException(e.getMessage()); + ioe.initCause(e); + try { + asyncHandler.onThrowable(ioe); + } catch (Throwable t) { + LOGGER.warn("c.operationComplete()", t); + } + throw ioe; + } + } - boolean avoidProxy = ProxyUtils.avoidProxy(proxyServer, uri.getHost()); + private ListenableFuture sendRequestWithNewChannel(Request request, URI uri, ProxyServer proxy, NettyResponseFuture future, AsyncHandler asyncHandler, + boolean asyncConnect, boolean reclaimCache) throws IOException { - if (useSSl) { - channels.constructSSLPipeline(cl.future()); - } + boolean useSSl = isSecure(uri) && proxy == null; + // Do not throw an exception when we need an extra connection for a redirect + // FIXME why? This violate the max connection per host handling, right? + boolean acquiredConnection = !reclaimCache && channels.acquireConnection(asyncHandler); Bootstrap bootstrap = channels.getBootstrap(request.getUrl(), useSSl); + NettyConnectListener cl = new NettyConnectListener.Builder(config, this, request, asyncHandler, future).build(uri); + ChannelFuture channelFuture; try { - InetSocketAddress remoteAddress; - if (request.getInetAddress() != null) { - remoteAddress = new InetSocketAddress(request.getInetAddress(), AsyncHttpProviderUtils.getPort(uri)); - } else if (proxyServer == null || avoidProxy) { - remoteAddress = new InetSocketAddress(AsyncHttpProviderUtils.getHost(uri), AsyncHttpProviderUtils.getPort(uri)); - } else { - remoteAddress = new InetSocketAddress(proxyServer.getHost(), proxyServer.getPort()); - } - - if (request.getLocalAddress() != null) { - channelFuture = bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); - } else { - channelFuture = bootstrap.connect(remoteAddress); - } + channelFuture = connect(request, uri, proxy, bootstrap); } catch (Throwable t) { if (acquiredConnection) { @@ -220,36 +283,11 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl // FIXME what does it have to do with the presence of a file? if (!asyncConnect && request.getFile() == null) { - int timeOut = config.getConnectionTimeoutInMs() > 0 ? config.getConnectionTimeoutInMs() : Integer.MAX_VALUE; - if (!channelFuture.awaitUninterruptibly(timeOut, TimeUnit.MILLISECONDS)) { - if (acquiredConnection) { - channels.releaseFreeConnections(); - } - // FIXME false or true? - channelFuture.cancel(false); - channels.abort(cl.future(), new ConnectException(String.format("Connect operation to %s timeout %s", uri, timeOut))); - } - - try { - cl.operationComplete(channelFuture); - } catch (Exception e) { - if (acquiredConnection) { - channels.releaseFreeConnections(); - } - IOException ioe = new IOException(e.getMessage()); - ioe.initCause(e); - try { - asyncHandler.onThrowable(ioe); - } catch (Throwable t) { - LOGGER.warn("c.operationComplete()", t); - } - throw ioe; - } + performSyncConnect(channelFuture, uri, acquiredConnection, cl, asyncHandler); } else { channelFuture.addListener(cl); } - // FIXME Why non cached??? LOGGER.debug("\nNon cached request \n{}\n\nusing Channel \n{}\n", cl.future().getNettyRequest(), channelFuture.channel()); if (!cl.future().isCancelled() || !cl.future().isDone()) { @@ -259,6 +297,29 @@ public ListenableFuture doConnect(final Request request, final AsyncHandl return cl.future(); } + public ListenableFuture sendRequest(final Request request, final AsyncHandler asyncHandler, NettyResponseFuture future, boolean asyncConnect, boolean reclaimCache) + throws IOException { + + if (closed.get()) { + throw new IOException("Closed"); + } + + // FIXME really useful? Why not do this check when building the request? + if (request.getUrl().startsWith(WEBSOCKET) && !validateWebSocketRequest(request, asyncHandler)) { + throw new IOException("WebSocket method must be a GET"); + } + + URI uri = config.isUseRawUrl() ? request.getRawURI() : request.getURI(); + ProxyServer proxy = ProxyUtils.getProxyServer(config, request); + Channel channel = getCachedChannel(future, uri, request.getConnectionPoolKeyStrategy(), proxy); + + if (channel != null && channel.isOpen() && channel.isActive()) { + return sendRequestWithCachedChannel(channel, request, uri, proxy, future, asyncHandler); + } else { + return sendRequestWithNewChannel(request, uri, proxy, future, asyncHandler, asyncConnect, reclaimCache); + } + } + private void sendFileBody(Channel channel, File file, NettyResponseFuture future) throws IOException { final RandomAccessFile raf = new RandomAccessFile(file, "r"); @@ -269,10 +330,10 @@ private void sendFileBody(Channel channel, File file, NettyResponseFuture fut if (Channels.getSslHandler(channel) != null) { writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise()); } else { - // FIXME why not use io.netty.channel.DefaultFileRegion? - FileRegion region = new OptimizedFileRegion(raf, 0, fileLength); + FileRegion region = new DefaultFileRegion(raf.getChannel(), 0, fileLength); writeFuture = channel.write(region, channel.newProgressivePromise()); } + // FIXME probably useless in Netty 4 writeFuture.addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { public void operationComplete(ChannelProgressiveFuture cf) { try { @@ -389,7 +450,7 @@ private void configureTransferAdapter(AsyncHandler handler, HttpRequest netty h.add(entries.getKey(), entries.getValue()); } - TransferCompletionHandler.class.cast(handler).transferAdapter(new TransferAdapter(h)); + TransferCompletionHandler.class.cast(handler).headers(h); } private void scheduleReaper(NettyResponseFuture future) { @@ -410,7 +471,7 @@ private void scheduleReaper(NettyResponseFuture future) { } } - protected final void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture future) { + public final void writeRequest(final Channel channel, final AsyncHttpClientConfig config, final NettyResponseFuture future) { try { // If the channel is dead because it was pooled and the remote // server decided to close it, we just let it go and the @@ -474,8 +535,7 @@ protected final void writeRequest(final Channel channel, final AsyncHttpClie scheduleReaper(future); } - // FIXME Clean up Netty 3: replayRequest's response parameter is unused + - // WTF return??? + // FIXME Clean up Netty 3: replayRequest's response parameter is unused + WTF return??? public void replayRequest(final NettyResponseFuture future, FilterContext fc, ChannelHandlerContext ctx) throws IOException { Request newRequest = fc.getRequest(); future.setAsyncHandler(fc.getAsyncHandler()); @@ -484,6 +544,6 @@ public void replayRequest(final NettyResponseFuture future, FilterContext fc, LOGGER.debug("\n\nReplaying Request {}\n for Future {}\n", newRequest, future); channels.drainChannel(ctx, future); - execute(newRequest, future); + sendNextRequest(newRequest, future); } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java similarity index 92% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java index e41b387115..ad2436db13 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequests.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java @@ -1,8 +1,21 @@ -package org.asynchttpclient.providers.netty4; - -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isNTLM; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isSecure; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.isWebSocket; +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.request; + +import static org.asynchttpclient.providers.netty.util.HttpUtil.*; import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; import static org.asynchttpclient.util.MiscUtil.isNonEmpty; import io.netty.buffer.ByteBuf; @@ -32,7 +45,9 @@ import org.asynchttpclient.ntlm.NTLMEngine; import org.asynchttpclient.ntlm.NTLMEngineException; import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieEncoder; -import org.asynchttpclient.providers.netty4.spnego.SpnegoEngine; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProvider; +import org.asynchttpclient.providers.netty.ws.WebSocketUtil; +import org.asynchttpclient.spnego.SpnegoEngine; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.asynchttpclient.util.AuthenticatorUtils; import org.asynchttpclient.util.UTF8UrlEncoder; @@ -145,9 +160,7 @@ else if (uri.getRawQuery() != null) String msg = NTLMEngine.INSTANCE.generateType1Msg("NTLM " + domain, authHost); headers.put(HttpHeaders.Names.AUTHORIZATION, "NTLM " + msg); } catch (NTLMEngineException e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; + throw new IOException(e); } break; case KERBEROS: @@ -157,9 +170,7 @@ else if (uri.getRawQuery() != null) try { challengeHeader = SpnegoEngine.instance().generateToken(server); } catch (Throwable e) { - IOException ie = new IOException(); - ie.initCause(e); - throw ie; + throw new IOException(e); } headers.put(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); break; @@ -257,11 +268,11 @@ else if (uri.getRawQuery() != null) } } else if (request.getParts() != null) { + // FIXME use Netty multipart MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); headers.put(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); headers.put(HttpHeaders.Names.CONTENT_LENGTH, mre.getContentLength()); - hasDeferredContent = true; } else if (request.getFile() != null) { diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/ProgressListener.java similarity index 70% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/ProgressListener.java index 10739dac52..823bbc3a29 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ProgressListener.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/ProgressListener.java @@ -1,4 +1,19 @@ -package org.asynchttpclient.providers.netty4; +/* + * Copyright 2010-2013 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.request; import io.netty.channel.ChannelProgressiveFuture; import io.netty.channel.ChannelProgressiveFutureListener; @@ -10,8 +25,14 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ProgressAsyncHandler; import org.asynchttpclient.Realm; +import org.asynchttpclient.providers.netty.future.NettyResponseFuture; +import org.asynchttpclient.providers.netty.future.NettyResponseFutures; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ProgressListener implements ChannelProgressiveFutureListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProgressListener.class); private final AsyncHttpClientConfig config; private final boolean notifyHeaders; @@ -28,32 +49,31 @@ public ProgressListener(AsyncHttpClientConfig config, boolean notifyHeaders, Asy @Override public void operationComplete(ChannelProgressiveFuture cf) { - // FIXME remove this with next 4.0.9: https://github.com/netty/netty/issues/1809 // The write operation failed. If the channel was cached, it means it got asynchronously closed. // Let's retry a second time. Throwable cause = cf.cause(); if (cause != null && future.getState() != NettyResponseFuture.STATE.NEW) { if (cause instanceof IllegalStateException) { - NettyAsyncHttpProvider.LOGGER.debug(cause.getMessage(), cause); + LOGGER.debug(cause.getMessage(), cause); try { cf.channel().close(); } catch (RuntimeException ex) { - NettyAsyncHttpProvider.LOGGER.debug(ex.getMessage(), ex); + LOGGER.debug(ex.getMessage(), ex); } return; } if (cause instanceof ClosedChannelException || NettyResponseFutures.abortOnReadCloseException(cause) || NettyResponseFutures.abortOnWriteCloseException(cause)) { - if (NettyAsyncHttpProvider.LOGGER.isDebugEnabled()) { - NettyAsyncHttpProvider.LOGGER.debug(cf.cause() == null ? "" : cf.cause().getMessage(), cf.cause()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(cf.cause() == null ? "" : cf.cause().getMessage(), cf.cause()); } try { cf.channel().close(); } catch (RuntimeException ex) { - NettyAsyncHttpProvider.LOGGER.debug(ex.getMessage(), ex); + LOGGER.debug(ex.getMessage(), ex); } return; } else { @@ -82,7 +102,7 @@ public void operationComplete(ChannelProgressiveFuture cf) { @Override public void operationProgressed(ChannelProgressiveFuture f, long progress, long total) { future.touch(); - if (asyncHandler instanceof ProgressAsyncHandler) { + if (!notifyHeaders && asyncHandler instanceof ProgressAsyncHandler) { long lastProgressValue = lastProgress.getAndSet(progress); ProgressAsyncHandler.class.cast(asyncHandler).onContentWriteProgress(progress - lastProgressValue, progress, total); } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java index acf9a994c8..61b5f13671 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyResponse.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.response; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java similarity index 95% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java index 2206317f25..86289d146d 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseBodyPart.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.response; import io.netty.buffer.ByteBuf; @@ -25,7 +25,7 @@ import java.nio.ByteBuffer; import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.providers.netty4.util.ByteBufUtil; +import org.asynchttpclient.providers.netty.util.ByteBufUtil; /** * A callback class used when an HTTP response body is received. diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java similarity index 97% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java index f3c02e262d..a024e8a624 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseHeaders.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.response; import io.netty.handler.codec.http.HttpHeaders; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java index ff8f3cd77e..45c7274245 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ResponseStatus.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java @@ -14,7 +14,7 @@ * under the License. * */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.response; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpProvider; diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoEngine.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoEngine.java deleted file mode 100644 index b0d653391c..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/spnego/SpnegoEngine.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -/* - * ==================================================================== - * - * 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 - * . - */ - -package org.asynchttpclient.providers.netty.spnego; - -import org.asynchttpclient.util.Base64; -import org.ietf.jgss.GSSContext; -import org.ietf.jgss.GSSException; -import org.ietf.jgss.GSSManager; -import org.ietf.jgss.GSSName; -import org.ietf.jgss.Oid; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; - -/** - * SPNEGO (Simple and Protected GSSAPI Negotiation Mechanism) authentication - * scheme. - * - * @since 4.1 - */ -public class SpnegoEngine { - private static final String SPNEGO_OID = "1.3.6.1.5.5.2"; - private static final String KERBEROS_OID = "1.2.840.113554.1.2.2"; - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private final SpnegoTokenGenerator spnegoGenerator; - - public SpnegoEngine(final SpnegoTokenGenerator spnegoGenerator) { - this.spnegoGenerator = spnegoGenerator; - } - - public SpnegoEngine() { - this(null); - } - - public String generateToken(String server) throws Throwable { - GSSContext gssContext = null; - byte[] token = null; // base64 decoded challenge - Oid negotiationOid = null; - - try { - log.debug("init {}", server); - /* Using the SPNEGO OID is the correct method. - * Kerberos v5 works for IIS but not JBoss. Unwrapping - * the initial token when using SPNEGO OID looks like what is - * described here... - * - * http://msdn.microsoft.com/en-us/library/ms995330.aspx - * - * Another helpful URL... - * - * http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/tsec_SPNEGO_token.html - * - * Unfortunately SPNEGO is JRE >=1.6. - */ - - /** Try SPNEGO by default, fall back to Kerberos later if error */ - negotiationOid = new Oid(SPNEGO_OID); - - boolean tryKerberos = false; - try { - GSSManager manager = GSSManager.getInstance(); - GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE); - gssContext = manager.createContext( - serverName.canonicalize(negotiationOid), negotiationOid, null, - GSSContext.DEFAULT_LIFETIME); - gssContext.requestMutualAuth(true); - gssContext.requestCredDeleg(true); - } catch (GSSException ex) { - log.error("generateToken", ex); - // BAD MECH means we are likely to be using 1.5, fall back to Kerberos MECH. - // Rethrow any other exception. - if (ex.getMajor() == GSSException.BAD_MECH) { - log.debug("GSSException BAD_MECH, retry with Kerberos MECH"); - tryKerberos = true; - } else { - throw ex; - } - - } - if (tryKerberos) { - /* Kerberos v5 GSS-API mechanism defined in RFC 1964.*/ - log.debug("Using Kerberos MECH {}", KERBEROS_OID); - negotiationOid = new Oid(KERBEROS_OID); - GSSManager manager = GSSManager.getInstance(); - GSSName serverName = manager.createName("HTTP@" + server, GSSName.NT_HOSTBASED_SERVICE); - gssContext = manager.createContext( - serverName.canonicalize(negotiationOid), negotiationOid, null, - GSSContext.DEFAULT_LIFETIME); - gssContext.requestMutualAuth(true); - gssContext.requestCredDeleg(true); - } - - // TODO suspicious: this will always be null because no value has been assigned before. Assign directly? - if (token == null) { - token = new byte[0]; - } - - token = gssContext.initSecContext(token, 0, token.length); - if (token == null) { - throw new Exception("GSS security context initialization failed"); - } - - /* - * IIS accepts Kerberos and SPNEGO tokens. Some other servers Jboss, Glassfish? - * seem to only accept SPNEGO. Below wraps Kerberos into SPNEGO token. - */ - if (spnegoGenerator != null && negotiationOid.toString().equals(KERBEROS_OID)) { - token = spnegoGenerator.generateSpnegoDERObject(token); - } - - gssContext.dispose(); - - String tokenstr = new String(Base64.encode(token)); - log.debug("Sending response '{}' back to the server", tokenstr); - - return tokenstr; - } catch (GSSException gsse) { - log.error("generateToken", gsse); - if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL - || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED) - throw new Exception(gsse.getMessage(), gsse); - if (gsse.getMajor() == GSSException.NO_CRED) - throw new Exception(gsse.getMessage(), gsse); - if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN - || gsse.getMajor() == GSSException.DUPLICATE_TOKEN - || gsse.getMajor() == GSSException.OLD_TOKEN) - throw new Exception(gsse.getMessage(), gsse); - // other error - throw new Exception(gsse.getMessage()); - } catch (IOException ex) { - throw new Exception(ex.getMessage()); - } - } -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java similarity index 95% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java index 952d787828..fa64563e70 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/ByteBufUtil.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java @@ -13,7 +13,7 @@ * License for the specific language governing permissions and limitations * under the License. */ -package org.asynchttpclient.providers.netty4.util; +package org.asynchttpclient.providers.netty.util; import io.netty.buffer.ByteBuf; diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ChannelBufferUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ChannelBufferUtil.java deleted file mode 100644 index e577d54735..0000000000 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ChannelBufferUtil.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty.util; - -import org.jboss.netty.buffer.ChannelBuffer; - -public class ChannelBufferUtil { - - public static byte[] channelBuffer2bytes(ChannelBuffer b) { - int readable = b.readableBytes(); - int readerIndex = b.readerIndex(); - if (b.hasArray()) { - byte[] array = b.array(); - if (b.arrayOffset() == 0 && readerIndex == 0 && array.length == readable) { - return array; - } - } - byte[] array = new byte[readable]; - b.getBytes(readerIndex, array); - return array; - } -} \ No newline at end of file diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/CleanupChannelGroup.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/CleanupChannelGroup.java index 486c61ef32..671da09988 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/CleanupChannelGroup.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/CleanupChannelGroup.java @@ -28,17 +28,11 @@ package org.asynchttpclient.providers.netty.util; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.group.ChannelGroupFuture; -import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.group.DefaultChannelGroupFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.netty.channel.Channel; +import io.netty.channel.group.ChannelGroupFuture; +import io.netty.channel.group.DefaultChannelGroup; +import io.netty.util.concurrent.GlobalEventExecutor; -import java.util.ArrayList; -import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -50,24 +44,20 @@ */ public class CleanupChannelGroup extends DefaultChannelGroup { - private final static Logger logger = LoggerFactory.getLogger(CleanupChannelGroup.class); // internal vars -------------------------------------------------------------------------------------------------- - private final AtomicBoolean closed; - private final ReentrantReadWriteLock lock; + private final AtomicBoolean closed = new AtomicBoolean(false); + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); // constructors --------------------------------------------------------------------------------------------------- public CleanupChannelGroup() { - this.closed = new AtomicBoolean(false); - this.lock = new ReentrantReadWriteLock(); + super(GlobalEventExecutor.INSTANCE); } public CleanupChannelGroup(String name) { - super(name); - this.closed = new AtomicBoolean(false); - this.lock = new ReentrantReadWriteLock(); + super(name, GlobalEventExecutor.INSTANCE); } // DefaultChannelGroup -------------------------------------------------------------------------------------------- @@ -80,9 +70,11 @@ public ChannelGroupFuture close() { // First time close() is called. return super.close(); } else { - Collection futures = new ArrayList(); - logger.debug("CleanupChannelGroup Already closed"); - return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures); + // FIXME DefaultChannelGroupFuture is package protected +// Collection futures = new ArrayList(); +// logger.debug("CleanupChannelGroup already closed"); +// return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures, GlobalEventExecutor.INSTANCE); + throw new UnsupportedOperationException("CleanupChannelGroup already closed"); } } finally { this.lock.writeLock().unlock(); diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/HttpUtil.java similarity index 94% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/HttpUtil.java index cf6b49a3a6..5889de9ea5 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/HttpUtil.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/HttpUtil.java @@ -1,4 +1,4 @@ -package org.asynchttpclient.providers.netty4.util; +package org.asynchttpclient.providers.netty.util; import static org.asynchttpclient.util.MiscUtil.isNonEmpty; diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/NettyWebSocket.java similarity index 71% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/NettyWebSocket.java index f4a4a8dd76..77e32b998f 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyWebSocket.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/NettyWebSocket.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.ws; import org.asynchttpclient.websocket.WebSocket; import org.asynchttpclient.websocket.WebSocketByteListener; @@ -45,74 +45,74 @@ public NettyWebSocket(Channel channel) { this.channel = channel; } - // @Override + @Override public WebSocket sendMessage(byte[] message) { channel.writeAndFlush(new BinaryWebSocketFrame(wrappedBuffer(message))); return this; } - // @Override + @Override public WebSocket stream(byte[] fragment, boolean last) { throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); } - // @Override + @Override public WebSocket stream(byte[] fragment, int offset, int len, boolean last) { throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); } - // @Override + @Override public WebSocket sendTextMessage(String message) { channel.writeAndFlush(new TextWebSocketFrame(message)); return this; } - // @Override + @Override public WebSocket streamText(String fragment, boolean last) { throw new UnsupportedOperationException("Streaming currently only supported by the Grizzly provider."); } - // @Override + @Override public WebSocket sendPing(byte[] payload) { channel.writeAndFlush(new PingWebSocketFrame(wrappedBuffer(payload))); return this; } - // @Override + @Override public WebSocket sendPong(byte[] payload) { channel.writeAndFlush(new PongWebSocketFrame(wrappedBuffer(payload))); return this; } - // @Override + @Override public WebSocket addWebSocketListener(WebSocketListener l) { listeners.add(l); return this; } - // @Override + @Override public WebSocket removeWebSocketListener(WebSocketListener l) { listeners.remove(l); return this; } public int getMaxBufferSize() { - return maxBufferSize; + return maxBufferSize; } - + public void setMaxBufferSize(int bufferSize) { - maxBufferSize = bufferSize; - - if(maxBufferSize < 8192) - maxBufferSize = 8192; + maxBufferSize = bufferSize; + + if (maxBufferSize < 8192) + maxBufferSize = 8192; } - - // @Override + + @Override public boolean isOpen() { return channel.isOpen(); } - // @Override + @Override public void close() { onClose(); listeners.clear(); @@ -124,7 +124,6 @@ public void close() { } } - // @Override public void close(int statusCode, String reason) { onClose(statusCode, reason); listeners.clear(); @@ -136,31 +135,30 @@ public void close(int statusCode, String reason) { } } - protected void onBinaryFragment(byte[] message, boolean last) { + public void onBinaryFragment(byte[] message, boolean last) { for (WebSocketListener l : listeners) { if (l instanceof WebSocketByteListener) { try { - WebSocketByteListener.class.cast(l).onFragment(message,last); - - if(byteBuffer == null) { - byteBuffer = new ByteArrayOutputStream(); - } - - byteBuffer.write(message); - - if(byteBuffer.size() > maxBufferSize) { - Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); + WebSocketByteListener.class.cast(l).onFragment(message, last); + + if (byteBuffer == null) { + byteBuffer = new ByteArrayOutputStream(); + } + + byteBuffer.write(message); + + if (byteBuffer.size() > maxBufferSize) { + Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); l.onError(e); - this.close(); - return; - } - - - if(last) { - WebSocketByteListener.class.cast(l).onMessage(byteBuffer.toByteArray()); - byteBuffer = null; - textBuffer = null; - } + this.close(); + return; + } + + if (last) { + WebSocketByteListener.class.cast(l).onMessage(byteBuffer.toByteArray()); + byteBuffer = null; + textBuffer = null; + } } catch (Exception ex) { l.onError(ex); } @@ -168,30 +166,30 @@ protected void onBinaryFragment(byte[] message, boolean last) { } } - protected void onTextFragment(String message, boolean last) { + public void onTextFragment(String message, boolean last) { for (WebSocketListener l : listeners) { if (l instanceof WebSocketTextListener) { try { - WebSocketTextListener.class.cast(l).onFragment(message,last); - - if(textBuffer == null) { - textBuffer = new StringBuilder(); - } - - textBuffer.append(message); - - if(textBuffer.length() > maxBufferSize) { - Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); + WebSocketTextListener.class.cast(l).onFragment(message, last); + + if (textBuffer == null) { + textBuffer = new StringBuilder(); + } + + textBuffer.append(message); + + if (textBuffer.length() > maxBufferSize) { + Exception e = new Exception("Exceeded Netty Web Socket maximum buffer size of " + getMaxBufferSize()); l.onError(e); - this.close(); - return; - } - - if(last) { - WebSocketTextListener.class.cast(l).onMessage(textBuffer.toString()); - byteBuffer = null; - textBuffer = null; - } + this.close(); + return; + } + + if (last) { + WebSocketTextListener.class.cast(l).onMessage(textBuffer.toString()); + byteBuffer = null; + textBuffer = null; + } } catch (Exception ex) { l.onError(ex); } @@ -199,7 +197,7 @@ protected void onTextFragment(String message, boolean last) { } } - protected void onError(Throwable t) { + public void onError(Throwable t) { for (WebSocketListener l : listeners) { try { l.onError(t); @@ -210,11 +208,11 @@ protected void onError(Throwable t) { } } - protected void onClose() { + public void onClose() { onClose(1000, "Normal closure; the connection successfully completed whatever purpose for which it was created."); } - protected void onClose(int code, String reason) { + public void onClose(int code, String reason) { for (WebSocketListener l : listeners) { try { if (l instanceof WebSocketCloseCodeReasonListener) { @@ -229,8 +227,6 @@ protected void onClose(int code, String reason) { @Override public String toString() { - return "NettyWebSocket{" + - "channel=" + channel + - '}'; + return "NettyWebSocket{" + "channel=" + channel + '}'; } } diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/WebSocketUtil.java similarity index 98% rename from providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java rename to providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/WebSocketUtil.java index 5c92684365..3321677f48 100644 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/WebSocketUtil.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/ws/WebSocketUtil.java @@ -10,7 +10,7 @@ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ -package org.asynchttpclient.providers.netty4; +package org.asynchttpclient.providers.netty.ws; import org.asynchttpclient.util.Base64; diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java index c55b13996c..4ceea15708 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderTest.java @@ -12,16 +12,8 @@ */ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertEquals; - -import java.util.concurrent.Executors; - -import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; public class NettyAsyncHttpProviderTest extends AbstractBasicTest { @@ -30,19 +22,4 @@ public class NettyAsyncHttpProviderTest extends AbstractBasicTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - - @Test - public void bossThreadPoolExecutor() throws Exception { - NettyAsyncHttpProviderConfig conf = new NettyAsyncHttpProviderConfig(); - conf.setBossExecutorService(Executors.newSingleThreadExecutor()); - - AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setAsyncHttpClientProviderConfig(conf).build(); - AsyncHttpClient c = getAsyncHttpClient(cf); - try { - Response r = c.prepareGet(getTargetUrl()).execute().get(); - assertEquals(r.getStatusCode(), 200); - } finally { - c.close(); - } - } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java index d422b202ac..3ef9a5b966 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderBasicTest.java @@ -12,15 +12,11 @@ */ package org.asynchttpclient.providers.netty; -import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.async.AsyncProvidersBasicTest; -@Test public class NettyAsyncProviderBasicTest extends AsyncProvidersBasicTest { @Override @@ -29,9 +25,9 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } @Override - protected AsyncHttpProviderConfig getProviderConfig() { + protected AsyncHttpProviderConfig getProviderConfig() { final NettyAsyncHttpProviderConfig config = new NettyAsyncHttpProviderConfig(); - config.addProperty("tcpNoDelay", true); + config.addProperty("TCP_NODELAY", true); return config; } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java index 87c313345d..ab0a698ad6 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncProviderPipelineTest.java @@ -14,6 +14,10 @@ package org.asynchttpclient.providers.netty; import static org.testng.Assert.*; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; +import io.netty.handler.codec.http.HttpMessage; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -24,24 +28,28 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.channel.SimpleChannelHandler; -import org.jboss.netty.handler.codec.http.HttpMessage; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig.AdditionalChannelInitializer; import org.testng.annotations.Test; public class NettyAsyncProviderPipelineTest extends AbstractBasicTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return new AsyncHttpClient(new CopyEncodingNettyAsyncHttpProvider(config), config); + return NettyProviderUtil.nettyProvider(config); } @Test(groups = { "standalone", "netty_provider" }) public void asyncPipelineTest() throws Exception { - AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).build()); + + NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); + nettyConfig.setHttpAdditionalChannelInitializer(new AdditionalChannelInitializer() { + public void initChannel(Channel ch) throws Exception { + // super.initPlainChannel(ch); + ch.pipeline().addBefore("inflater", "copyEncodingHeader", new CopyEncodingHandler()); + } + }); + AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAsyncHttpClientProviderConfig(nettyConfig).build()); + try { final CountDownLatch l = new CountDownLatch(1); Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); @@ -65,35 +73,17 @@ public Response onCompleted(Response response) throws Exception { } } - private static class CopyEncodingNettyAsyncHttpProvider extends - NettyAsyncHttpProvider { - public CopyEncodingNettyAsyncHttpProvider(AsyncHttpClientConfig config) { - super(config); - } - - protected ChannelPipelineFactory createPlainPipelineFactory() { - final ChannelPipelineFactory pipelineFactory = super.createPlainPipelineFactory(); - return new ChannelPipelineFactory() { - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = pipelineFactory.getPipeline(); - pipeline.addBefore("inflater", "copyEncodingHeader", new CopyEncodingHandler()); - return pipeline; - } - }; - } - } - - private static class CopyEncodingHandler extends SimpleChannelHandler { + private static class CopyEncodingHandler extends ChannelInboundHandlerAdapter { @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { - Object msg = e.getMessage(); - if (msg instanceof HttpMessage) { - HttpMessage m = (HttpMessage) msg; - // for test there is no Content-Encoding header so just hard coding value + public void channelRead(ChannelHandlerContext ctx, Object e) { + if (e instanceof HttpMessage) { + HttpMessage m = (HttpMessage) e; + // for test there is no Content-Encoding header so just hard + // coding value // for verification - m.setHeader("X-Original-Content-Encoding", ""); + m.headers().set("X-Original-Content-Encoding", ""); } - ctx.sendUpstream(e); + ctx.fireChannelRead(e); } } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java index 812a04e0fe..e679303540 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java @@ -13,12 +13,7 @@ package org.asynchttpclient.providers.netty; -import org.asynchttpclient.Cookie; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.providers.netty.NettyResponse; -import org.asynchttpclient.providers.netty.ResponseStatus; -import org.testng.annotations.Test; +import static org.testng.Assert.*; import java.text.SimpleDateFormat; import java.util.Date; @@ -26,8 +21,12 @@ import java.util.Locale; import java.util.TimeZone; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import org.asynchttpclient.Cookie; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.providers.netty.response.NettyResponse; +import org.asynchttpclient.providers.netty.response.ResponseStatus; +import org.testng.annotations.Test; /** * @author Benjamin Hanzelmann @@ -44,7 +43,7 @@ public void testCookieParseExpires() { final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date)); NettyResponse - response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -61,7 +60,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseMaxAge() { final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -77,7 +76,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseWeirdExpiresValue() { final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java index 61a633e002..1056d502fa 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAuthTimeoutTest.java @@ -22,5 +22,4 @@ public class NettyAuthTimeoutTest extends AuthTimeoutTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java index 2e0a4091fc..69dfb34b78 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java @@ -15,9 +15,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.BasicAuthTest; -import org.testng.annotations.Test; -@Test public class NettyBasicAuthTest extends BasicAuthTest { @Override @@ -29,9 +27,4 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return NettyAsyncHttpProvider.class.getName(); } - - @Test(enabled = false) - public void stringBuilderBodyConsumerTest() throws Exception { - // FIXME - } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java index 945761d5e1..11e6d709b6 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyConnectionPoolTest.java @@ -12,14 +12,11 @@ */ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; +import static org.testng.Assert.*; +import io.netty.channel.Channel; import java.util.concurrent.TimeUnit; -import org.jboss.netty.channel.Channel; - import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.ConnectionsPool; diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java index 4989481508..fdbfb52d13 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyMultipartUploadTest.java @@ -15,12 +15,10 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.async.MultipartUploadTest; -import org.testng.annotations.Test; /** * @author dominict */ -@Test public class NettyMultipartUploadTest extends MultipartUploadTest { @Override diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java index c4692cb476..ff4eef3f1c 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyPerRequestTimeoutTest.java @@ -12,7 +12,7 @@ */ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertTrue; +import static org.testng.Assert.*; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java index 499e0025c4..983076d728 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyProviderUtil.java @@ -21,16 +21,9 @@ public class NettyProviderUtil { public static AsyncHttpClient nettyProvider(AsyncHttpClientConfig config) { - // FIXME why do tests fail with this set up? Seems like we have a race condition - // if (config == null) { - // config = new AsyncHttpClientConfig.Builder().build(); - // } - // return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config); - if (config == null) { - return new AsyncHttpClient(); - } else { - return new AsyncHttpClient(config); + config = new AsyncHttpClientConfig.Builder().build(); } + return new AsyncHttpClient(new NettyAsyncHttpProvider(config), config); } } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java index 6ca05960ab..01f53bffa9 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyRequestThrottleTimeoutTest.java @@ -12,11 +12,11 @@ */ package org.asynchttpclient.providers.netty; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.testng.Assert.*; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Future; @@ -27,17 +27,16 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; - import org.asynchttpclient.AsyncCompletionHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; import org.asynchttpclient.async.AbstractBasicTest; +import org.eclipse.jetty.continuation.Continuation; +import org.eclipse.jetty.continuation.ContinuationSupport; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; public class NettyRequestThrottleTimeoutTest extends AbstractBasicTest { private static final String MSG = "Enough is enough."; @@ -80,11 +79,12 @@ public void run() { public void testRequestTimeout() throws IOException { final Semaphore requestThrottle = new Semaphore(1); - final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAllowPoolingConnection(true).setMaximumConnectionsTotal(1).build()); + final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAllowPoolingConnection(true) + .setMaximumConnectionsTotal(1).build()); try { final CountDownLatch latch = new CountDownLatch(2); + final List tooManyConnections = Collections.synchronizedList(new ArrayList(2)); - final List tooManyConnections = new ArrayList(2); for (int i = 0; i < 2; i++) { new Thread(new Runnable() { @@ -119,7 +119,6 @@ public void onThrowable(Throwable t) { } }).start(); - } try { @@ -128,7 +127,7 @@ public void onThrowable(Throwable t) { fail("failed to wait for requests to complete"); } - assertTrue(tooManyConnections.size() == 0, "Should not have any connection errors where too many connections have been attempted"); + assertTrue(tooManyConnections.isEmpty(), "Should not have any connection errors where too many connections have been attempted"); } finally { client.close(); } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java index 6169dc0fe3..09f89010cd 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java @@ -40,7 +40,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -// FIXME there's no retry actually +//FIXME there's no retry actually public class RetryNonBlockingIssue extends AbstractBasicTest { @Override @@ -52,9 +52,11 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public void setUpGlobal() throws Exception { port1 = findFreePort(); server = newJettyHttpServer(port1); + ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*"); + server.setHandler(context); server.start(); } @@ -138,7 +140,7 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - assertEquals(200, theres.getStatusCode()); + assertEquals(theres.getStatusCode(), 200); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -179,7 +181,7 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut StringBuilder b = new StringBuilder(); for (ListenableFuture r : res) { Response theres = r.get(); - assertEquals(200, theres.getStatusCode()); + assertEquals(theres.getStatusCode(), 200); b.append("==============\r\n"); b.append("Response Headers\r\n"); Map> heads = theres.getHeaders(); @@ -188,7 +190,8 @@ public void testRetryBlocking() throws IOException, InterruptedException, Execut assertTrue(heads.size() > 0); } - logger.debug(b.toString()); + System.out.println(b.toString()); + System.out.flush(); } finally { client.close(); diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java index 63b875480c..185ffb1806 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyRedirectTest.java @@ -15,7 +15,6 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.netty.NettyProviderUtil; -import org.asynchttpclient.providers.netty.NettyProviderUtil; import org.asynchttpclient.websocket.RedirectTest; public class NettyRedirectTest extends RedirectTest { @@ -24,5 +23,4 @@ public class NettyRedirectTest extends RedirectTest { public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { return NettyProviderUtil.nettyProvider(config); } - } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java index cb35f53be2..c1286255ad 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/websocket/NettyTextMessageTest.java @@ -16,9 +16,7 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.netty.NettyProviderUtil; import org.asynchttpclient.websocket.TextMessageTest; -import org.testng.annotations.Test; -@Test public class NettyTextMessageTest extends TextMessageTest { @Override public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { diff --git a/providers/netty4/pom.xml b/providers/netty4/pom.xml deleted file mode 100644 index 90a29ea432..0000000000 --- a/providers/netty4/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - org.asynchttpclient - async-http-client-providers-parent - 2.0.0-SNAPSHOT - - 4.0.0 - async-http-client-netty4-provider - Asynchronous Http Client Netty 4 Provider - - The Async Http Client Netty 4 Provider. - - - - - sonatype-releases - https://oss.sonatype.org/content/repositories/releases - - true - - - false - - - - sonatype-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - - - - io.netty - netty-all - 4.0.9.Final - - - org.javassist - javassist - 3.18.0-GA - - - - \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java deleted file mode 100644 index a17fc9e1e5..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProvider.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2010-2013 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty4; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.Request; -import org.asynchttpclient.Response; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class NettyAsyncHttpProvider implements AsyncHttpProvider { - - static final Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); - - private final AsyncHttpClientConfig config; - private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; - private final AtomicBoolean closed = new AtomicBoolean(false); - private final Channels channels; - private final NettyRequestSender requestSender; - private final NettyChannelHandler channelHandler; - private final boolean executeConnectAsync; - - public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { - - this.config = config; - if (config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig) { - asyncHttpProviderConfig = NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()); - } else { - asyncHttpProviderConfig = new NettyAsyncHttpProviderConfig(); - } - - channels = new Channels(config, asyncHttpProviderConfig); - requestSender = new NettyRequestSender(closed, config, channels); - channelHandler = new NettyChannelHandler(config, requestSender, channels, closed); - channels.configure(channelHandler); - - executeConnectAsync = asyncHttpProviderConfig.isAsyncConnect(); - // FIXME - // if (!executeConnectAsync) { - // DefaultChannelFuture.setUseDeadLockChecker(true); - // } - } - - @Override - public String toString() { - return String.format("NettyAsyncHttpProvider4:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections() - - channels.freeConnections.availablePermits(), channels.openChannels.toString(), channels.connectionsPool.toString()); - } - - @Override - public void close() { - closed.set(true); - try { - channels.close(); -// config.executorService().shutdown(); - config.reaper().shutdown(); - } catch (Throwable t) { - LOGGER.warn("Unexpected error on close", t); - } - } - - @Override - public Response prepareResponse(final HttpResponseStatus status, final HttpResponseHeaders headers, final List bodyParts) { - throw new UnsupportedOperationException("Mocked, should be refactored"); - } - - @Override - public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { - return requestSender.doConnect(request, asyncHandler, null, true, executeConnectAsync, false); - } -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java deleted file mode 100644 index be8aa75d44..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderConfig.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - * - */ -package org.asynchttpclient.providers.netty4; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelOption; -import io.netty.channel.EventLoopGroup; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.asynchttpclient.AsyncHttpProviderConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class can be used to pass Netty's internal configuration options. See Netty documentation for more information. - */ -public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig { - - private final static Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProviderConfig.class); - - /** - * Use Netty's blocking IO stategy. - */ - private boolean useBlockingIO; - - /** - * Allow configuring the Netty's event loop. - */ - private EventLoopGroup eventLoopGroup; - - private AdditionalChannelInitializer httpAdditionalChannelInitializer; - private AdditionalChannelInitializer wsAdditionalChannelInitializer; - private AdditionalChannelInitializer httpsAdditionalChannelInitializer; - private AdditionalChannelInitializer wssAdditionalChannelInitializer; - - /** - * Execute the connect operation asynchronously. - */ - private boolean asyncConnect; - - /** - * HttpClientCodec's maxInitialLineLength - */ - private int maxInitialLineLength = 4096; - - /** - * HttpClientCodec's maxHeaderSize - */ - private int maxHeaderSize = 8192; - - /** - * HttpClientCodec's maxChunkSize - */ - private int maxChunkSize = 8192; - - /** - * Use direct {@link java.nio.ByteBuffer} - */ - public final static String USE_DIRECT_BYTEBUFFER = "bufferFactory"; - - /** - * Allow nested request from any {@link org.asynchttpclient.AsyncHandler} - */ - public final static String DISABLE_NESTED_REQUEST = "disableNestedRequest"; - - /** - * See {@link java.net.Socket#setReuseAddress(boolean)} - */ - public final static String REUSE_ADDRESS = ChannelOption.SO_REUSEADDR.name(); - - private final Map properties = new HashMap(); - - public NettyAsyncHttpProviderConfig() { - properties.put(REUSE_ADDRESS, Boolean.FALSE); - } - - /** - * Add a property that will be used when the AsyncHttpClient initialize its {@link org.asynchttpclient.AsyncHttpProvider} - * - * @param name - * the name of the property - * @param value - * the value of the property - * @return this instance of AsyncHttpProviderConfig - */ - public NettyAsyncHttpProviderConfig addProperty(String name, Object value) { - - if (name.equals(REUSE_ADDRESS) && value == Boolean.TRUE && System.getProperty("os.name").toLowerCase().contains("win")) { - LOGGER.warn("Can't enable {} on Windows", REUSE_ADDRESS); - } else { - properties.put(name, value); - } - - return this; - } - - /** - * Return the value associated with the property's name - * - * @param name - * @return this instance of AsyncHttpProviderConfig - */ - public Object getProperty(String name) { - return properties.get(name); - } - - /** - * Remove the value associated with the property's name - * - * @param name - * @return true if removed - */ - public Object removeProperty(String name) { - return properties.remove(name); - } - - /** - * Return the curent entry set. - * - * @return a the curent entry set. - */ - public Set> propertiesSet() { - return properties.entrySet(); - } - - public boolean isUseBlockingIO() { - return useBlockingIO; - } - - public void setUseBlockingIO(boolean useBlockingIO) { - this.useBlockingIO = useBlockingIO; - } - - public EventLoopGroup getEventLoopGroup() { - return eventLoopGroup; - } - - public void setEventLoopGroup(EventLoopGroup eventLoopGroup) { - this.eventLoopGroup = eventLoopGroup; - } - - public boolean isAsyncConnect() { - return asyncConnect; - } - - public void setAsyncConnect(boolean asyncConnect) { - this.asyncConnect = asyncConnect; - } - - public int getMaxInitialLineLength() { - return maxInitialLineLength; - } - - public void setMaxInitialLineLength(int maxInitialLineLength) { - this.maxInitialLineLength = maxInitialLineLength; - } - - public int getMaxHeaderSize() { - return maxHeaderSize; - } - - public void setMaxHeaderSize(int maxHeaderSize) { - this.maxHeaderSize = maxHeaderSize; - } - - public int getMaxChunkSize() { - return maxChunkSize; - } - - public void setMaxChunkSize(int maxChunkSize) { - this.maxChunkSize = maxChunkSize; - } - - public AdditionalChannelInitializer getHttpAdditionalChannelInitializer() { - return httpAdditionalChannelInitializer; - } - - public void setHttpAdditionalChannelInitializer(AdditionalChannelInitializer httpAdditionalChannelInitializer) { - this.httpAdditionalChannelInitializer = httpAdditionalChannelInitializer; - } - - public AdditionalChannelInitializer getWsAdditionalChannelInitializer() { - return wsAdditionalChannelInitializer; - } - - public void setWsAdditionalChannelInitializer(AdditionalChannelInitializer wsAdditionalChannelInitializer) { - this.wsAdditionalChannelInitializer = wsAdditionalChannelInitializer; - } - - public AdditionalChannelInitializer getHttpsAdditionalChannelInitializer() { - return httpsAdditionalChannelInitializer; - } - - public void setHttpsAdditionalChannelInitializer(AdditionalChannelInitializer httpsAdditionalChannelInitializer) { - this.httpsAdditionalChannelInitializer = httpsAdditionalChannelInitializer; - } - - public AdditionalChannelInitializer getWssAdditionalChannelInitializer() { - return wssAdditionalChannelInitializer; - } - - public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssAdditionalChannelInitializer) { - this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer; - } - - public static interface AdditionalChannelInitializer { - - void initChannel(Channel ch) throws Exception; - } -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java deleted file mode 100644 index 484a8b694b..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java +++ /dev/null @@ -1,873 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -import static io.netty.handler.codec.http.HttpResponseStatus.*; -import static org.asynchttpclient.providers.netty4.util.HttpUtil.*; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandler.Sharable; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.PrematureChannelClosureException; -import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.HttpHeaders; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpRequest; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; -import java.nio.channels.ClosedChannelException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHandler.STATE; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Cookie; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.MaxRedirectException; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Realm; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.ResponseFilter; -import org.asynchttpclient.ntlm.NTLMEngine; -import org.asynchttpclient.ntlm.NTLMEngineException; -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; -import org.asynchttpclient.providers.netty4.spnego.SpnegoEngine; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.websocket.WebSocketUpgradeHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Sharable -public class NettyChannelHandler extends ChannelInboundHandlerAdapter { - - private static final Logger LOGGER = LoggerFactory.getLogger(NettyChannelHandler.class); - - private final AsyncHttpClientConfig config; - private final NettyRequestSender requestSender; - private final Channels channels; - private final AtomicBoolean closed; - private final Protocol httpProtocol = new HttpProtocol(); - private final Protocol webSocketProtocol = new WebSocketProtocol(); - - public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requestSender, Channels channels, AtomicBoolean isClose) { - this.config = config; - this.requestSender = requestSender; - this.channels = channels; - this.closed = isClose; - } - - @Override - public void channelRead(final ChannelHandlerContext ctx, Object e) throws Exception { - - Object attribute = Channels.getDefaultAttribute(ctx); - - if (attribute instanceof Callback) { - Callback ac = (Callback) attribute; - if (e instanceof LastHttpContent || !(e instanceof HttpContent)) { - ac.call(); - Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); - } - - } else if (attribute instanceof NettyResponseFuture) { - Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - NettyResponseFuture future = (NettyResponseFuture) attribute; - - p.handle(ctx, future, e); - - } else if (attribute != DiscardEvent.INSTANCE) { - try { - LOGGER.trace("Closing an orphan channel {}", ctx.channel()); - ctx.channel().close(); - } catch (Throwable t) { - } - } - } - - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - - if (closed.get()) { - return; - } - - try { - super.channelInactive(ctx); - } catch (Exception ex) { - LOGGER.trace("super.channelClosed", ex); - } - - channels.removeFromPool(ctx); - Object attachment = Channels.getDefaultAttribute(ctx); - LOGGER.debug("Channel Closed: {} with attachment {}", ctx.channel(), attachment); - - if (attachment instanceof Callback) { - Callback callback = (Callback) attachment; - Channels.setDefaultAttribute(ctx, callback.future()); - callback.call(); - - } else if (attachment instanceof NettyResponseFuture) { - NettyResponseFuture future = NettyResponseFuture.class.cast(attachment); - future.touch(); - - if (!config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { - return; - } - - Protocol p = (ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol); - p.onClose(ctx); - - if (future != null && !future.isDone() && !future.isCancelled()) { - if (!requestSender.retry(ctx.channel(), future)) { - channels.abort(future, new IOException("Remotely Closed")); - } - } else { - channels.closeChannel(ctx); - } - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception { - Channel channel = ctx.channel(); - Throwable cause = e.getCause() != null ? e.getCause() : e; - NettyResponseFuture future = null; - - if (cause instanceof PrematureChannelClosureException) { - return; - } - - LOGGER.debug("Unexpected I/O exception on channel {}", channel, cause); - - try { - if (cause instanceof ClosedChannelException) { - return; - } - - Object attribute = Channels.getDefaultAttribute(ctx); - if (attribute instanceof NettyResponseFuture) { - future = (NettyResponseFuture) attribute; - future.attachChannel(null, false); - future.touch(); - - if (cause instanceof IOException) { - - // FIXME why drop the original exception and create a new - // one? - if (!config.getIOExceptionFilters().isEmpty()) { - if (applyIoExceptionFiltersAndReplayRequest(ctx, future, new IOException("Channel Closed"))) { - return; - } - } else { - // Close the channel so the recovering can occurs. - try { - ctx.channel().close(); - } catch (Throwable t) { - // Swallow. - } - return; - } - } - - if (NettyResponseFutures.abortOnReadCloseException(cause) || NettyResponseFutures.abortOnWriteCloseException(cause)) { - LOGGER.debug("Trying to recover from dead Channel: {}", channel); - return; - } - } else if (attribute instanceof Callback) { - future = Callback.class.cast(attribute).future(); - } - } catch (Throwable t) { - cause = t; - } - - if (future != null) { - try { - LOGGER.debug("Was unable to recover Future: {}", future); - channels.abort(future, cause); - } catch (Throwable t) { - LOGGER.error(t.getMessage(), t); - } - } - - Protocol protocol = ctx.pipeline().get(HttpClientCodec.class) != null ? httpProtocol : webSocketProtocol; - protocol.onError(ctx, e); - - channels.closeChannel(ctx); - // FIXME not really sure - // ctx.fireChannelRead(e); - ctx.close(); - } - - private boolean applyIoExceptionFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, IOException e) throws IOException { - - boolean replayed = false; - - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler()).request(future.getRequest()).ioException(e).build(); - for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - channels.abort(future, efe); - } - } - - if (fc.replayRequest()) { - requestSender.replayRequest(future, fc, ctx); - replayed = true; - } - return replayed; - } - - private boolean redirect(Request request, NettyResponseFuture future, HttpResponse response, final ChannelHandlerContext ctx) throws Exception { - - io.netty.handler.codec.http.HttpResponseStatus status = response.getStatus(); - boolean redirectEnabled = request.isRedirectOverrideSet() ? request.isRedirectEnabled() : config.isRedirectEnabled(); - boolean isRedirectStatus = status.equals(MOVED_PERMANENTLY) || status.equals(FOUND) || status.equals(SEE_OTHER) || status.equals(TEMPORARY_REDIRECT); - if (redirectEnabled && isRedirectStatus) { - - if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) { - // We must allow 401 handling again. - future.getAndSetAuth(false); - - String location = response.headers().get(HttpHeaders.Names.LOCATION); - URI uri = AsyncHttpProviderUtils.getRedirectUri(future.getURI(), location); - - if (!uri.toString().equals(future.getURI().toString())) { - final RequestBuilder nBuilder = new RequestBuilder(future.getRequest()); - if (config.isRemoveQueryParamOnRedirect()) { - nBuilder.setQueryParameters(null); - } - - // FIXME why not do that for 301 and 307 too? - if ((status.equals(FOUND) || status.equals(SEE_OTHER)) && !(status.equals(FOUND) && config.isStrict302Handling())) { - nBuilder.setMethod(HttpMethod.GET.name()); - } - - // in case of a redirect from HTTP to HTTPS, future attributes might change - final boolean initialConnectionKeepAlive = future.isKeepAlive(); - final String initialPoolKey = channels.getPoolKey(future); - - future.setURI(uri); - String newUrl = uri.toString(); - if (request.getUrl().startsWith(WEBSOCKET)) { - newUrl = newUrl.replace(HTTP, WEBSOCKET); - } - LOGGER.debug("Redirecting to {}", newUrl); - - for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE)) { - for (Cookie c : CookieDecoder.decode(cookieStr)) { - nBuilder.addOrReplaceCookie(c); - } - } - - for (String cookieStr : future.getHttpResponse().headers().getAll(HttpHeaders.Names.SET_COOKIE2)) { - for (Cookie c : CookieDecoder.decode(cookieStr)) { - nBuilder.addOrReplaceCookie(c); - } - } - - Callback callback = new Callback(future) { - public void call() throws Exception { - if (!(initialConnectionKeepAlive && ctx.channel().isActive() && channels.offerToPool(initialPoolKey, ctx.channel()))) { - channels.finishChannel(ctx); - } - } - }; - - if (HttpHeaders.isTransferEncodingChunked(response)) { - // We must make sure there is no bytes left before - // executing the next request. - // FIXME investigate this - Channels.setDefaultAttribute(ctx, callback); - } else { - // FIXME don't understand: this offers the connection to the pool, or even closes it, while the request has not been sent, right? - callback.call(); - } - - Request target = nBuilder.setUrl(newUrl).build(); - future.setRequest(target); - requestSender.execute(target, future); - return true; - } - } else { - throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); - } - } - return false; - } - - private final class HttpProtocol implements Protocol { - - private Realm kerberosChallenge(List proxyAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - - URI uri = request.getURI(); - String host = request.getVirtualHost() == null ? AsyncHttpProviderUtils.getHost(uri) : request.getVirtualHost(); - String server = proxyServer == null ? host : proxyServer.getHost(); - try { - String challengeHeader = SpnegoEngine.instance().generateToken(server); - headers.remove(HttpHeaders.Names.AUTHORIZATION); - headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); - - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - return realmBuilder.setUri(uri.getRawPath()).setMethodName(request.getMethod()).setScheme(Realm.AuthScheme.KERBEROS).build(); - } catch (Throwable throwable) { - if (isNTLM(proxyAuth)) { - return ntlmChallenge(proxyAuth, request, proxyServer, headers, realm, future); - } - channels.abort(future, throwable); - return null; - } - } - - private Realm ntlmChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - - boolean useRealm = (proxyServer == null && realm != null); - - String ntlmDomain = useRealm ? realm.getNtlmDomain() : proxyServer.getNtlmDomain(); - String ntlmHost = useRealm ? realm.getNtlmHost() : proxyServer.getHost(); - String principal = useRealm ? realm.getPrincipal() : proxyServer.getPrincipal(); - String password = useRealm ? realm.getPassword() : proxyServer.getPassword(); - - Realm newRealm; - if (realm != null && !realm.isNtlmMessageType2Received()) { - String challengeHeader = NTLMEngine.INSTANCE.generateType1Msg(ntlmDomain, ntlmHost); - - URI uri = request.getURI(); - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(uri.getRawPath()).setMethodName(request.getMethod()) - .setNtlmMessageType2Received(true).build(); - future.getAndSetAuth(false); - } else { - addType3NTLMAuthorizationHeader(wwwAuth, headers, principal, password, ntlmDomain, ntlmHost); - - Realm.RealmBuilder realmBuilder; - Realm.AuthScheme authScheme; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - authScheme = realm.getAuthScheme(); - } else { - realmBuilder = new Realm.RealmBuilder(); - authScheme = Realm.AuthScheme.NTLM; - } - newRealm = realmBuilder.setScheme(authScheme).setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); - } - - return newRealm; - } - - private Realm ntlmProxyChallenge(List wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, - NettyResponseFuture future) throws NTLMEngineException { - future.getAndSetAuth(false); - headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); - - addType3NTLMAuthorizationHeader(wwwAuth, headers, proxyServer.getPrincipal(), proxyServer.getPassword(), proxyServer.getNtlmDomain(), proxyServer.getHost()); - - Realm newRealm; - Realm.RealmBuilder realmBuilder; - if (realm != null) { - realmBuilder = new Realm.RealmBuilder().clone(realm); - } else { - realmBuilder = new Realm.RealmBuilder(); - } - newRealm = realmBuilder// .setScheme(realm.getAuthScheme()) - .setUri(request.getURI().getPath()).setMethodName(request.getMethod()).build(); - - return newRealm; - } - - private void addType3NTLMAuthorizationHeader(List auth, FluentCaseInsensitiveStringsMap headers, String username, String password, String domain, String workstation) - throws NTLMEngineException { - headers.remove(HttpHeaders.Names.AUTHORIZATION); - - if (isNTLM(auth)) { - String serverChallenge = auth.get(0).trim().substring("NTLM ".length()); - String challengeHeader = NTLMEngine.INSTANCE.generateType3Msg(username, password, domain, workstation, serverChallenge); - - headers.add(HttpHeaders.Names.AUTHORIZATION, "NTLM " + challengeHeader); - } - } - - private List getAuthorizationToken(Iterable> list, String headerAuth) { - ArrayList l = new ArrayList(); - for (Entry e : list) { - if (e.getKey().equalsIgnoreCase(headerAuth)) { - l.add(e.getValue().trim()); - } - } - return l; - } - - private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { - if (lastValidChunk && future.isKeepAlive()) { - channels.drainChannel(ctx, future); - } else { - if (future.isKeepAlive() && ctx.channel().isActive() && channels.offerToPool(channels.getPoolKey(future), ctx.channel())) { - markAsDone(future, ctx); - return; - } - channels.finishChannel(ctx); - } - markAsDone(future, ctx); - } - - private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { - boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; - if (c.closeUnderlyingConnection()) { - future.setKeepAlive(false); - } - return state; - } - - private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { - // We need to make sure everything is OK before adding the - // connection back to the pool. - try { - future.done(); - } catch (Throwable t) { - // Never propagate exception once we know we are done. - LOGGER.debug(t.getMessage(), t); - } - - if (!future.isKeepAlive() || !ctx.channel().isActive()) { - channels.closeChannel(ctx); - } - } - - private boolean applyResponseFiltersAndReplayRequest(ChannelHandlerContext ctx, NettyResponseFuture future, HttpResponseStatus status, HttpResponseHeaders responseHeaders) - throws IOException { - - boolean replayed = false; - - AsyncHandler handler = future.getAsyncHandler(); - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(future.getRequest()).responseStatus(status).responseHeaders(responseHeaders) - .build(); - - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - // FIXME Is it work protecting against this? - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - channels.abort(future, efe); - } - } - - // The handler may have been wrapped. - handler = fc.getAsyncHandler(); - future.setAsyncHandler(handler); - - // The request has changed - if (fc.replayRequest()) { - requestSender.replayRequest(future, fc, ctx); - replayed = true; - } - return replayed; - } - - private boolean handleResponseAndExit(final ChannelHandlerContext ctx, final NettyResponseFuture future, AsyncHandler handler, HttpRequest nettyRequest, - ProxyServer proxyServer, HttpResponse response) throws Exception { - Request request = future.getRequest(); - int statusCode = response.getStatus().code(); - HttpResponseStatus status = new ResponseStatus(future.getURI(), response); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); - final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); - final RequestBuilder builder = new RequestBuilder(future.getRequest()); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - - // store the original headers so we can re-send all them to - // the handler in case of trailing headers - future.setHttpResponse(response); - - future.setKeepAlive(!HttpHeaders.Values.CLOSE.equalsIgnoreCase(response.headers().get(HttpHeaders.Names.CONNECTION))); - - if (!config.getResponseFilters().isEmpty() && applyResponseFiltersAndReplayRequest(ctx, future, status, responseHeaders)) { - return true; - } - - // FIXME handle without returns - if (statusCode == UNAUTHORIZED.code() && realm != null) { - List wwwAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.WWW_AUTHENTICATE); - if (!wwwAuth.isEmpty() && !future.getAndSetAuth(true)) { - future.setState(NettyResponseFuture.STATE.NEW); - Realm newRealm = null; - // NTLM - boolean negociate = wwwAuth.contains("Negotiate"); - if (!wwwAuth.contains("Kerberos") && (isNTLM(wwwAuth) || negociate)) { - newRealm = ntlmChallenge(wwwAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (negociate) { - newRealm = kerberosChallenge(wwwAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) { - return true; - } - } else { - newRealm = new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(request.getURI().getPath()).setMethodName(request.getMethod()) - .setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth.get(0)).build(); - } - - final Realm nr = new Realm.RealmBuilder().clone(newRealm).setUri(URI.create(request.getUrl()).getPath()).build(); - - LOGGER.debug("Sending authentication to {}", request.getUrl()); - Callback callback = new Callback(future) { - public void call() throws Exception { - channels.drainChannel(ctx, future); - requestSender.execute(builder.setHeaders(headers).setRealm(nr).build(), future); - } - }; - - if (future.isKeepAlive() && HttpHeaders.isTransferEncodingChunked(response)) { - // We must make sure there is no bytes left - // before executing the next request. - Channels.setDefaultAttribute(ctx, callback); - } else { - callback.call(); - } - - return true; - } - - } else if (statusCode == CONTINUE.code()) { - future.getAndSetWriteHeaders(false); - future.getAndSetWriteBody(true); - // FIXME is this necessary - requestSender.writeRequest(ctx.channel(), config, future); - return true; - - } else if (statusCode == PROXY_AUTHENTICATION_REQUIRED.code()) { - List proxyAuth = getAuthorizationToken(response.headers(), HttpHeaders.Names.PROXY_AUTHENTICATE); - if (realm != null && !proxyAuth.isEmpty() && !future.getAndSetAuth(true)) { - LOGGER.debug("Sending proxy authentication to {}", request.getUrl()); - - future.setState(NettyResponseFuture.STATE.NEW); - Realm newRealm = null; - - boolean negociate = proxyAuth.contains("Negotiate"); - if (!proxyAuth.contains("Kerberos") && (isNTLM(proxyAuth) || negociate)) { - newRealm = ntlmProxyChallenge(proxyAuth, request, proxyServer, headers, realm, future); - // SPNEGO KERBEROS - } else if (negociate) { - newRealm = kerberosChallenge(proxyAuth, request, proxyServer, headers, realm, future); - if (newRealm == null) { - return true; - } - } else { - newRealm = future.getRequest().getRealm(); - } - - future.setReuseChannel(true); - future.setConnectAllowed(true); - requestSender.execute(builder.setHeaders(headers).setRealm(newRealm).build(), future); - return true; - } - - } else if (statusCode == OK.code() && nettyRequest.getMethod() == HttpMethod.CONNECT) { - - LOGGER.debug("Connected to {}:{}", proxyServer.getHost(), proxyServer.getPort()); - - if (future.isKeepAlive()) { - future.attachChannel(ctx.channel(), true); - } - - try { - LOGGER.debug("Connecting to proxy {} for scheme {}", proxyServer, request.getUrl()); - channels.upgradeProtocol(ctx.channel().pipeline(), request.getURI().getScheme()); - } catch (Throwable ex) { - channels.abort(future, ex); - } - future.setReuseChannel(true); - future.setConnectAllowed(false); - requestSender.execute(builder.build(), future); - return true; - - } - - if (redirect(request, future, response, ctx)) { - return true; - } - - if (!future.getAndSetStatusReceived(true) && (handler.onStatusReceived(status) != STATE.CONTINUE || handler.onHeadersReceived(responseHeaders) != STATE.CONTINUE)) { - finishUpdate(future, ctx, HttpHeaders.isTransferEncodingChunked(response)); - return true; - } - - return false; - } - - @Override - public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture future, final Object e) throws Exception { - future.touch(); - - // The connect timeout occurred. - if (future.isCancelled() || future.isDone()) { - channels.finishChannel(ctx); - return; - } - - HttpRequest nettyRequest = future.getNettyRequest(); - AsyncHandler handler = future.getAsyncHandler(); - Request request = future.getRequest(); - ProxyServer proxyServer = future.getProxyServer(); - try { - if (e instanceof HttpResponse) { - HttpResponse response = (HttpResponse) e; - LOGGER.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); - future.getPendingResponse().set(response); - return; - } - - if (e instanceof HttpContent) { - - AtomicReference responseRef = future.getPendingResponse(); - HttpResponse response = responseRef.getAndSet(null); - if (handler != null) { - if (response != null && handleResponseAndExit(ctx, future, handler, nettyRequest, proxyServer, response)) { - return; - } - - HttpContent chunk = (HttpContent) e; - - boolean interrupt = false; - boolean last = chunk instanceof LastHttpContent; - - // FIXME - // Netty 3 provider is broken: in case of trailing headers, - // onHeadersReceived should be called before - // updateBodyAndInterrupt - if (last) { - LastHttpContent lastChunk = (LastHttpContent) chunk; - HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); - if (!trailingHeaders.isEmpty()) { - interrupt = handler.onHeadersReceived(new ResponseHeaders(future.getURI(), future.getHttpResponse().headers(), trailingHeaders)) != STATE.CONTINUE; - } - } - - if (!interrupt && chunk.content().readableBytes() > 0) { - // FIXME why - interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); - } - - if (interrupt || last) { - finishUpdate(future, ctx, !last); - } - } - } - } catch (Exception t) { - if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty() && applyIoExceptionFiltersAndReplayRequest(ctx, future, IOException.class.cast(t))) { - return; - } - - try { - channels.abort(future, t); - } finally { - finishUpdate(future, ctx, false); - throw t; - } - } - } - - @Override - public void onError(ChannelHandlerContext ctx, Throwable error) { - } - - @Override - public void onClose(ChannelHandlerContext ctx) { - } - } - - private final class WebSocketProtocol implements Protocol { - - private static final byte OPCODE_TEXT = 0x1; - private static final byte OPCODE_BINARY = 0x2; - private static final byte OPCODE_UNKNOWN = -1; - protected byte pendingOpcode = OPCODE_UNKNOWN; - - // We don't need to synchronize as replacing the "ws-decoder" will - // process using the same thread. - private void invokeOnSucces(ChannelHandlerContext ctx, WebSocketUpgradeHandler h) { - if (!h.touchSuccess()) { - try { - h.onSuccess(new NettyWebSocket(ctx.channel())); - } catch (Exception ex) { - LOGGER.warn("onSuccess unexpected exception", ex); - } - } - } - - @Override - public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object e) throws Exception { - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(future.getAsyncHandler()); - Request request = future.getRequest(); - - if (e instanceof HttpResponse) { - HttpResponse response = (HttpResponse) e; - - HttpResponseStatus s = new ResponseStatus(future.getURI(), response); - HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); - - // FIXME there's a method for that IIRC - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(h).request(request).responseStatus(s).responseHeaders(responseHeaders).build(); - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - try { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } catch (FilterException efe) { - channels.abort(future, efe); - } - } - - // The handler may have been wrapped. - future.setAsyncHandler(fc.getAsyncHandler()); - - // The request has changed - if (fc.replayRequest()) { - requestSender.replayRequest(future, fc, ctx); - return; - } - - future.setHttpResponse(response); - if (redirect(request, future, response, ctx)) - return; - - boolean validStatus = response.getStatus().equals(SWITCHING_PROTOCOLS); - boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null; - String c = response.headers().get(HttpHeaders.Names.CONNECTION); - if (c == null) { - c = response.headers().get(HttpHeaders.Names.CONNECTION.toLowerCase()); - } - - boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); - - s = new ResponseStatus(future.getURI(), response); - final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; - - final boolean headerOK = h.onHeadersReceived(responseHeaders) == STATE.CONTINUE; - if (!headerOK || !validStatus || !validUpgrade || !validConnection || !statusReceived) { - channels.abort(future, new IOException("Invalid handshake response")); - return; - } - - String accept = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT); - String key = WebSocketUtil.getAcceptKey(future.getNettyRequest().headers().get(HttpHeaders.Names.SEC_WEBSOCKET_KEY)); - if (accept == null || !accept.equals(key)) { - throw new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)); - } - - Channels.upgradePipelineForWebSockets(ctx); - - invokeOnSucces(ctx, h); - future.done(); - - } else if (e instanceof WebSocketFrame) { - - final WebSocketFrame frame = (WebSocketFrame) e; - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - invokeOnSucces(ctx, h); - - if (webSocket != null) { - if (frame instanceof CloseWebSocketFrame) { - Channels.setDefaultAttribute(ctx, DiscardEvent.INSTANCE); - CloseWebSocketFrame closeFrame = CloseWebSocketFrame.class.cast(frame); - webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText()); - } else { - if (frame instanceof TextWebSocketFrame) { - pendingOpcode = OPCODE_TEXT; - } else if (frame instanceof BinaryWebSocketFrame) { - pendingOpcode = OPCODE_BINARY; - } - - if (frame.content() != null && frame.content().readableBytes() > 0) { - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); - h.onBodyPartReceived(rp); - - if (pendingOpcode == OPCODE_BINARY) { - webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); - } else { - webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); - } - } - } - } else { - LOGGER.debug("UpgradeHandler returned a null NettyWebSocket "); - } - } else if (e instanceof LastHttpContent) { - // FIXME what to do with this kind of messages? - } else { - LOGGER.error("Invalid message {}", e); - } - } - - @Override - public void onError(ChannelHandlerContext ctx, Throwable e) { - try { - Object attribute = Channels.getDefaultAttribute(ctx); - LOGGER.warn("onError {}", e); - if (!(attribute instanceof NettyResponseFuture)) { - return; - } - - NettyResponseFuture nettyResponse = (NettyResponseFuture) attribute; - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - if (webSocket != null) { - webSocket.onError(e.getCause()); - webSocket.close(); - } - } catch (Throwable t) { - LOGGER.error("onError", t); - } - } - - @Override - public void onClose(ChannelHandlerContext ctx) { - LOGGER.trace("onClose {}"); - Object attribute = Channels.getDefaultAttribute(ctx); - if (!(attribute instanceof NettyResponseFuture)) { - return; - } - - try { - NettyResponseFuture nettyResponse = NettyResponseFuture.class.cast(attribute); - WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); - NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); - - // FIXME How could this test not succeed, attachment is a - // NettyResponseFuture???? - if (attribute != DiscardEvent.INSTANCE) - webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent)."); - } catch (Throwable t) { - LOGGER.error("onError", t); - } - } - } -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java deleted file mode 100644 index ee7f9f98fb..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/OptimizedFileRegion.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -import io.netty.channel.FileRegion; -import io.netty.util.AbstractReferenceCounted; - -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.channels.FileChannel; -import java.nio.channels.WritableByteChannel; - -public class OptimizedFileRegion extends AbstractReferenceCounted implements FileRegion { - - private final FileChannel file; - private final RandomAccessFile raf; - private final long position; - private final long count; - private long byteWritten; - - public OptimizedFileRegion(RandomAccessFile raf, long position, long count) { - this.raf = raf; - this.file = raf.getChannel(); - this.position = position; - this.count = count; - } - - public long position() { - return position; - } - - public long count() { - return count; - } - - public long transfered() { - return byteWritten; - } - - public long transferTo(WritableByteChannel target, long position) throws IOException { - long count = this.count - position; - if (count < 0 || position < 0) { - throw new IllegalArgumentException("position out of range: " + position + " (expected: 0 - " + (this.count - 1) + ")"); - } - if (count == 0) { - return 0L; - } - - long bw = file.transferTo(this.position + position, count, target); - byteWritten += bw; - if (byteWritten == raf.length()) { - deallocate(); - } - return bw; - } - - public void deallocate() { - try { - file.close(); - } catch (IOException e) { - NettyAsyncHttpProvider.LOGGER.warn("Failed to close a file.", e); - } - - try { - raf.close(); - } catch (IOException e) { - NettyAsyncHttpProvider.LOGGER.warn("Failed to close a file.", e); - } - } -} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java deleted file mode 100644 index 57445877e8..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import io.netty.channel.ChannelHandlerContext; - -public interface Protocol{ - - void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception; - - void onError(ChannelHandlerContext ctx, Throwable error); - - void onClose(ChannelHandlerContext ctx); -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java deleted file mode 100644 index 90b67893ee..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/ThreadLocalBoolean.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -public class ThreadLocalBoolean extends ThreadLocal { - - private final boolean defaultValue; - - public ThreadLocalBoolean() { - this(false); - } - - public ThreadLocalBoolean(boolean defaultValue) { - this.defaultValue = defaultValue; - } - - @Override - protected Boolean initialValue() { - return defaultValue ? Boolean.TRUE : Boolean.FALSE; - } -} \ No newline at end of file diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java deleted file mode 100644 index be2d720842..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/spnego/SpnegoTokenGenerator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -/* - * ==================================================================== - * - * 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 - * . - * - */ - -package org.asynchttpclient.providers.netty4.spnego; - -import java.io.IOException; - -/** - * Abstract SPNEGO token generator. Implementations should take an Kerberos ticket and transform - * into a SPNEGO token. - *

- * Implementations of this interface are expected to be thread-safe. - * - * @since 4.1 - */ -public interface SpnegoTokenGenerator { - - byte[] generateSpnegoDERObject(byte[] kerberosTicket) throws IOException; - -} diff --git a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java b/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java deleted file mode 100644 index 2de4e4d7aa..0000000000 --- a/providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/util/CleanupChannelGroup.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -/* - * Copyright 2010 Bruno de Carvalho - * - * Licensed 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. - */ - -package org.asynchttpclient.providers.netty4.util; - -import io.netty.channel.Channel; -//import io.netty.channel.ChannelFuture; -//import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.ChannelGroupFuture; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.util.concurrent.GlobalEventExecutor; - -//import java.util.ArrayList; -//import java.util.Collection; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; - -/** - * Extension of {@link DefaultChannelGroup} that's used mainly as a cleanup container, where {@link #close()} is only - * supposed to be called once. - * - * @author Bruno de Carvalho - */ -public class CleanupChannelGroup extends DefaultChannelGroup { - -// private final static Logger logger = LoggerFactory.getLogger(CleanupChannelGroup.class); - - // internal vars -------------------------------------------------------------------------------------------------- - - private final AtomicBoolean closed = new AtomicBoolean(false); - private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); - - // constructors --------------------------------------------------------------------------------------------------- - - public CleanupChannelGroup() { - super(GlobalEventExecutor.INSTANCE); - } - - public CleanupChannelGroup(String name) { - super(name, GlobalEventExecutor.INSTANCE); - } - - // DefaultChannelGroup -------------------------------------------------------------------------------------------- - - @Override - public ChannelGroupFuture close() { - this.lock.writeLock().lock(); - try { - if (!this.closed.getAndSet(true)) { - // First time close() is called. - return super.close(); - } else { - // FIXME DefaultChannelGroupFuture is package protected -// Collection futures = new ArrayList(); -// logger.debug("CleanupChannelGroup already closed"); -// return new DefaultChannelGroupFuture(ChannelGroup.class.cast(this), futures, GlobalEventExecutor.INSTANCE); - throw new UnsupportedOperationException("CleanupChannelGroup already closed"); - } - } finally { - this.lock.writeLock().unlock(); - } - } - - @Override - public boolean add(Channel channel) { - // Synchronization must occur to avoid add() and close() overlap (thus potentially leaving one channel open). - // This could also be done by synchronizing the method itself but using a read lock here (rather than a - // synchronized() block) allows multiple concurrent calls to add(). - this.lock.readLock().lock(); - try { - if (this.closed.get()) { - // Immediately close channel, as close() was already called. - channel.close(); - return false; - } - - return super.add(channel); - } finally { - this.lock.readLock().unlock(); - } - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java deleted file mode 100644 index 177e28611a..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncHttpProviderTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.AbstractBasicTest; - -public class NettyAsyncHttpProviderTest extends AbstractBasicTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java deleted file mode 100644 index 113366e944..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderBasicTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig; -import org.testng.annotations.Test; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProviderConfig; -import org.asynchttpclient.async.AsyncProvidersBasicTest; - -@Test -public class NettyAsyncProviderBasicTest extends AsyncProvidersBasicTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @Override - protected AsyncHttpProviderConfig getProviderConfig() { - final NettyAsyncHttpProviderConfig config = new NettyAsyncHttpProviderConfig(); - config.addProperty("TCP_NODELAY", true); - return config; - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java deleted file mode 100644 index c670f5dfa6..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncProviderPipelineTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.netty4; - -import static org.testng.Assert.*; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.http.HttpMessage; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.async.AbstractBasicTest; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProviderConfig.AdditionalChannelInitializer; -import org.testng.annotations.Test; - -public class NettyAsyncProviderPipelineTest extends AbstractBasicTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @Test(groups = { "standalone", "netty_provider" }) - public void asyncPipelineTest() throws Exception { - - NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); - nettyConfig.setHttpAdditionalChannelInitializer(new AdditionalChannelInitializer() { - public void initChannel(Channel ch) throws Exception { - // super.initPlainChannel(ch); - ch.pipeline().addBefore("inflater", "copyEncodingHeader", new CopyEncodingHandler()); - } - }); - AsyncHttpClient p = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAsyncHttpClientProviderConfig(nettyConfig).build()); - - try { - final CountDownLatch l = new CountDownLatch(1); - Request request = new RequestBuilder("GET").setUrl(getTargetUrl()).build(); - p.executeRequest(request, new AsyncCompletionHandlerAdapter() { - @Override - public Response onCompleted(Response response) throws Exception { - try { - assertEquals(response.getStatusCode(), 200); - assertEquals(response.getHeader("X-Original-Content-Encoding"), ""); - } finally { - l.countDown(); - } - return response; - } - }).get(); - if (!l.await(TIMEOUT, TimeUnit.SECONDS)) { - fail("Timeout out"); - } - } finally { - p.close(); - } - } - - private static class CopyEncodingHandler extends ChannelInboundHandlerAdapter { - @Override - public void channelRead(ChannelHandlerContext ctx, Object e) { - if (e instanceof HttpMessage) { - HttpMessage m = (HttpMessage) e; - // for test there is no Content-Encoding header so just hard - // coding value - // for verification - m.headers().set("X-Original-Content-Encoding", ""); - } - ctx.fireChannelRead(e); - } - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java deleted file mode 100644 index 653a89ceef..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncResponseTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.Cookie; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.providers.netty4.NettyResponse; -import org.asynchttpclient.providers.netty4.ResponseStatus; -import org.testng.annotations.Test; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.TimeZone; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -/** - * @author Benjamin Hanzelmann - */ -public class NettyAsyncResponseTest { - - @Test(groups = "standalone") - public void testCookieParseExpires() { - // e.g. "Sun, 06-Feb-2012 03:45:24 GMT"; - SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US); - sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - - Date date = new Date(System.currentTimeMillis() + 60000); // sdf.parse( dateString ); - final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date)); - - NettyResponse - response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { - @Override - public FluentCaseInsensitiveStringsMap getHeaders() { - return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); - } - }, null); - - List cookies = response.getCookies(); - assertEquals(cookies.size(), 1); - - Cookie cookie = cookies.get(0); - assertTrue(cookie.getMaxAge() > 55 && cookie.getMaxAge() < 61, ""); - } - - @Test(groups = "standalone") - public void testCookieParseMaxAge() { - final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { - @Override - public FluentCaseInsensitiveStringsMap getHeaders() { - return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); - } - }, null); - List cookies = response.getCookies(); - assertEquals(cookies.size(), 1); - - Cookie cookie = cookies.get(0); - assertEquals(cookie.getMaxAge(), 60); - } - - @Test(groups = "standalone") - public void testCookieParseWeirdExpiresValue() { - final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { - @Override - public FluentCaseInsensitiveStringsMap getHeaders() { - return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); - } - }, null); - - List cookies = response.getCookies(); - assertEquals(cookies.size(), 1); - - Cookie cookie = cookies.get(0); - assertEquals(cookie.getMaxAge(), 60); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java deleted file mode 100644 index cd292b06c1..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamHandlerTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.AsyncStreamHandlerTest; - -public class NettyAsyncStreamHandlerTest extends AsyncStreamHandlerTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java deleted file mode 100644 index acba9b815f..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAsyncStreamLifecycleTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.AsyncStreamLifecycleTest; - -public class NettyAsyncStreamLifecycleTest extends AsyncStreamLifecycleTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java deleted file mode 100644 index d49325760f..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyAuthTimeoutTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.AuthTimeoutTest; -import org.testng.annotations.Test; - -@Test -public class NettyAuthTimeoutTest extends AuthTimeoutTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java deleted file mode 100644 index 971fe6b107..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicAuthTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.BasicAuthTest; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; - -public class NettyBasicAuthTest extends BasicAuthTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @Override - public String getProviderClass() { - return NettyAsyncHttpProvider.class.getName(); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java deleted file mode 100644 index 31a20c5278..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBasicHttpsTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.BasicHttpsTest; - -public class NettyBasicHttpsTest extends BasicHttpsTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java deleted file mode 100644 index 4cd124390f..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyChunkTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.BodyChunkTest; - -public class NettyBodyChunkTest extends BodyChunkTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java deleted file mode 100644 index 0a8e231014..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyBodyDeferringAsyncHandlerTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.BodyDeferringAsyncHandlerTest; - -public class NettyBodyDeferringAsyncHandlerTest extends BodyDeferringAsyncHandlerTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java deleted file mode 100644 index b87ff9d130..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyByteBufferCapacityTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ByteBufferCapacityTest; - -public class NettyByteBufferCapacityTest extends ByteBufferCapacityTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java deleted file mode 100644 index bc36fc0546..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyChunkingTest.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ChunkingTest; - -public class NettyChunkingTest extends ChunkingTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java deleted file mode 100644 index f36fa3f814..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyComplexClientTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ComplexClientTest; - -public class NettyComplexClientTest extends ComplexClientTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java deleted file mode 100644 index 1db87da20b..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyConnectionPoolTest.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.util.concurrent.TimeUnit; - -import io.netty.channel.Channel; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ConnectionsPool; -import org.asynchttpclient.async.ConnectionPoolTest; - -public class NettyConnectionPoolTest extends ConnectionPoolTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @Override - public void testInvalidConnectionsPool() { - ConnectionsPool cp = new ConnectionsPool() { - - public boolean offer(String key, Channel connection) { - return false; - } - - public Channel poll(String connection) { - return null; - } - - public boolean removeAll(Channel connection) { - return false; - } - - public boolean canCacheConnection() { - return false; - } - - public void destroy() { - - } - }; - - AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build()); - try { - Exception exception = null; - try { - client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS); - } catch (Exception ex) { - ex.printStackTrace(); - exception = ex; - } - assertNotNull(exception); - assertEquals(exception.getMessage(), "Too many connections -1"); - } finally { - client.close(); - } - } - - @Override - public void testValidConnectionsPool() { - ConnectionsPool cp = new ConnectionsPool() { - - public boolean offer(String key, Channel connection) { - return true; - } - - public Channel poll(String connection) { - return null; - } - - public boolean removeAll(Channel connection) { - return false; - } - - public boolean canCacheConnection() { - return true; - } - - public void destroy() { - - } - }; - - AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setConnectionsPool(cp).build()); - try { - Exception exception = null; - try { - client.prepareGet(getTargetUrl()).execute().get(TIMEOUT, TimeUnit.SECONDS); - } catch (Exception ex) { - ex.printStackTrace(); - exception = ex; - } - assertNull(exception); - } finally { - client.close(); - } - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java deleted file mode 100644 index 25d0771169..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyDigestAuthTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.DigestAuthTest; - -public class NettyDigestAuthTest extends DigestAuthTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java deleted file mode 100644 index 5c7f89ef2e..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyEmptyBodyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.EmptyBodyTest; - -public class NettyEmptyBodyTest extends EmptyBodyTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java deleted file mode 100644 index ed3a02549b..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyErrorResponseTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ErrorResponseTest; - -public class NettyErrorResponseTest extends ErrorResponseTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java deleted file mode 100644 index 62d52429e8..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyExpect100ContinueTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.Expect100ContinueTest; - -public class NettyExpect100ContinueTest extends Expect100ContinueTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java deleted file mode 100644 index 02c459157e..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilePartLargeFileTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.FilePartLargeFileTest; - -public class NettyFilePartLargeFileTest extends FilePartLargeFileTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java deleted file mode 100644 index bb0ea1fed4..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFilterTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.FilterTest; - -public class NettyFilterTest extends FilterTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java deleted file mode 100644 index 4461d5ef06..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyFollowingThreadTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.FollowingThreadTest; - -public class NettyFollowingThreadTest extends FollowingThreadTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java deleted file mode 100644 index d4c13d3206..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHead302Test.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.Head302Test; - -public class NettyHead302Test extends Head302Test { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java deleted file mode 100644 index f5051ec05c..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHostnameVerifierTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.HostnameVerifierTest; - -public class NettyHostnameVerifierTest extends HostnameVerifierTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java deleted file mode 100644 index 89cf0d322a..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyHttpToHttpsRedirectTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.HttpToHttpsRedirectTest; - -public class NettyHttpToHttpsRedirectTest extends HttpToHttpsRedirectTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java deleted file mode 100644 index 107cb8b0d5..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyIdleStateHandlerTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.IdleStateHandlerTest; - -public class NettyIdleStateHandlerTest extends IdleStateHandlerTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java deleted file mode 100644 index 1d271ee4ff..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyInputStreamTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.InputStreamTest; - -public class NettyInputStreamTest extends InputStreamTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java deleted file mode 100644 index cce436950d..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyListenableFutureTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ListenableFutureTest; - -public class NettyListenableFutureTest extends ListenableFutureTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java deleted file mode 100644 index 593bb71bb8..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxConnectionsInThreads.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010-2012 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and Apache License v2.0 which accompanies this distribution. - * The Eclipse Public License is available at - * http://www.eclipse.org/legal/epl-v10.html - * The Apache License v2.0 is available at - * http://www.apache.org/licenses/LICENSE-2.0.html - * You may elect to redistribute this code under either of these licenses. - *******************************************************************************/ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.MaxConnectionsInThreads; - -public class NettyMaxConnectionsInThreads extends MaxConnectionsInThreads { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java deleted file mode 100644 index 5aef28ba4c..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMaxTotalConnectionTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.MaxTotalConnectionTest; - -public class NettyMaxTotalConnectionTest extends MaxTotalConnectionTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java deleted file mode 100644 index ff5a2028bb..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipartUploadTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.MultipartUploadTest; - -/** - * @author dominict - */ -public class NettyMultipartUploadTest extends MultipartUploadTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java deleted file mode 100644 index 8cb91eae98..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyMultipleHeaderTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.MultipleHeaderTest; - -public class NettyMultipleHeaderTest extends MultipleHeaderTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java deleted file mode 100644 index d74dc2d284..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNoNullResponseTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.NoNullResponseTest; - -public class NettyNoNullResponseTest extends NoNullResponseTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java deleted file mode 100644 index 098f63c3cb..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyNonAsciiContentLengthTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.NonAsciiContentLengthTest; - -public class NettyNonAsciiContentLengthTest extends NonAsciiContentLengthTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java deleted file mode 100644 index 380dbeb710..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyParamEncodingTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ParamEncodingTest; - -public class NettyParamEncodingTest extends ParamEncodingTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java deleted file mode 100644 index c8a45f3c34..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestRelative302Test.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.PerRequestRelative302Test; - -public class NettyPerRequestRelative302Test extends PerRequestRelative302Test { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java deleted file mode 100644 index 4b669e81f9..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPerRequestTimeoutTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import static org.testng.Assert.assertTrue; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.PerRequestTimeoutTest; - -public class NettyPerRequestTimeoutTest extends PerRequestTimeoutTest { - - @Override - protected void checkTimeoutMessage(String message) { - assertTrue(message - .startsWith("Request reached time out of 100 ms after ")); - } - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java deleted file mode 100644 index 6c434178b4..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostRedirectGetTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.PostRedirectGetTest; - -public class NettyPostRedirectGetTest extends PostRedirectGetTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java deleted file mode 100644 index 44850262f6..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPostWithQSTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.PostWithQSTest; - -public class NettyPostWithQSTest extends PostWithQSTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java deleted file mode 100644 index b5cae8cefa..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ProxyTest; - -public class NettyProxyTest extends ProxyTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java deleted file mode 100644 index 736b9d3699..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyProxyTunnellingTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ProxyTunnellingTest; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; - -public class NettyProxyTunnellingTest extends ProxyTunnellingTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - public String getProviderClass() { - return NettyAsyncHttpProvider.class.getName(); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java deleted file mode 100644 index f71d57cea5..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyPutLargeFileTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.PutLargeFileTest; - -public class NettyPutLargeFileTest extends PutLargeFileTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java deleted file mode 100644 index cc7fe3628a..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyQueryParametersTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.QueryParametersTest; - -public class NettyQueryParametersTest extends QueryParametersTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java deleted file mode 100644 index 2c63c75b9d..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRC10KTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.RC10KTest; - -public class NettyRC10KTest extends RC10KTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java deleted file mode 100644 index 91d782bd20..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRedirectConnectionUsageTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.RedirectConnectionUsageTest; - -public class NettyRedirectConnectionUsageTest extends RedirectConnectionUsageTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java deleted file mode 100644 index b9880e79c5..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRelative302Test.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.Relative302Test; - -public class NettyRelative302Test extends Relative302Test { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java deleted file mode 100644 index 7a65ad5bca..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRemoteSiteTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.RemoteSiteTest; - -public class NettyRemoteSiteTest extends RemoteSiteTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java deleted file mode 100644 index 766a8f1d97..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRequestThrottleTimeoutTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import static org.testng.Assert.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Future; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.asynchttpclient.AsyncCompletionHandler; -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Response; -import org.asynchttpclient.async.AbstractBasicTest; -import org.eclipse.jetty.continuation.Continuation; -import org.eclipse.jetty.continuation.ContinuationSupport; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; - -public class NettyRequestThrottleTimeoutTest extends AbstractBasicTest { - private static final String MSG = "Enough is enough."; - private static final int SLEEPTIME_MS = 1000; - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @Override - public AbstractHandler configureHandler() throws Exception { - return new SlowHandler(); - } - - private class SlowHandler extends AbstractHandler { - public void handle(String target, Request baseRequest, HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { - response.setStatus(HttpServletResponse.SC_OK); - final Continuation continuation = ContinuationSupport.getContinuation(request); - continuation.suspend(); - new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(SLEEPTIME_MS); - response.getOutputStream().print(MSG); - response.getOutputStream().flush(); - continuation.complete(); - } catch (InterruptedException e) { - logger.error(e.getMessage(), e); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - } - }).start(); - baseRequest.setHandled(true); - } - } - - @Test(groups = { "standalone", "netty_provider" }) - public void testRequestTimeout() throws IOException { - final Semaphore requestThrottle = new Semaphore(1); - - final AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setCompressionEnabled(true).setAllowPoolingConnection(true) - .setMaximumConnectionsTotal(1).build()); - try { - final CountDownLatch latch = new CountDownLatch(2); - final List tooManyConnections = Collections.synchronizedList(new ArrayList(2)); - - for (int i = 0; i < 2; i++) { - new Thread(new Runnable() { - - public void run() { - try { - requestThrottle.acquire(); - Future responseFuture = null; - try { - responseFuture = client.prepareGet(getTargetUrl()).setRequestTimeoutInMs(SLEEPTIME_MS / 2).execute(new AsyncCompletionHandler() { - - @Override - public Response onCompleted(Response response) throws Exception { - requestThrottle.release(); - return response; - } - - @Override - public void onThrowable(Throwable t) { - requestThrottle.release(); - } - }); - } catch (Exception e) { - tooManyConnections.add(e); - } - - if (responseFuture != null) - responseFuture.get(); - } catch (Exception e) { - } finally { - latch.countDown(); - } - - } - }).start(); - } - - try { - latch.await(30, TimeUnit.SECONDS); - } catch (Exception e) { - fail("failed to wait for requests to complete"); - } - - assertTrue(tooManyConnections.isEmpty(), "Should not have any connection errors where too many connections have been attempted"); - } finally { - client.close(); - } - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java deleted file mode 100644 index ed148663e6..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyRetryRequestTest.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ - -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.RetryRequestTest; - -public class NettyRetryRequestTest extends RetryRequestTest{ - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java deleted file mode 100644 index ad60dd6125..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettySimpleAsyncHttpClientTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.SimpleAsyncHttpClientTest; -import org.asynchttpclient.providers.netty4.NettyAsyncHttpProvider; - -public class NettySimpleAsyncHttpClientTest extends SimpleAsyncHttpClientTest { - - /** - * Not Used with {@link org.asynchttpclient.SimpleAsyncHttpClient} - * @param config - * @return - */ - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return null; - } - - public String getProviderClass() { - return NettyAsyncHttpProvider.class.getName(); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java deleted file mode 100644 index deeb92e9c1..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyTransferListenerTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.TransferListenerTest; - -public class NettyTransferListenerTest extends TransferListenerTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java deleted file mode 100644 index 5a26dbeac3..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyWebDavBasicTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.WebDavBasicTest; - -public class NettyWebDavBasicTest extends WebDavBasicTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java deleted file mode 100644 index 04ee3c7a22..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/NettyZeroCopyFileTest.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.async.ZeroCopyFileTest; - -public class NettyZeroCopyFileTest extends ZeroCopyFileTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java deleted file mode 100644 index d1b2dc45ed..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/RetryNonBlockingIssue.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4; - -import static org.asynchttpclient.async.util.TestUtils.*; -import static org.testng.Assert.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutionException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.async.AbstractBasicTest; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -//FIXME there's no retry actually -public class RetryNonBlockingIssue extends AbstractBasicTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } - - @BeforeClass(alwaysRun = true) - public void setUpGlobal() throws Exception { - port1 = findFreePort(); - server = newJettyHttpServer(port1); - - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); - context.setContextPath("/"); - context.addServlet(new ServletHolder(new MockExceptionServlet()), "/*"); - - server.setHandler(context); - server.start(); - } - - protected String getTargetUrl() { - return String.format("http://127.0.0.1:%d/", port1); - } - - private ListenableFuture testMethodRequest(AsyncHttpClient client, int requests, String action, String id) throws IOException { - Request r = new RequestBuilder("GET")// - .setUrl(getTargetUrl())// - .addQueryParameter(action, "1")// - .addQueryParameter("maxRequests", "" + requests)// - .addQueryParameter("id", id)// - .build(); - return client.executeRequest(r); - } - - /** - * Tests that a head request can be made - * - * @throws IOException - * @throws ExecutionException - * @throws InterruptedException - */ - @Test - public void testRetryNonBlocking() throws IOException, InterruptedException, ExecutionException { - - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// - .setAllowPoolingConnection(true)// - .setMaximumConnectionsTotal(100)// - .setConnectionTimeoutInMs(60000)// - .setRequestTimeoutInMs(30000)// - .build(); - - AsyncHttpClient client = getAsyncHttpClient(config); - try { - List> res = new ArrayList>(); - for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); - } - - StringBuilder b = new StringBuilder(); - for (ListenableFuture r : res) { - Response theres = r.get(); - assertEquals(200, theres.getStatusCode()); - b.append("==============\r\n"); - b.append("Response Headers\r\n"); - Map> heads = theres.getHeaders(); - b.append(heads + "\r\n"); - b.append("==============\r\n"); - assertTrue(heads.size() > 0); - } - System.out.println(b.toString()); - System.out.flush(); - - } finally { - client.close(); - } - } - - @Test - public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedException, ExecutionException { - - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// - .setAllowPoolingConnection(true)// - .setMaximumConnectionsTotal(100)// - .setConnectionTimeoutInMs(60000)// - .setRequestTimeoutInMs(30000)// - .setAsyncConnectMode(true) // - .build(); - - AsyncHttpClient client = getAsyncHttpClient(config); - - try { - List> res = new ArrayList>(); - for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); - } - - StringBuilder b = new StringBuilder(); - for (ListenableFuture r : res) { - Response theres = r.get(); - assertEquals(theres.getStatusCode(), 200); - b.append("==============\r\n"); - b.append("Response Headers\r\n"); - Map> heads = theres.getHeaders(); - b.append(heads + "\r\n"); - b.append("==============\r\n"); - assertTrue(heads.size() > 0); - } - System.out.println(b.toString()); - System.out.flush(); - - } finally { - client.close(); - } - } - - @Test - public void testRetryBlocking() throws IOException, InterruptedException, ExecutionException { - - NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); - nettyConfig.setUseBlockingIO(true); - - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// - .setAllowPoolingConnection(true)// - .setMaximumConnectionsTotal(100)// - .setConnectionTimeoutInMs(60000)// - .setRequestTimeoutInMs(30000)// - .setAsyncHttpClientProviderConfig(nettyConfig)// - .build(); - - AsyncHttpClient client = getAsyncHttpClient(config); - - try { - List> res = new ArrayList>(); - for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); - } - - StringBuilder b = new StringBuilder(); - for (ListenableFuture r : res) { - Response theres = r.get(); - assertEquals(theres.getStatusCode(), 200); - b.append("==============\r\n"); - b.append("Response Headers\r\n"); - Map> heads = theres.getHeaders(); - b.append(heads + "\r\n"); - b.append("==============\r\n"); - assertTrue(heads.size() > 0); - - } - System.out.println(b.toString()); - System.out.flush(); - - } finally { - client.close(); - } - } - - @SuppressWarnings("serial") - public class MockExceptionServlet extends HttpServlet { - - private Map requests = new ConcurrentHashMap(); - - private synchronized int increment(String id) { - int val = 0; - if (requests.containsKey(id)) { - Integer i = requests.get(id); - val = i + 1; - requests.put(id, val); - } else { - requests.put(id, 1); - val = 1; - } - System.out.println("REQUESTS: " + requests); - return val; - } - - public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - String maxRequests = req.getParameter("maxRequests"); - int max = 0; - try { - max = Integer.parseInt(maxRequests); - } catch (NumberFormatException e) { - max = 3; - } - String id = req.getParameter("id"); - int requestNo = increment(id); - String servlet = req.getParameter("servlet"); - String io = req.getParameter("io"); - String error = req.getParameter("500"); - - if (requestNo >= max) { - res.setHeader("Success-On-Attempt", "" + requestNo); - res.setHeader("id", id); - if (servlet != null && servlet.trim().length() > 0) - res.setHeader("type", "servlet"); - if (error != null && error.trim().length() > 0) - res.setHeader("type", "500"); - if (io != null && io.trim().length() > 0) - res.setHeader("type", "io"); - res.setStatus(200); - res.setContentLength(0); - res.flushBuffer(); - return; - } - - res.setStatus(200); - res.setContentLength(100); - res.setContentType("application/octet-stream"); - res.flushBuffer(); - - // error after flushing the status - if (servlet != null && servlet.trim().length() > 0) - throw new ServletException("Servlet Exception"); - - if (io != null && io.trim().length() > 0) - throw new IOException("IO Exception"); - - if (error != null && error.trim().length() > 0) { - res.sendError(500, "servlet process was 500"); - } - } - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java deleted file mode 100644 index 5474f7f9f2..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyByteMessageTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4.websocket; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty4.NettyProviderUtil; -import org.asynchttpclient.websocket.ByteMessageTest; - -public class NettyByteMessageTest extends ByteMessageTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java deleted file mode 100644 index f44962885b..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyCloseCodeReasonMsgTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ - -package org.asynchttpclient.providers.netty4.websocket; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty4.NettyProviderUtil; -import org.asynchttpclient.websocket.CloseCodeReasonMessageTest; - -public class NettyCloseCodeReasonMsgTest extends CloseCodeReasonMessageTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java deleted file mode 100644 index a5e9d8cec7..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyRedirectTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4.websocket; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty4.NettyProviderUtil; -import org.asynchttpclient.websocket.RedirectTest; - -public class NettyRedirectTest extends RedirectTest { - - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java b/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java deleted file mode 100644 index 10832e370b..0000000000 --- a/providers/netty4/src/test/java/org/asynchttpclient/providers/netty4/websocket/NettyTextMessageTest.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.netty4.websocket; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.providers.netty4.NettyProviderUtil; -import org.asynchttpclient.websocket.TextMessageTest; - -public class NettyTextMessageTest extends TextMessageTest { - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - return NettyProviderUtil.nettyProvider(config); - } -} diff --git a/providers/netty4/src/test/resources/300k.png b/providers/netty4/src/test/resources/300k.png deleted file mode 100644 index bff4a8598918ed4945bc27db894230d8b5b7cc80..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265495 zcmV)wK$O3UP)4Tx0C)k_S!Y-jOSA6TybDWOa?Uv;S#r)f3c`|eT%s5Vq5=jGkfbOeQNVzJ zh$0}MqDW9c0mXoTprU{v@eX><`M&#n_x`(oZtt@_?^ab;_fFMxSJeQ(wn&bM2tm*R z5E@2_vNh7>b#`&(#ZCYu{J{b>AWZg-j?l5THV6M}`#B1rJ?4nip058@?0;s^`}jtC z0{~gWY%iZ^?@$;w0f5l;j)^gK?Ay7^5D+m@x`oAdDyXu>T*tw1>TZV>Ifw zjJ>TM0BBYKaMWaSls^DOL72`P>+KKgA?gEwVF>dH3@SLKmISf(2yATe*JC?a8Df; zV!3AE#SN|_M0^t{EX!1t}!4OC>*_(?IwmE-rxY^zs;JFY=zzl={Ul0SL z;64mU0dt@S^#AImfFB^koLHC_4T8ZZ7>B|m!r?LDFy{SBPVYY`hQG)8!{h$DMqc0z z%f|dO=bzbl;W_`-83=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P79h!5!(Yis_B>z)d!uIT$0ZW(6pZ|iTT0rTL|L&F7 z|7|}e{lhx^`LPwtMEO~MH-Ec)RPHd7X^3!?*hHgmrJvVnCtlZj|4E5ia_&VB#^X$) z4AT<=`bCww&up5svuV-m7VZxbGG9SX`~Gl2>$Tao_fGFw9b>j5d}rm9^}Byry=wXy z?!#@%-jp5~8Q!<+N~Hg@LUw`1hAp0Ag~~5{G{l6rpXW5{IkD`ajaXH8NKLQCgT?FQ zv^Os+otU?{p8J=gY0}5vNmYz0)@PP{+_xfdLg$L+`wyd@&S#s{ofg+n9jcnb=wtow zyr&j(V+#XQV}qE#=dv>_tVS0SM zb^Yo%sXLrK}p1`GzeOd@Pw zodt4u{6e(vA2`HO+B92w!wh#|NKWxz^=|T`qCJkbBGpxg?9xA-vrW8om3MhUa?$C( Q>4ou<|EC`eTz_&S0BPL&!vFvP diff --git a/providers/netty4/src/test/resources/gzip.txt.gz b/providers/netty4/src/test/resources/gzip.txt.gz deleted file mode 100644 index 80aeb98d2b03a00c13d7c2725d3e281f47a57d81..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 47 zcmb2|=HR#?o9WBIoL-e#pjT2+!r;CBl#a)_^V*(gwKoQx@Hl(&Bs)Xnt@zJE3=9ka Do?Q|u diff --git a/providers/netty4/src/test/resources/logback-test.xml b/providers/netty4/src/test/resources/logback-test.xml deleted file mode 100644 index 4acf278710..0000000000 --- a/providers/netty4/src/test/resources/logback-test.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - %d [%thread] %level %logger - %m%n - - - - - - - - - \ No newline at end of file diff --git a/providers/netty4/src/test/resources/realm.properties b/providers/netty4/src/test/resources/realm.properties deleted file mode 100644 index bc9faad66a..0000000000 --- a/providers/netty4/src/test/resources/realm.properties +++ /dev/null @@ -1 +0,0 @@ -user=admin, admin \ No newline at end of file diff --git a/providers/netty4/src/test/resources/ssltest-cacerts.jks b/providers/netty4/src/test/resources/ssltest-cacerts.jks deleted file mode 100644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EVu=442wl0v-D9 zY(M8{-PubkwzyTHh=e~puP#a?<`8Y573wnC))7D8CjX>JzqOAqOET}qY8W3qwFIq% zsgqZxO;|@)yV;Qf{a@bi(_EC};ihIUSJTZn_Oa;jzOKEk!wH4^|gKF_(#8tA4@lW=+Zd(SpK;7LM`c(&h7%?_;A_W(D-b*&d+B392QxIJIT3K8mjl zD{82bd5MoMGV?JzzH+EdLh~lFT=|uA+s^a;bW5`p^R?;g?M?mD*u4DX)2wTJ_K$`~ z#fkJvE@N^%ad{7lPReD;f9}%Zm{iq$IVx_bD+t@EUm~~$zKvw#WsG;v> z2OhmMYxnZ|yX#+->E!eXE~-yw$zt*nR+kRnUzKmhKB-f`D8BgiSiiiy@i@=+UFyYfkd(N8_S4}x2gVV#U}iarSjKkO6^c`eDA}GZT?GhqaIO2{k-+j; z(NrA!B5fX{#$yzgxAe|(3BBY~#J{_?Q#?sKe-+Kpl%+>rqn~tL63ucc$=2VLkA%>! zEXzD54_V8;pn2gfD!D02i%j6>!J;Bs#M3)@hGls#7MTMX#cJg|cChX#T{ZLWJ=GE! zU5K~hP9gnS1$iTKXu&(?HoNMF6kM`PJ!9O|sN22V0yYKe@03qG# A2><{9 diff --git a/providers/netty4/src/test/resources/ssltest-keystore.jks b/providers/netty4/src/test/resources/ssltest-keystore.jks deleted file mode 100644 index a95b7c5f4fbe9f9cba881475b3854861cb182263..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1445 zcmezO_TO6u1_mY|W&~rFV#CB@AV=73#>MqOiCqRwOxq0j*toRW7+Dy#m;@OaSs7TG zm==Ahum1KTDl}5e`kqee9lk>GwJCjfCp7D~ov*(x`E$+b6=xjpnr%q9^|4>@`!@E+ zi}uIu{+!!*!-C=Vp@lxxA&;l{Nk*7CEQ|PTX1Z`q#lHsu!v5(6#vw9KEZxO~bf#Zb zE?Il~dGkX>A=cv6>qSIP+-5VqZyGyUOVDFdgS=Z}_JfL#JMP&==)6<6Sh2b9`t5ry zzPG<5v@n$N`kc{=4oZz#{&v|`N2`6xPN7puSbB3j=P~RMOPb*@xlF*s=gqB!uVbHl z2<4ScJw8W+`&G{xr?Pq@ONfRqihy3>ye<~BGoZ+h#{_(N>D|Fs2ur2%ps7pF>I zDyq!Qu>EItI4*4OBcD3qb*tuHm9|&fwWayCaOz5XseaVX$*ge1Rv~TixJ>9JFm50^r<=XRnFV)>E5XyX* z`20}6VuG$_v3GNlivo}JLPd+C-52%4{>}87eQM$FyR%#4dd~lTX}Zdhn78D zytSvNb1s=yot+rkvqPAJ?zzMvo@KDD8@ayqLK67Bw^~d=)8$1RIHVRV%M2zL;>ym3BqC9{cp0q5C^#N!jg;Oqrb#c%Au7>88ae?(Y>*m{+_%clwSNmXJJ#2fue( zuJwJi@zm*L*}2hczl+}&I(v&Z{!e{~)NHj6dxQ**W%OyC*S>kOC&pB3PjK_JM&HO^ zRTfe!{SI<_w7t5|Kk+(W=VGl)mKCeLEB4tu{LIA6$iRr~JYXVV2D)pqdW7|<3-SD= zw~jv1mb8iy&d&Q#`!qf`dG>O9pQr~tnf__VzSRmDJ@rmb-s#wH?mS~d;Zu_jv8;Q9 z_!+M@r%rmY%EEvlj5C;{;O@<$*r}E~J@OlQHe8oaPUyCHC1O(4B!1-dme<8*cPnpb uEt|hX&w*2cNrXr4-_Nv(?*ugF{&{FJ?S$IdRLMmwGq0yv95LW9JOTidn?aWV diff --git a/providers/netty4/src/test/resources/textfile.txt b/providers/netty4/src/test/resources/textfile.txt deleted file mode 100644 index 87daee60a9..0000000000 --- a/providers/netty4/src/test/resources/textfile.txt +++ /dev/null @@ -1 +0,0 @@ -filecontent: hello \ No newline at end of file diff --git a/providers/netty4/src/test/resources/textfile2.txt b/providers/netty4/src/test/resources/textfile2.txt deleted file mode 100644 index 6a91fe609c..0000000000 --- a/providers/netty4/src/test/resources/textfile2.txt +++ /dev/null @@ -1 +0,0 @@ -filecontent: hello2 \ No newline at end of file diff --git a/providers/pom.xml b/providers/pom.xml index 9a7178b576..72af625a7f 100644 --- a/providers/pom.xml +++ b/providers/pom.xml @@ -46,7 +46,6 @@ grizzly netty - netty4 From 290dd6643dfe9a996fcb9a0933d1cd31b99b68dd Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 13:31:49 +0200 Subject: [PATCH 0139/2389] Remove HttpContent and clean up Status, Headers and BodyParts --- .../asynchttpclient/AsyncHttpProvider.java | 17 +-- .../java/org/asynchttpclient/HttpContent.java | 49 -------- .../asynchttpclient/HttpResponseBodyPart.java | 7 +- .../asynchttpclient/HttpResponseHeaders.java | 9 +- .../asynchttpclient/HttpResponseStatus.java | 54 ++++++--- .../java/org/asynchttpclient/Response.java | 109 +++++++++--------- .../providers/ResponseBase.java | 2 +- .../providers/jdk/JDKAsyncHttpProvider.java | 76 ++++++------ .../providers/jdk/ResponseBodyPart.java | 1 - .../providers/jdk/ResponseHeaders.java | 1 - .../providers/jdk/ResponseStatus.java | 15 ++- .../resumable/ResumableAsyncHandler.java | 2 +- .../webdav/WebDavCompletionHandlerBase.java | 28 +++-- .../asynchttpclient/async/PostWithQSTest.java | 8 +- .../providers/grizzly/EventHandler.java | 16 ++- .../grizzly/GrizzlyAsyncHttpProvider.java | 20 +--- .../grizzly/GrizzlyResponseBodyPart.java | 4 +- .../grizzly/GrizzlyResponseHeaders.java | 8 +- .../grizzly/GrizzlyResponseStatus.java | 24 ++-- .../netty/NettyAsyncHttpProvider.java | 10 -- .../providers/netty/handler/HttpProtocol.java | 2 +- .../netty/handler/WebSocketProtocol.java | 4 +- .../netty/response/ResponseBodyPart.java | 2 - .../netty/response/ResponseHeaders.java | 3 +- .../netty/response/ResponseStatus.java | 43 +++---- .../netty/NettyAsyncResponseTest.java | 6 +- 26 files changed, 214 insertions(+), 306 deletions(-) delete mode 100644 api/src/main/java/org/asynchttpclient/HttpContent.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java index da96a0497e..c8f910b8fb 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java @@ -17,7 +17,6 @@ import java.io.Closeable; import java.io.IOException; -import java.util.List; /** * Interface to be used when implementing custom asynchronous I/O HTTP client. @@ -33,22 +32,10 @@ public interface AsyncHttpProvider extends Closeable { * @return a {@link ListenableFuture} of Type T. * @throws IOException */ - public ListenableFuture execute(Request request, AsyncHandler handler) throws IOException; + ListenableFuture execute(Request request, AsyncHandler handler) throws IOException; /** * Close the current underlying TCP/HTTP connection. */ - public void close(); - - /** - * Prepare a {@link Response} - * - * @param status {@link HttpResponseStatus} - * @param headers {@link HttpResponseHeaders} - * @param bodyParts list of {@link HttpResponseBodyPart} - * @return a {@link Response} - */ - public Response prepareResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts); + void close(); } diff --git a/api/src/main/java/org/asynchttpclient/HttpContent.java b/api/src/main/java/org/asynchttpclient/HttpContent.java deleted file mode 100644 index 219e2411cc..0000000000 --- a/api/src/main/java/org/asynchttpclient/HttpContent.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2010 Ning, Inc. - * - * Ning 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. - */ -package org.asynchttpclient; - -import java.net.URI; - -/** - * Base class for callback class used by {@link AsyncHandler} - */ -public class HttpContent { - protected final AsyncHttpProvider provider; - protected final URI uri; - - protected HttpContent(URI url, AsyncHttpProvider provider) { - this.provider = provider; - this.uri = url; - } - - /** - * Return the current {@link AsyncHttpProvider} - * - * @return the current {@link AsyncHttpProvider} - */ - public final AsyncHttpProvider provider() { - return provider; - } - - /** - * Return the request {@link URI} - * - * @return the request {@link URI} - */ - public final URI getUrl() { - return uri; - } -} diff --git a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java index e7f350e439..42bb8c8158 100644 --- a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java +++ b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java @@ -18,17 +18,12 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; import java.nio.ByteBuffer; /** * A callback class used when an HTTP response body is received. */ -public abstract class HttpResponseBodyPart extends HttpContent { - - public HttpResponseBodyPart(URI uri, AsyncHttpProvider provider) { - super(uri, provider); - } +public abstract class HttpResponseBodyPart { /** * Return length of this part in bytes. diff --git a/api/src/main/java/org/asynchttpclient/HttpResponseHeaders.java b/api/src/main/java/org/asynchttpclient/HttpResponseHeaders.java index 54c894f712..5ecc6898c3 100644 --- a/api/src/main/java/org/asynchttpclient/HttpResponseHeaders.java +++ b/api/src/main/java/org/asynchttpclient/HttpResponseHeaders.java @@ -15,22 +15,19 @@ */ package org.asynchttpclient; -import java.net.URI; /** * A class that represent the HTTP headers. */ -public abstract class HttpResponseHeaders extends HttpContent { +public abstract class HttpResponseHeaders { private final boolean traillingHeaders; - public HttpResponseHeaders(URI uri, AsyncHttpProvider provider) { - super(uri, provider); + public HttpResponseHeaders() { this.traillingHeaders = false; } - public HttpResponseHeaders(URI uri, AsyncHttpProvider provider, boolean traillingHeaders) { - super(uri, provider); + public HttpResponseHeaders(boolean traillingHeaders) { this.traillingHeaders = traillingHeaders; } diff --git a/api/src/main/java/org/asynchttpclient/HttpResponseStatus.java b/api/src/main/java/org/asynchttpclient/HttpResponseStatus.java index 3581e46582..b2e5b0d7ab 100644 --- a/api/src/main/java/org/asynchttpclient/HttpResponseStatus.java +++ b/api/src/main/java/org/asynchttpclient/HttpResponseStatus.java @@ -17,55 +17,79 @@ package org.asynchttpclient; import java.net.URI; +import java.util.List; /** * A class that represent the HTTP response' status line (code + text) */ -public abstract class HttpResponseStatus extends HttpContent { +public abstract class HttpResponseStatus { - public HttpResponseStatus(URI uri, AsyncHttpProvider provider) { - super(uri, provider); + private final URI uri; + protected final AsyncHttpClientConfig config; + + public HttpResponseStatus(URI uri, AsyncHttpClientConfig config) { + this.uri = uri; + this.config = config; } /** - * Return the response status code + * Return the request {@link URI} + * + * @return the request {@link URI} + */ + public final URI getUri() { + return uri; + } + + /** + * Prepare a {@link Response} * + * @param headers {@link HttpResponseHeaders} + * @param bodyParts list of {@link HttpResponseBodyPart} + * @param config the client config + * @return a {@link Response} + */ + public abstract Response prepareResponse(HttpResponseHeaders headers, List bodyParts); + + /** + * Return the response status code + * * @return the response status code */ - abstract public int getStatusCode(); + public abstract int getStatusCode(); /** * Return the response status text - * + * * @return the response status text */ - abstract public String getStatusText(); + public abstract String getStatusText(); /** * Protocol name from status line. - * + * * @return Protocol name. */ - abstract public String getProtocolName(); + public abstract String getProtocolName(); /** * Protocol major version. - * + * * @return Major version. */ - abstract public int getProtocolMajorVersion(); + public abstract int getProtocolMajorVersion(); /** * Protocol minor version. - * + * * @return Minor version. */ - abstract public int getProtocolMinorVersion(); + public abstract int getProtocolMinorVersion(); /** * Full protocol name + version - * + * * @return protocol name + version */ - abstract public String getProtocolText(); + public abstract String getProtocolText(); } diff --git a/api/src/main/java/org/asynchttpclient/Response.java b/api/src/main/java/org/asynchttpclient/Response.java index 3db376606d..e8598013f4 100644 --- a/api/src/main/java/org/asynchttpclient/Response.java +++ b/api/src/main/java/org/asynchttpclient/Response.java @@ -31,50 +31,50 @@ public interface Response { /** * Returns the status code for the request. - * + * * @return The status code */ int getStatusCode(); /** * Returns the status text for the request. - * + * * @return The status text */ String getStatusText(); /** * Return the entire response body as a byte[]. - * + * * @return the entire response body as a byte[]. * @throws IOException */ byte[] getResponseBodyAsBytes() throws IOException; - + /** * Return the entire response body as a ByteBuffer. - * + * * @return the entire response body as a ByteBuffer. * @throws IOException */ ByteBuffer getResponseBodyAsByteBuffer() throws IOException; /** - * Returns an input stream for the response body. Note that you should not try to get this more than once, - * and that you should not close the stream. - * + * Returns an input stream for the response body. Note that you should not try to get this more than once, and that you should not close the stream. + * * @return The input stream * @throws java.io.IOException */ InputStream getResponseBodyAsStream() throws IOException; /** - * Returns the first maxLength bytes of the response body as a string. Note that this does not check - * whether the content type is actually a textual one, but it will use the charset if present in the content - * type header. - * - * @param maxLength The maximum number of bytes to read - * @param charset the charset to use when decoding the stream + * Returns the first maxLength bytes of the response body as a string. Note that this does not check whether the content type is actually a textual one, but it will use the + * charset if present in the content type header. + * + * @param maxLength + * The maximum number of bytes to read + * @param charset + * the charset to use when decoding the stream * @return The response body * @throws java.io.IOException */ @@ -82,19 +82,20 @@ public interface Response { /** * Return the entire response body as a String. - * - * @param charset the charset to use when decoding the stream + * + * @param charset + * the charset to use when decoding the stream * @return the entire response body as a String. * @throws IOException */ String getResponseBody(String charset) throws IOException; /** - * Returns the first maxLength bytes of the response body as a string. Note that this does not check - * whether the content type is actually a textual one, but it will use the charset if present in the content - * type header. - * - * @param maxLength The maximum number of bytes to read + * Returns the first maxLength bytes of the response body as a string. Note that this does not check whether the content type is actually a textual one, but it will use the + * charset if present in the content type header. + * + * @param maxLength + * The maximum number of bytes to read * @return The response body * @throws java.io.IOException */ @@ -102,16 +103,15 @@ public interface Response { /** * Return the entire response body as a String. - * + * * @return the entire response body as a String. * @throws IOException */ String getResponseBody() throws IOException; /** - * Return the request {@link URI}. Note that if the request got redirected, the value of the {@link URI} will be - * the last valid redirect url. - * + * Return the request {@link URI}. Note that if the request got redirected, the value of the {@link URI} will be the last valid redirect url. + * * @return the request {@link URI}. * @throws MalformedURLException */ @@ -119,21 +119,21 @@ public interface Response { /** * Return the content-type header value. - * + * * @return the content-type header value. */ String getContentType(); /** * Return the response header - * + * * @return the response header */ String getHeader(String name); /** * Return a {@link List} of the response header value. - * + * * @return the response header */ List getHeaders(String name); @@ -142,14 +142,14 @@ public interface Response { /** * Return true if the response redirects to another object. - * + * * @return True if the response redirects to another object. */ boolean isRedirected(); /** * Subclasses SHOULD implement toString() in a way that identifies the request for logging. - * + * * @return The textual representation */ String toString(); @@ -161,66 +161,61 @@ public interface Response { /** * Return true if the response's status has been computed by an {@link AsyncHandler} - * + * * @return true if the response's status has been computed by an {@link AsyncHandler} */ boolean hasResponseStatus(); /** - * Return true if the response's headers has been computed by an {@link AsyncHandler} It will return false if the - * either {@link AsyncHandler#onStatusReceived(HttpResponseStatus)} - * or {@link AsyncHandler#onHeadersReceived(HttpResponseHeaders)} returned {@link AsyncHandler.STATE#ABORT} - * + * Return true if the response's headers has been computed by an {@link AsyncHandler} It will return false if the either + * {@link AsyncHandler#onStatusReceived(HttpResponseStatus)} or {@link AsyncHandler#onHeadersReceived(HttpResponseHeaders)} returned {@link AsyncHandler.STATE#ABORT} + * * @return true if the response's headers has been computed by an {@link AsyncHandler} */ boolean hasResponseHeaders(); /** - * Return true if the response's body has been computed by an {@link AsyncHandler}. It will return false if the - * either {@link AsyncHandler#onStatusReceived(HttpResponseStatus)} + * Return true if the response's body has been computed by an {@link AsyncHandler}. It will return false if the either {@link AsyncHandler#onStatusReceived(HttpResponseStatus)} * or {@link AsyncHandler#onHeadersReceived(HttpResponseHeaders)} returned {@link AsyncHandler.STATE#ABORT} - * + * * @return true if the response's body has been computed by an {@link AsyncHandler} */ boolean hasResponseBody(); public static class ResponseBuilder { - private final List bodies = - Collections.synchronizedList(new ArrayList()); + private final List bodyParts = Collections.synchronizedList(new ArrayList()); private HttpResponseStatus status; private HttpResponseHeaders headers; - /** - * Accumulate {@link HttpContent} in order to build a {@link Response} - * - * @param httpContent {@link HttpContent} - * @return this - */ - public ResponseBuilder accumulate(HttpContent httpContent) { - if (httpContent instanceof HttpResponseStatus) { - status = (HttpResponseStatus) httpContent; - } else if (httpContent instanceof HttpResponseHeaders) { - headers = (HttpResponseHeaders) httpContent; - } else if (httpContent instanceof HttpResponseBodyPart) { - bodies.add((HttpResponseBodyPart) httpContent); - } + public ResponseBuilder accumulate(HttpResponseStatus status) { + this.status = status; + return this; + } + + public ResponseBuilder accumulate(HttpResponseHeaders headers) { + this.headers = headers; + return this; + } + + public ResponseBuilder accumulate(HttpResponseBodyPart bodyPart) { + bodyParts.add(bodyPart); return this; } /** * Build a {@link Response} instance - * + * * @return a {@link Response} instance */ public Response build() { - return status == null ? null : status.provider().prepareResponse(status, headers, bodies); + return status == null ? null : status.prepareResponse(headers, bodyParts); } /** * Reset the internal state of this builder. */ public void reset() { - bodies.clear(); + bodyParts.clear(); status = null; headers = null; } diff --git a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java index 9718c3302c..b7f4dfd410 100644 --- a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java +++ b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java @@ -47,7 +47,7 @@ public final String getStatusText() { /* @Override */ public final URI getUri() { - return status.getUrl(); + return status.getUri(); } /* @Override */ diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index 9268f67cc9..061dcd191e 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -12,43 +12,9 @@ */ package org.asynchttpclient.providers.jdk; -import static org.asynchttpclient.util.MiscUtil.isNonEmpty; +import static org.asynchttpclient.util.AsyncHttpProviderUtils.*; +import static org.asynchttpclient.util.MiscUtil.*; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.AsyncHttpProviderConfig; -import org.asynchttpclient.Body; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.MaxRedirectException; -import org.asynchttpclient.ProgressAsyncHandler; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Realm; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.ResponseFilter; -import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.multipart.MultipartRequestEntity; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.util.AuthenticatorUtils; -import org.asynchttpclient.util.ProxyUtils; -import org.asynchttpclient.util.SslUtils; -import org.asynchttpclient.util.UTF8UrlEncoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.naming.AuthenticationException; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLHandshakeException; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -78,7 +44,37 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.zip.GZIPInputStream; -import static org.asynchttpclient.util.AsyncHttpProviderUtils.DEFAULT_CHARSET; +import javax.naming.AuthenticationException; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLHandshakeException; + +import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.AsyncHttpProvider; +import org.asynchttpclient.AsyncHttpProviderConfig; +import org.asynchttpclient.Body; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; +import org.asynchttpclient.ListenableFuture; +import org.asynchttpclient.MaxRedirectException; +import org.asynchttpclient.ProgressAsyncHandler; +import org.asynchttpclient.ProxyServer; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Request; +import org.asynchttpclient.RequestBuilder; +import org.asynchttpclient.filter.FilterContext; +import org.asynchttpclient.filter.FilterException; +import org.asynchttpclient.filter.IOExceptionFilter; +import org.asynchttpclient.filter.ResponseFilter; +import org.asynchttpclient.listener.TransferCompletionHandler; +import org.asynchttpclient.multipart.MultipartRequestEntity; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.asynchttpclient.util.AuthenticatorUtils; +import org.asynchttpclient.util.ProxyUtils; +import org.asynchttpclient.util.SslUtils; +import org.asynchttpclient.util.UTF8UrlEncoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class JDKAsyncHttpProvider implements AsyncHttpProvider { private final static Logger logger = LoggerFactory.getLogger(JDKAsyncHttpProvider.class); @@ -208,10 +204,6 @@ public void close() { } } - public Response prepareResponse(HttpResponseStatus status, HttpResponseHeaders headers, List bodyParts) { - return new JDKResponse(status, headers, bodyParts); - } - private final class AsyncHttpUrlConnection implements Callable { private HttpURLConnection urlConnection; @@ -254,7 +246,7 @@ public T call() throws Exception { logger.debug("\n\nRequest {}\n\nResponse {}\n", request, statusCode); - ResponseStatus status = new ResponseStatus(uri, urlConnection, JDKAsyncHttpProvider.this); + ResponseStatus status = new ResponseStatus(uri, urlConnection, config); FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(asyncHandler).request(request).responseStatus(status).build(); for (ResponseFilter asyncFilter : config.getResponseFilters()) { fc = asyncFilter.filter(fc); diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java index 3081baee6f..b80ced8345 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java @@ -32,7 +32,6 @@ public class ResponseBodyPart extends HttpResponseBodyPart { private boolean closeConnection; public ResponseBodyPart(URI uri, byte[] chunk, AsyncHttpProvider provider, boolean last) { - super(uri, provider); this.chunk = chunk; isLast = last; } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java index 1a07b53c0e..ed71a96aa7 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java @@ -30,7 +30,6 @@ public class ResponseHeaders extends HttpResponseHeaders { private final FluentCaseInsensitiveStringsMap headers; public ResponseHeaders(URI uri, HttpURLConnection urlConnection, AsyncHttpProvider provider) { - super(uri, provider, false); this.urlConnection = urlConnection; headers = computerHeaders(); } diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java index d88d211683..b5cbc7094a 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java @@ -12,12 +12,16 @@ */ package org.asynchttpclient.providers.jdk; -import org.asynchttpclient.AsyncHttpProvider; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Response; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URI; +import java.util.List; /** * A class that represent the HTTP response' status line (code + text) @@ -26,10 +30,15 @@ public class ResponseStatus extends HttpResponseStatus { private final HttpURLConnection urlConnection; - public ResponseStatus(URI uri, HttpURLConnection urlConnection, AsyncHttpProvider provider) { - super(uri, provider); + public ResponseStatus(URI uri, HttpURLConnection urlConnection, AsyncHttpClientConfig config) { + super(uri, config); this.urlConnection = urlConnection; } + + @Override + public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { + return new JDKResponse(this, headers, bodyParts); + } /** * Return the response status code diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java index 6991d05383..297ed0a0f4 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java @@ -106,7 +106,7 @@ public ResumableAsyncHandler(ResumableProcessor resumableProcessor, boolean accu public AsyncHandler.STATE onStatusReceived(final HttpResponseStatus status) throws Exception { responseBuilder.accumulate(status); if (status.getStatusCode() == 200 || status.getStatusCode() == 206) { - url = status.getUrl().toURL().toString(); + url = status.getUri().toURL().toString(); } else { return AsyncHandler.STATE.ABORT; } diff --git a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java index 74ac5ab684..6781d561cd 100644 --- a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java +++ b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java @@ -29,6 +29,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; @@ -81,12 +82,12 @@ public final STATE onHeadersReceived(final HttpResponseHeaders headers) throws E /* @Override */ public final T onCompleted() throws Exception { if (status != null) { - Response response = status.provider().prepareResponse(status, headers, bodies); + Response response = status.prepareResponse(headers, bodies); Document document = null; if (status.getStatusCode() == 207) { document = readXMLResponse(response.getResponseBodyAsStream()); } - return onCompleted(new WebDavResponse(status.provider().prepareResponse(status, headers, bodies), document)); + return onCompleted(new WebDavResponse(status.prepareResponse(headers, bodies), document)); } else { throw new IllegalStateException("Status is null"); } @@ -111,47 +112,52 @@ public void onThrowable(Throwable t) { private class HttpStatusWrapper extends HttpResponseStatus { - private final HttpResponseStatus wrapper; + private final HttpResponseStatus wrapped; private final String statusText; private final int statusCode; public HttpStatusWrapper(HttpResponseStatus wrapper, String statusText, int statusCode) { - super(wrapper.getUrl(), wrapper.provider()); - this.wrapper = wrapper; + super(wrapper.getUri(), null); + this.wrapped = wrapper; this.statusText = statusText; this.statusCode = statusCode; } + + @Override + public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { + return wrapped.prepareResponse(headers, bodyParts); + } @Override public int getStatusCode() { - return (statusText == null ? wrapper.getStatusCode() : statusCode); + return (statusText == null ? wrapped.getStatusCode() : statusCode); } @Override public String getStatusText() { - return (statusText == null ? wrapper.getStatusText() : statusText); + return (statusText == null ? wrapped.getStatusText() : statusText); } @Override public String getProtocolName() { - return wrapper.getProtocolName(); + return wrapped.getProtocolName(); } @Override public int getProtocolMajorVersion() { - return wrapper.getProtocolMajorVersion(); + return wrapped.getProtocolMajorVersion(); } @Override public int getProtocolMinorVersion() { - return wrapper.getProtocolMinorVersion(); + return wrapped.getProtocolMinorVersion(); } @Override public String getProtocolText() { - return wrapper.getStatusText(); + return wrapped.getStatusText(); } } diff --git a/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java b/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java index 442f389082..26d85587ac 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java @@ -91,8 +91,8 @@ public void postWithNulParamQS() throws IOException, ExecutionException, Timeout /* @Override */ public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { - if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=")) { - throw new IOException(status.getUrl().toURL().toString()); + if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=")) { + throw new IOException(status.getUri().toURL().toString()); } return super.onStatusReceived(status); } @@ -114,7 +114,7 @@ public void postWithNulParamsQS() throws IOException, ExecutionException, Timeou /* @Override */ public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { - if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c&d=e")) { + if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c&d=e")) { throw new IOException("failed to parse the query properly"); } return super.onStatusReceived(status); @@ -137,7 +137,7 @@ public void postWithEmptyParamsQS() throws IOException, ExecutionException, Time /* @Override */ public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { - if (!status.getUrl().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c=&d=e")) { + if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c=&d=e")) { throw new IOException("failed to parse the query properly"); } return super.onStatusReceived(status); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index c0e28d05c1..732697e3b5 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -14,6 +14,7 @@ package org.asynchttpclient.providers.grizzly; import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProviderConfig; import org.asynchttpclient.Cookie; import org.asynchttpclient.MaxRedirectException; @@ -74,15 +75,15 @@ public final class EventHandler { } - private final GrizzlyAsyncHttpProvider provider; + private final AsyncHttpClientConfig config; GrizzlyAsyncHttpProvider.Cleanup cleanup; // -------------------------------------------------------- Constructors - EventHandler(final GrizzlyAsyncHttpProvider provider) { - this.provider = provider; + EventHandler(final AsyncHttpClientConfig config) { + this.config = config; } @@ -107,8 +108,7 @@ public void onHttpContentParsed(HttpContent content, context.setCurrentState(handler.onBodyPartReceived( new GrizzlyResponseBodyPart(content, context.getRequest().getURI(), - ctx.getConnection(), - provider))); + ctx.getConnection()))); } catch (Exception e) { handler.onThrowable(e); } @@ -188,7 +188,7 @@ public void onInitialLineParsed(HttpHeader httpHeader, final GrizzlyResponseStatus responseStatus = new GrizzlyResponseStatus((HttpResponsePacket) httpHeader, context.getRequest().getURI(), - provider); + config); context.setResponseStatus(responseStatus); if (context.getStatusHandler() != null) { return; @@ -238,9 +238,7 @@ public void onHttpHeadersParsed(HttpHeader httpHeader, final AsyncHandler handler = context.getHandler(); final GrizzlyResponseHeaders responseHeaders = - new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader, - context.getRequest().getURI(), - provider); + new GrizzlyResponseHeaders((HttpResponsePacket) httpHeader); if (context.getProvider().getClientConfig().hasResponseFilters()) { final List filters = context.getProvider() .getClientConfig().getResponseFilters(); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index a375d815de..9ef48ad96b 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -189,22 +189,6 @@ public void close() { } - - /** - * {@inheritDoc} - */ - public Response prepareResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts) { - - return new GrizzlyResponse(status, - headers, - bodyParts, - clientConfig.isRfc6265CookieEncoding()); - - } - - // ---------------------------------------------------------- Public Methods @@ -321,7 +305,7 @@ public void onTimeout(Connection connection) { } final AsyncHttpClientEventFilter eventFilter; - final EventHandler handler = new EventHandler(this); + final EventHandler handler = new EventHandler(clientConfig); if (providerConfig != null) { eventFilter = new AsyncHttpClientEventFilter(handler, @@ -434,7 +418,7 @@ private FilterChainBuilder createSpdyFilterChain(final FilterChainBuilder fcb, spdyFcb.set(idx, new SpdyFramingFilter()); final SpdyMode spdyMode = ((npnEnabled) ? SpdyMode.NPN : SpdyMode.PLAIN); AsyncSpdyClientEventFilter spdyFilter = - new AsyncSpdyClientEventFilter(new EventHandler(this), + new AsyncSpdyClientEventFilter(new EventHandler(clientConfig), spdyMode, clientConfig.executorService()); spdyFilter.setInitialWindowSize(clientConfig.getSpdyInitialWindowSize()); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java index e0a2931ac9..4f2236e321 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java @@ -48,9 +48,7 @@ class GrizzlyResponseBodyPart extends HttpResponseBodyPart { public GrizzlyResponseBodyPart(final HttpContent content, final URI uri, - final Connection connection, - final AsyncHttpProvider provider) { - super(uri, provider); + final Connection connection) { this.content = content; this.connection = connection; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java index 588c33ca50..babd1af641 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseHeaders.java @@ -13,15 +13,12 @@ package org.asynchttpclient.providers.grizzly; -import org.asynchttpclient.AsyncHttpProvider; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseHeaders; import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.util.MimeHeaders; -import java.net.URI; - /** * {@link HttpResponseHeaders} implementation using the Grizzly 2.0 HTTP client @@ -39,11 +36,8 @@ class GrizzlyResponseHeaders extends HttpResponseHeaders { // ------------------------------------------------------------ Constructors - public GrizzlyResponseHeaders(final HttpResponsePacket response, - final URI uri, - final AsyncHttpProvider provider) { + public GrizzlyResponseHeaders(final HttpResponsePacket response) { - super(uri, provider); grizzlyHeaders = new MimeHeaders(); grizzlyHeaders.copyFrom(response.getHeaders()); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java index e4e74e3c91..9bafb37be4 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java @@ -13,13 +13,16 @@ package org.asynchttpclient.providers.grizzly; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseStatus; +import java.net.URI; +import java.util.List; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Response; import org.glassfish.grizzly.http.HttpResponsePacket; -import java.net.URI; - /** * {@link HttpResponseStatus} implementation using the Grizzly 2.0 HTTP client * codec. @@ -43,9 +46,9 @@ public class GrizzlyResponseStatus extends HttpResponseStatus { public GrizzlyResponseStatus(final HttpResponsePacket response, final URI uri, - final AsyncHttpProvider provider) { + AsyncHttpClientConfig config) { - super(uri, provider); + super(uri, config); statusCode = response.getStatus(); statusText = response.getReasonPhrase(); majorVersion = response.getProtocol().getMajorVersion(); @@ -57,7 +60,14 @@ public GrizzlyResponseStatus(final HttpResponsePacket response, // ----------------------------------------- Methods from HttpResponseStatus - + @Override + public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { + return new GrizzlyResponse(this, + headers, + bodyParts, + config.isRfc6265CookieEncoding()); + }; + /** * {@inheritDoc} */ diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index 60656ffad2..f8348abde6 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -16,18 +16,13 @@ package org.asynchttpclient.providers.netty; import java.io.IOException; -import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.Request; -import org.asynchttpclient.Response; import org.asynchttpclient.providers.netty.channel.Channels; import org.asynchttpclient.providers.netty.handler.NettyChannelHandler; import org.asynchttpclient.providers.netty.request.NettyRequestSender; @@ -75,11 +70,6 @@ public void close() { } } - @Override - public Response prepareResponse(final HttpResponseStatus status, final HttpResponseHeaders headers, final List bodyParts) { - throw new UnsupportedOperationException("Mocked, should be refactored"); - } - @Override public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { return requestSender.sendRequest(request, asyncHandler, null, asyncHttpProviderConfig.isAsyncConnect(), false); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java index a5d689ac91..0b871daf61 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -242,7 +242,7 @@ private boolean handleResponseAndExit(final ChannelHandlerContext ctx, final Net ProxyServer proxyServer, HttpResponse response) throws Exception { Request request = future.getRequest(); int statusCode = response.getStatus().code(); - HttpResponseStatus status = new ResponseStatus(future.getURI(), response); + HttpResponseStatus status = new ResponseStatus(future.getURI(), response, config); HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); final RequestBuilder builder = new RequestBuilder(future.getRequest()); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java index eee8b91515..d29c3a85b0 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java @@ -78,7 +78,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object if (e instanceof HttpResponse) { HttpResponse response = (HttpResponse) e; - HttpResponseStatus s = new ResponseStatus(future.getURI(), response); + HttpResponseStatus s = new ResponseStatus(future.getURI(), response, config); HttpResponseHeaders responseHeaders = new ResponseHeaders(future.getURI(), response.headers()); // FIXME there's a method for that IIRC @@ -116,7 +116,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object boolean validConnection = c == null ? false : c.equalsIgnoreCase(HttpHeaders.Values.UPGRADE); - s = new ResponseStatus(future.getURI(), response); + s = new ResponseStatus(future.getURI(), response, config); final boolean statusReceived = h.onStatusReceived(s) == STATE.UPGRADE; final boolean headerOK = h.onHeadersReceived(responseHeaders) == STATE.CONTINUE; diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java index 86289d146d..e50d36faa8 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java @@ -36,9 +36,7 @@ public class ResponseBodyPart extends HttpResponseBodyPart { private final boolean last; private boolean closeConnection = false; - // FIXME unused AsyncHttpProvider provider public ResponseBodyPart(URI uri, ByteBuf buf, boolean last) { - super(uri, null); bytes = ByteBufUtil.byteBuf2bytes(buf); this.last = last; } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java index a024e8a624..c48aad3394 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseHeaders.java @@ -37,9 +37,8 @@ public ResponseHeaders(URI uri, HttpHeaders responseHeaders) { this(uri, responseHeaders, null); } - // FIXME unused AsyncHttpProvider provider public ResponseHeaders(URI uri,HttpHeaders responseHeaders, HttpHeaders traillingHeaders) { - super(uri, null, traillingHeaders != null); + super(traillingHeaders != null); this.responseHeaders = responseHeaders; this.trailingHeaders = traillingHeaders; headers = computerHeaders(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java index 45c7274245..79acf80565 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseStatus.java @@ -16,49 +16,33 @@ */ package org.asynchttpclient.providers.netty.response; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.Request; -import org.asynchttpclient.Response; - import io.netty.handler.codec.http.HttpResponse; -import java.io.IOException; import java.net.URI; import java.util.List; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.HttpResponseBodyPart; +import org.asynchttpclient.HttpResponseHeaders; +import org.asynchttpclient.HttpResponseStatus; +import org.asynchttpclient.Response; + /** * A class that represent the HTTP response' status line (code + text) */ public class ResponseStatus extends HttpResponseStatus { - private static final AsyncHttpProvider fakeProvider = new AsyncHttpProvider() { - public ListenableFuture execute(Request request, AsyncHandler handler) throws IOException { - throw new UnsupportedOperationException("Mocked, should be refactored"); - } - - public void close() { - throw new UnsupportedOperationException("Mocked, should be refactored"); - } - - public Response prepareResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts) { - return new NettyResponse(status, headers, bodyParts); - } - }; - private final HttpResponse response; - // FIXME ResponseStatus should have an abstract prepareResponse(headers, bodyParts) method instead of being passed the provider! - public ResponseStatus(URI uri, HttpResponse response) { - super(uri, fakeProvider); + public ResponseStatus(URI uri, HttpResponse response, AsyncHttpClientConfig config) { + super(uri, config); this.response = response; } + + @Override + public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { + return new NettyResponse(this, headers, bodyParts); + } /** * Return the response status code @@ -97,5 +81,4 @@ public int getProtocolMinorVersion() { public String getProtocolText() { return response.getProtocolVersion().text(); } - } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java index e679303540..e20854bba7 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyAsyncResponseTest.java @@ -43,7 +43,7 @@ public void testCookieParseExpires() { final String cookieDef = String.format("efmembercheck=true; expires=%s; path=/; domain=.eclipse.org", sdf.format(date)); NettyResponse - response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { + response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders() { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -60,7 +60,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseMaxAge() { final String cookieDef = "efmembercheck=true; max-age=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders() { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); @@ -76,7 +76,7 @@ public FluentCaseInsensitiveStringsMap getHeaders() { @Test(groups = "standalone") public void testCookieParseWeirdExpiresValue() { final String cookieDef = "efmembercheck=true; expires=60; path=/; domain=.eclipse.org"; - NettyResponse response = new NettyResponse(new ResponseStatus(null, null), new HttpResponseHeaders(null, null, false) { + NettyResponse response = new NettyResponse(new ResponseStatus(null, null, null), new HttpResponseHeaders() { @Override public FluentCaseInsensitiveStringsMap getHeaders() { return new FluentCaseInsensitiveStringsMap().add("Set-Cookie", cookieDef); From 23a101121459dbdcf641f9a05ec6a8c64cde128b Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 13:47:23 +0200 Subject: [PATCH 0140/2389] Minor clean up --- .../BodyDeferringAsyncHandler.java | 2 -- .../providers/jdk/JDKAsyncHttpProvider.java | 32 +++++++++++++++++-- .../PropertiesBasedResumableProcessor.java | 8 +++-- .../resumable/ResumableIOExceptionFilter.java | 8 ++--- .../util/AsyncHttpProviderUtils.java | 30 ----------------- .../asynchttpclient/async/RemoteSiteTest.java | 10 ++---- .../netty/handler/WebSocketProtocol.java | 2 +- 7 files changed, 43 insertions(+), 49 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/BodyDeferringAsyncHandler.java b/api/src/main/java/org/asynchttpclient/BodyDeferringAsyncHandler.java index 1bf49bbb03..3114dcf2e1 100644 --- a/api/src/main/java/org/asynchttpclient/BodyDeferringAsyncHandler.java +++ b/api/src/main/java/org/asynchttpclient/BodyDeferringAsyncHandler.java @@ -12,8 +12,6 @@ */ package org.asynchttpclient; -import org.asynchttpclient.Response.ResponseBuilder; - import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index 061dcd191e..7dfefa7af6 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -322,7 +322,7 @@ public T call() throws Exception { InputStream stream = is; if (bufferResponseInMemory || byteToRead <= 0) { int[] lengthWrapper = new int[1]; - byte[] bytes = AsyncHttpProviderUtils.readFully(is, lengthWrapper); + byte[] bytes = readFully(is, lengthWrapper); stream = new ByteArrayInputStream(bytes, 0, lengthWrapper[0]); byteToRead = lengthWrapper[0]; } @@ -410,6 +410,34 @@ public T call() throws Exception { } return null; } + + // FIXME Streams should be streamed, not turned into byte arrays + private final byte[] readFully(InputStream in, int[] lengthWrapper) throws IOException { + // just in case available() returns bogus (or -1), allocate non-trivial chunk + byte[] b = new byte[Math.max(512, in.available())]; + int offset = 0; + while (true) { + int left = b.length - offset; + int count = in.read(b, offset, left); + if (count < 0) { // EOF + break; + } + offset += count; + if (count == left) { // full buffer, need to expand + b = doubleUp(b); + } + } + // wish Java had Tuple return type... + lengthWrapper[0] = offset; + return b; + } + + private final byte[] doubleUp(byte[] b) { + int len = b.length; + byte[] b2 = new byte[len + len]; + System.arraycopy(b, 0, b2, 0, len); + return b2; + } private FilterContext handleIoException(FilterContext fc) throws FilterException { for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { @@ -571,7 +599,7 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request urlConnection.getOutputStream().write(b); } else if (request.getStreamData() != null) { int[] lengthWrapper = new int[1]; - cachedBytes = AsyncHttpProviderUtils.readFully(request.getStreamData(), lengthWrapper); + cachedBytes = readFully(request.getStreamData(), lengthWrapper); cachedBytesLenght = lengthWrapper[0]; urlConnection.setRequestProperty("Content-Length", String.valueOf(cachedBytesLenght)); urlConnection.setFixedLengthStreamingMode(cachedBytesLenght); diff --git a/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java b/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java index 85ebb2bde6..980869a5ad 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java +++ b/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java @@ -96,10 +96,11 @@ private static String append(Map.Entry e) { /** * {@inheritDoc} */ - /* @Override */ + @Override public Map load() { + Scanner scan = null; try { - Scanner scan = new Scanner(new File(TMP, storeName), "UTF-8"); + scan = new Scanner(new File(TMP, storeName), "UTF-8"); scan.useDelimiter("[=\n]"); String key; @@ -115,6 +116,9 @@ public Map load() { } catch (Throwable ex) { // Survive any exceptions log.warn(ex.getMessage(), ex); + } finally { + if (scan != null) + scan.close(); } return properties; } diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java index 456360ae15..87868e35de 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableIOExceptionFilter.java @@ -18,18 +18,16 @@ import org.asynchttpclient.filter.IOExceptionFilter; /** - * Simple {@link org.asynchttpclient.filter.IOExceptionFilter} that replay the current {@link org.asynchttpclient.Request} using - * a {@link ResumableAsyncHandler} + * Simple {@link org.asynchttpclient.filter.IOExceptionFilter} that replay the current {@link org.asynchttpclient.Request} using a {@link ResumableAsyncHandler} */ public class ResumableIOExceptionFilter implements IOExceptionFilter { - public FilterContext filter(FilterContext ctx) throws FilterException { + public FilterContext filter(FilterContext ctx) throws FilterException { if (ctx.getIOException() != null && ctx.getAsyncHandler() instanceof ResumableAsyncHandler) { Request request = ResumableAsyncHandler.class.cast(ctx.getAsyncHandler()).adjustRequestRange(ctx.getRequest()); - return new FilterContext.FilterContextBuilder(ctx).request(request).replayRequest(true).build(); + return new FilterContext.FilterContextBuilder(ctx).request(request).replayRequest(true).build(); } return ctx; } } - \ No newline at end of file diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index a98cd8a33b..500ed4a290 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -14,7 +14,6 @@ import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; import java.io.UnsupportedEncodingException; @@ -379,35 +378,6 @@ public final static MultipartRequestEntity createMultipartRequestEntity(List cookies) { StringBuilder sb = new StringBuilder(); diff --git a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java index a5025ffb17..e5b7c85d43 100644 --- a/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RemoteSiteTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.apache.commons.io.IOUtils; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; @@ -33,7 +34,6 @@ import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.Response; -import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.testng.annotations.Test; /** @@ -173,13 +173,9 @@ public void asyncFullBodyProperlyRead() throws Exception { Response r = client.prepareGet("http://www.cyberpresse.ca/").execute().get(); InputStream stream = r.getResponseBodyAsStream(); - // FIXME available is an ESTIMATE!!! - int available = stream.available(); - int[] lengthWrapper = new int[1]; - AsyncHttpProviderUtils.readFully(stream, lengthWrapper); - int byteToRead = lengthWrapper[0]; + int contentLength = Integer.valueOf(r.getHeader("Content-Length")); - assertEquals(available, byteToRead); + assertEquals(contentLength, IOUtils.toByteArray(stream).length); } finally { client.close(); } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java index d29c3a85b0..49bdadc313 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java @@ -184,7 +184,7 @@ public void onError(ChannelHandlerContext ctx, Throwable e) { return; } - NettyResponseFuture nettyResponse = (NettyResponseFuture) attribute; + NettyResponseFuture nettyResponse = (NettyResponseFuture) attribute; WebSocketUpgradeHandler h = WebSocketUpgradeHandler.class.cast(nettyResponse.getAsyncHandler()); NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted()); From 86605899a1a59a0d19b64feebe6bfdcdca72776e Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 14:26:23 +0200 Subject: [PATCH 0141/2389] Fix webdav test --- .../webdav/WebDavCompletionHandlerBase.java | 105 +++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java index 6781d561cd..1386adb160 100644 --- a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java +++ b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java @@ -15,6 +15,8 @@ import org.asynchttpclient.AsyncCompletionHandlerBase; import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.Cookie; +import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseBodyPart; import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; @@ -32,6 +34,9 @@ import java.io.IOException; import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -127,7 +132,105 @@ public HttpStatusWrapper(HttpResponseStatus wrapper, String statusText, int stat @Override public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { - return wrapped.prepareResponse(headers, bodyParts); + final Response wrappedResponse = wrapped.prepareResponse(headers, bodyParts); + + return new Response() { + + @Override + public int getStatusCode() { + return statusCode; + } + + @Override + public String getStatusText() { + return statusText; + } + + @Override + public byte[] getResponseBodyAsBytes() throws IOException { + return wrappedResponse.getResponseBodyAsBytes(); + } + + @Override + public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { + return wrappedResponse.getResponseBodyAsByteBuffer(); + } + + @Override + public InputStream getResponseBodyAsStream() throws IOException { + return wrappedResponse.getResponseBodyAsStream(); + } + + @Override + public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException { + return wrappedResponse.getResponseBodyExcerpt(maxLength, charset); + } + + @Override + public String getResponseBody(String charset) throws IOException { + return wrappedResponse.getResponseBody(charset); + } + + @Override + public String getResponseBodyExcerpt(int maxLength) throws IOException { + return wrappedResponse.getResponseBodyExcerpt(maxLength); + } + + @Override + public String getResponseBody() throws IOException { + return wrappedResponse.getResponseBody(); + } + + @Override + public URI getUri() throws MalformedURLException { + return wrappedResponse.getUri(); + } + + @Override + public String getContentType() { + return wrappedResponse.getContentType(); + } + + @Override + public String getHeader(String name) { + return wrappedResponse.getHeader(name); + } + + @Override + public List getHeaders(String name) { + return wrappedResponse.getHeaders(name); + } + + @Override + public FluentCaseInsensitiveStringsMap getHeaders() { + return wrappedResponse.getHeaders(); + } + + @Override + public boolean isRedirected() { + return wrappedResponse.isRedirected(); + } + + @Override + public List getCookies() { + return wrappedResponse.getCookies(); + } + + @Override + public boolean hasResponseStatus() { + return wrappedResponse.hasResponseStatus(); + } + + @Override + public boolean hasResponseHeaders() { + return wrappedResponse.hasResponseHeaders(); + } + + @Override + public boolean hasResponseBody() { + return wrappedResponse.hasResponseBody(); + } + }; } @Override From 41460f4f6f501b918c7f23ab57c3f30456582cb8 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 14:46:29 +0200 Subject: [PATCH 0142/2389] Removed deprecated APIs --- .../AsyncHttpClientConfig.java | 22 ------- .../java/org/asynchttpclient/ProxyServer.java | 12 ---- .../main/java/org/asynchttpclient/Realm.java | 22 ------- .../java/org/asynchttpclient/Request.java | 8 --- .../asynchttpclient/RequestBuilderBase.java | 61 +++++++++---------- .../SimpleAsyncHttpClient.java | 4 +- .../org/asynchttpclient/multipart/Part.java | 11 ---- .../providers/jdk/JDKAsyncHttpProvider.java | 2 +- 8 files changed, 33 insertions(+), 109 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 104137ea0b..3ce08af1ad 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -296,16 +296,6 @@ public boolean getAllowPoolingConnection() { return allowPoolingConnection; } - /** - * Is the {@link ConnectionsPool} support enabled. - * - * @return true if keep-alive is enabled - * @deprecated - Use {@link AsyncHttpClientConfig#getAllowPoolingConnection()} - */ - public boolean getKeepAlive() { - return allowPoolingConnection; - } - /** * Return the USER_AGENT header value * @@ -777,18 +767,6 @@ public Builder setAllowPoolingConnection(boolean allowPoolingConnection) { return this; } - /** - * Set true if connection can be pooled by a {@link ConnectionsPool}. Default is true. - * - * @param allowPoolingConnection true if connection can be pooled by a {@link ConnectionsPool} - * @return a {@link Builder} - * @deprecated - Use {@link AsyncHttpClientConfig.Builder#setAllowPoolingConnection(boolean)} - */ - public Builder setKeepAlive(boolean allowPoolingConnection) { - this.allowPoolingConnection = allowPoolingConnection; - return this; - } - /** * Set the{@link ScheduledExecutorService} used to expire idle connections. * diff --git a/api/src/main/java/org/asynchttpclient/ProxyServer.java b/api/src/main/java/org/asynchttpclient/ProxyServer.java index d7d841c3fc..9cd3ecc70a 100644 --- a/api/src/main/java/org/asynchttpclient/ProxyServer.java +++ b/api/src/main/java/org/asynchttpclient/ProxyServer.java @@ -57,18 +57,6 @@ public String toString() { private String encoding = "UTF-8"; private String ntlmDomain = System.getProperty("http.auth.ntlm.domain", ""); - private boolean isBasic = true; - - @Deprecated - public boolean isBasic() { - return isBasic; - } - - @Deprecated - public void setBasic(boolean isBasic) { - this.isBasic = isBasic; - } - public ProxyServer(final Protocol protocol, final String host, final int port, String principal, String password) { this.protocol = protocol; this.host = host; diff --git a/api/src/main/java/org/asynchttpclient/Realm.java b/api/src/main/java/org/asynchttpclient/Realm.java index de213f74c0..9c09faaedb 100644 --- a/api/src/main/java/org/asynchttpclient/Realm.java +++ b/api/src/main/java/org/asynchttpclient/Realm.java @@ -164,16 +164,6 @@ public boolean getUsePreemptiveAuth() { return usePreemptiveAuth; } - /** - * Return the NTLM domain to use. This value should map the JDK - * - * @return the NTLM domain - * @deprecated - use getNtlmDomain() - */ - public String getDomain() { - return domain; - } - /** * Return the NTLM domain to use. This value should map the JDK * @@ -280,17 +270,6 @@ public static class RealmBuilder { private String host = "localhost"; private boolean messageType2Received = false; - @Deprecated - public String getDomain() { - return domain; - } - - @Deprecated - public RealmBuilder setDomain(String domain) { - this.domain = domain; - return this; - } - public String getNtlmDomain() { return domain; } @@ -630,5 +609,4 @@ public Realm build() { opaque); } } - } diff --git a/api/src/main/java/org/asynchttpclient/Request.java b/api/src/main/java/org/asynchttpclient/Request.java index 2c68f6df5b..48cabc6a76 100644 --- a/api/src/main/java/org/asynchttpclient/Request.java +++ b/api/src/main/java/org/asynchttpclient/Request.java @@ -120,14 +120,6 @@ public interface Request { */ public BodyGenerator getBodyGenerator(); - /** - * Return the current size of the content-lenght header based on the body's size. - * - * @return the current size of the content-lenght header based on the body's size. - * @deprecated - */ - public long getLength(); - /** * Return the current size of the content-lenght header based on the body's size. * diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index c1bbc4b289..0a0001f8bc 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -98,7 +98,7 @@ public RequestImpl(Request prototype) { this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); - this.followRedirects = prototype.isRedirectOverrideSet()? prototype.isRedirectEnabled() : null; + this.followRedirects = prototype.isRedirectOverrideSet() ? prototype.isRedirectEnabled() : null; this.requestTimeoutInMs = prototype.getRequestTimeoutInMs(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); @@ -107,16 +107,17 @@ public RequestImpl(Request prototype) { } } - /* @Override */ - + @Override public String getMethod() { return method; } + @Override public InetAddress getInetAddress() { return address; } + @Override public InetAddress getLocalAddress() { return localAddress; } @@ -130,12 +131,12 @@ private String removeTrailingSlash(URI uri) { } } - /* @Override */ + @Override public String getUrl() { return removeTrailingSlash(getURI()); } - /* @Override */ + @Override public String getRawUrl() { return removeTrailingSlash(getRawURI()); } @@ -208,7 +209,7 @@ private URI toURI(boolean encode) { return URI.create(builder.toString()); } - /* @Override */ + @Override public FluentCaseInsensitiveStringsMap getHeaders() { if (headers == null) { headers = new FluentCaseInsensitiveStringsMap(); @@ -221,87 +222,85 @@ public boolean hasHeaders() { return headers != null && !headers.isEmpty(); } - /* @Override */ + @Override public Collection getCookies() { if (cookies == null) { - cookies = Collections.unmodifiableCollection(Collections.emptyList()); + cookies = Collections.unmodifiableCollection(Collections. emptyList()); } return cookies; } - /* @Override */ + @Override public byte[] getByteData() { return byteData; } - /* @Override */ + @Override public String getStringData() { return stringData; } - /* @Override */ + @Override public InputStream getStreamData() { return streamData; } - /* @Override */ + @Override public BodyGenerator getBodyGenerator() { return bodyGenerator; } - /* @Override */ - - /** - * @return - * @deprecated - */ - public long getLength() { - return length; - } - + @Override public long getContentLength() { return length; } - /* @Override */ + @Override public FluentStringsMap getParams() { return params; } - /* @Override */ + @Override public List getParts() { return parts; } - /* @Override */ + @Override public String getVirtualHost() { return virtualHost; } + @Override public FluentStringsMap getQueryParams() { return queryParams; } + @Override public ProxyServer getProxyServer() { return proxyServer; } + @Override public Realm getRealm() { return realm; } + @Override public File getFile() { return file; } + @Override public boolean isRedirectEnabled() { - return (followRedirects != null && followRedirects); + return followRedirects != null && followRedirects; } - public boolean isRedirectOverrideSet(){ + @Override + public boolean isRedirectOverrideSet() { return followRedirects != null; } + @Override public int getRequestTimeoutInMs() { return requestTimeoutInMs; } @@ -377,10 +376,10 @@ public T setUrl(String url) { } public T setInetAddress(InetAddress address) { - request.address = address; - return derived.cast(this); + request.address = address; + return derived.cast(this); } - + public T setLocalInetAddress(InetAddress address) { request.localAddress = address; return derived.cast(this); @@ -407,7 +406,7 @@ private URI buildURI(String url) { url = s + url.substring(uri.getScheme().length() + 1); return buildURI(url); } else { - throw new IllegalArgumentException("Invalid url " + uri.toString()); + throw new IllegalArgumentException("Invalid url " + uri.toString()); } } diff --git a/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java index e4cd81b893..8f38f7ef44 100644 --- a/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/SimpleAsyncHttpClient.java @@ -557,8 +557,8 @@ public Builder setRequestCompressionLevel(int requestCompressionLevel) { return this; } - public Builder setRealmDomain(String domain) { - realm().setDomain(domain); + public Builder setRealmNtlmDomain(String domain) { + realm().setNtlmDomain(domain); return this; } diff --git a/api/src/main/java/org/asynchttpclient/multipart/Part.java b/api/src/main/java/org/asynchttpclient/multipart/Part.java index 3d71bf5240..40d8b90382 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/Part.java +++ b/api/src/main/java/org/asynchttpclient/multipart/Part.java @@ -116,16 +116,6 @@ public abstract class Part implements org.asynchttpclient.Part { */ static final byte[] CONTENT_ID_BYTES = MultipartEncodingUtil.getAsciiBytes(CONTENT_ID); - /** - * Return the boundary string. - * - * @return the boundary string - * @deprecated uses a constant string. Rather use {@link #getPartBoundary} - */ - public static String getBoundary() { - return BOUNDARY; - } - /** * The ASCII bytes to use as the multipart boundary. */ @@ -165,7 +155,6 @@ public static String getBoundary() { * Gets the part boundary to be used. * * @return the part boundary as an array of bytes. - * @since 3.0 */ protected byte[] getPartBoundary() { if (boundaryBytes == null) { diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java index 7dfefa7af6..d6cec0a5b5 100644 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java @@ -544,7 +544,7 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request break; case NTLM: jdkNtlmDomain = System.getProperty(NTLM_DOMAIN); - System.setProperty(NTLM_DOMAIN, realm.getDomain()); + System.setProperty(NTLM_DOMAIN, realm.getNtlmDomain()); break; case NONE: break; From 20392262064c5ec1ac89b039d4ef8ed6d3ab709a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 14:50:06 +0200 Subject: [PATCH 0143/2389] Port 169051cb72ff8487696cd7e19a20e3654f50fc49 on master --- .../org/asynchttpclient/multipart/MultipartBody.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java index 9f5ec1d756..70d15e21e2 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java @@ -579,18 +579,20 @@ private long writeToTarget(WritableByteChannel target, ByteArrayOutputStream byt final SocketChannel channel = (SocketChannel) target; channel.register(selector, SelectionKey.OP_WRITE); - while (written < byteWriter.size() && selector.select() != 0) { + while (written < byteWriter.size()) { + selector.select(1000); + maxSpin++; final Set selectedKeys = selector.selectedKeys(); for (SelectionKey key : selectedKeys) { if (key.isWritable()) { written += target.write(message); + maxSpin = 0; } } - } - - if (written < byteWriter.size()) { - throw new IOException("Unable to write on channel " + target); + if (maxSpin >= 10) { + throw new IOException("Unable to write on channel " + target); + } } } finally { selector.close(); From 0db5154bb4e010bf4c9b6cc6d69323860e18b066 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 14:50:23 +0200 Subject: [PATCH 0144/2389] Port fb2daaca6441d9846db25ffccc194f9921b5a3c8 on master --- api/src/main/java/org/asynchttpclient/multipart/FilePart.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/FilePart.java b/api/src/main/java/org/asynchttpclient/multipart/FilePart.java index 6cbab86a56..1d06806710 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/FilePart.java +++ b/api/src/main/java/org/asynchttpclient/multipart/FilePart.java @@ -148,9 +148,9 @@ public FilePart(String name, String fileName, File file, String contentType, Str * @throws java.io.IOException If an IO problem occurs */ protected void sendDispositionHeader(OutputStream out) throws IOException { + super.sendDispositionHeader(out); String filename = this.source.getFileName(); if (filename != null) { - super.sendDispositionHeader(out); out.write(FILE_NAME_BYTES); out.write(QUOTE_BYTES); out.write(MultipartEncodingUtil.getAsciiBytes(filename)); From 91fc8269c3e17320a7c8015186b697a754458048 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 15:19:34 +0200 Subject: [PATCH 0145/2389] Drop JDK provider, close #392 --- .../org/asynchttpclient/AsyncHttpClient.java | 11 +- .../asynchttpclient/AsyncHttpProvider.java | 2 - .../providers/jdk/JDKAsyncHttpProvider.java | 759 ------------------ .../jdk/JDKAsyncHttpProviderConfig.java | 44 - .../providers/jdk/JDKDelegateFuture.java | 84 -- .../providers/jdk/JDKFuture.java | 182 ----- .../providers/jdk/JDKResponse.java | 63 -- .../providers/jdk/ResponseBodyPart.java | 92 --- .../providers/jdk/ResponseHeaders.java | 59 -- .../providers/jdk/ResponseStatus.java | 89 -- 10 files changed, 3 insertions(+), 1382 deletions(-) delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProviderConfig.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java delete mode 100644 api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 7097322940..18ddaa77fe 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -147,8 +147,7 @@ public class AsyncHttpClient implements Closeable { */ private static final String[] DEFAULT_PROVIDERS = { "org.asynchttpclient.providers.netty.NettyAsyncHttpProvider", - "org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider", - "org.asynchttpclient.providers.jdk.JDKAsyncHttpProvider" + "org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider" }; private final AsyncHttpProvider httpProvider; @@ -174,8 +173,7 @@ public class AsyncHttpClient implements Closeable { *

  • JDK
  • * * - * If none of those providers are found, then the runtime will default to - * the {@link org.asynchttpclient.providers.jdk.JDKAsyncHttpProvider}. + * If none of those providers are found, then the engine will throw an IllegalStateException. */ public AsyncHttpClient() { this(new AsyncHttpClientConfig.Builder().build()); @@ -200,11 +198,9 @@ public AsyncHttpClient(AsyncHttpProvider provider) { *
      *
    • netty
    • *
    • grizzly
    • - *
    • JDK
    • *
    * - * If none of those providers are found, then the runtime will default to - * the {@link org.asynchttpclient.providers.jdk.JDKAsyncHttpProvider}. + * If none of those providers are found, then the engine will throw an IllegalStateException. * * @param config a {@link AsyncHttpClientConfig} */ @@ -642,7 +638,6 @@ private static AsyncHttpProvider loadProvider(final String className, return null; } - @SuppressWarnings("unchecked") private static AsyncHttpProvider loadDefaultProvider(String[] providerClassNames, AsyncHttpClientConfig config) { AsyncHttpProvider provider; diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java index c8f910b8fb..848249a6d1 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpProvider.java @@ -20,8 +20,6 @@ /** * Interface to be used when implementing custom asynchronous I/O HTTP client. - * By default, the {@link org.asynchttpclient.providers.jdk.JDKAsyncHttpProvider} is used if - * none of the other provider modules are found on the classpath. */ public interface AsyncHttpProvider extends Closeable { diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java deleted file mode 100644 index d6cec0a5b5..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProvider.java +++ /dev/null @@ -1,759 +0,0 @@ -/* - * Copyright (c) 2010-2013 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import static org.asynchttpclient.util.AsyncHttpProviderUtils.*; -import static org.asynchttpclient.util.MiscUtil.*; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.lang.reflect.Field; -import java.net.Authenticator; -import java.net.ConnectException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.PasswordAuthentication; -import java.net.Proxy; -import java.net.SocketAddress; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; -import java.security.GeneralSecurityException; -import java.security.NoSuchAlgorithmException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.zip.GZIPInputStream; - -import javax.naming.AuthenticationException; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLHandshakeException; - -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.AsyncHttpProviderConfig; -import org.asynchttpclient.Body; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.ListenableFuture; -import org.asynchttpclient.MaxRedirectException; -import org.asynchttpclient.ProgressAsyncHandler; -import org.asynchttpclient.ProxyServer; -import org.asynchttpclient.Realm; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.filter.FilterContext; -import org.asynchttpclient.filter.FilterException; -import org.asynchttpclient.filter.IOExceptionFilter; -import org.asynchttpclient.filter.ResponseFilter; -import org.asynchttpclient.listener.TransferCompletionHandler; -import org.asynchttpclient.multipart.MultipartRequestEntity; -import org.asynchttpclient.util.AsyncHttpProviderUtils; -import org.asynchttpclient.util.AuthenticatorUtils; -import org.asynchttpclient.util.ProxyUtils; -import org.asynchttpclient.util.SslUtils; -import org.asynchttpclient.util.UTF8UrlEncoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class JDKAsyncHttpProvider implements AsyncHttpProvider { - private final static Logger logger = LoggerFactory.getLogger(JDKAsyncHttpProvider.class); - - private final static String NTLM_DOMAIN = "http.auth.ntlm.domain"; - - private final AsyncHttpClientConfig config; - - private final AtomicBoolean isClose = new AtomicBoolean(false); - - private final static int MAX_BUFFERED_BYTES = 8192; - - private final AtomicInteger maxConnections = new AtomicInteger(); - - private String jdkNtlmDomain; - - private Authenticator jdkAuthenticator; - - private boolean bufferResponseInMemory = false; - - private ExecutorService service; - - private boolean managedExecutorService; - - public JDKAsyncHttpProvider(AsyncHttpClientConfig config) { - - this.config = config; - service = config.executorService(); - managedExecutorService = (service == null); - if (service == null) { - service = AsyncHttpProviderUtils.createDefaultExecutorService(); - } - AsyncHttpProviderConfig providerConfig = config.getAsyncHttpProviderConfig(); - if (providerConfig instanceof JDKAsyncHttpProviderConfig) { - configure(JDKAsyncHttpProviderConfig.class.cast(providerConfig)); - } - } - - private void configure(JDKAsyncHttpProviderConfig config) { - for (Map.Entry e : config.propertiesSet()) { - System.setProperty(e.getKey(), e.getValue()); - } - - if (config.getProperty(JDKAsyncHttpProviderConfig.FORCE_RESPONSE_BUFFERING) != null) { - bufferResponseInMemory = true; - } - } - - public ListenableFuture execute(Request request, AsyncHandler handler) throws IOException { - return execute(request, handler, null); - } - - public ListenableFuture execute(Request request, AsyncHandler handler, ListenableFuture future) throws IOException { - if (isClose.get()) { - throw new IOException("Closed"); - } - - if (config.getMaxTotalConnections() > -1 && (maxConnections.get() + 1) > config.getMaxTotalConnections()) { - throw new IOException(String.format("Too many connections %s", config.getMaxTotalConnections())); - } - - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - if (proxyServer != null || realm != null) { - try { - configureProxyAndAuth(proxyServer, realm); - } catch (AuthenticationException e) { - throw new IOException(e.getMessage()); - } - } - - HttpURLConnection urlConnection = createUrlConnection(request); - - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); - - JDKDelegateFuture delegate = null; - if (future != null) { - delegate = new JDKDelegateFuture(handler, requestTimeout, future, urlConnection); - } - - JDKFuture f = (delegate == null) ? new JDKFuture(handler, requestTimeout, urlConnection) : delegate; - f.touch(); - - f.setInnerFuture(service.submit(new AsyncHttpUrlConnection(urlConnection, request, handler, f))); - maxConnections.incrementAndGet(); - - return f; - } - - private HttpURLConnection createUrlConnection(Request request) throws IOException { - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - Proxy proxy = null; - if (proxyServer != null || realm != null) { - try { - proxy = configureProxyAndAuth(proxyServer, realm); - } catch (AuthenticationException e) { - throw new IOException(e.getMessage()); - } - } - - HttpURLConnection urlConnection = (HttpURLConnection) - request.getURI().toURL().openConnection(proxy == null ? Proxy.NO_PROXY : proxy); - - if (request.getUrl().startsWith("https")) { - HttpsURLConnection secure = (HttpsURLConnection) urlConnection; - SSLContext sslContext = config.getSSLContext(); - if (sslContext == null) { - try { - sslContext = SslUtils.getSSLContext(); - } catch (NoSuchAlgorithmException e) { - throw new IOException(e.getMessage()); - } catch (GeneralSecurityException e) { - throw new IOException(e.getMessage()); - } - } - secure.setSSLSocketFactory(sslContext.getSocketFactory()); - secure.setHostnameVerifier(config.getHostnameVerifier()); - } - return urlConnection; - } - - public void close() { - isClose.set(true); - if (managedExecutorService) { - service.shutdownNow(); - } - } - - private final class AsyncHttpUrlConnection implements Callable { - - private HttpURLConnection urlConnection; - private Request request; - private final AsyncHandler asyncHandler; - private final ListenableFuture future; - private int currentRedirectCount; - private AtomicBoolean isAuth = new AtomicBoolean(false); - private byte[] cachedBytes; - private int cachedBytesLenght; - private boolean terminate = true; - - public AsyncHttpUrlConnection(HttpURLConnection urlConnection, Request request, AsyncHandler asyncHandler, ListenableFuture future) { - this.urlConnection = urlConnection; - this.request = request; - this.asyncHandler = asyncHandler; - this.future = future; - this.request = request; - } - - public T call() throws Exception { - AsyncHandler.STATE state = AsyncHandler.STATE.ABORT; - try { - URI uri = null; - // Encoding with URLConnection is a bit bogus so we need to try both way before setting it - try { - uri = AsyncHttpProviderUtils.createUri(request.getRawUrl()); - } catch (IllegalArgumentException u) { - uri = AsyncHttpProviderUtils.createUri(request.getUrl()); - } - - configure(uri, urlConnection, request); - urlConnection.connect(); - - if (asyncHandler instanceof TransferCompletionHandler) { - throw new IllegalStateException(TransferCompletionHandler.class.getName() + "not supported by this provider"); - } - - int statusCode = urlConnection.getResponseCode(); - - logger.debug("\n\nRequest {}\n\nResponse {}\n", request, statusCode); - - ResponseStatus status = new ResponseStatus(uri, urlConnection, config); - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(asyncHandler).request(request).responseStatus(status).build(); - for (ResponseFilter asyncFilter : config.getResponseFilters()) { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } - - // The request has changed - if (fc.replayRequest()) { - request = fc.getRequest(); - urlConnection = createUrlConnection(request); - terminate = false; - return call(); - } - - boolean redirectEnabled = (request.isRedirectEnabled() || config.isRedirectEnabled()); - if (redirectEnabled && (statusCode == 302 || statusCode == 301)) { - - if (currentRedirectCount++ < config.getMaxRedirects()) { - String location = urlConnection.getHeaderField("Location"); - URI redirUri = AsyncHttpProviderUtils.getRedirectUri(uri, location); - String newUrl = redirUri.toString(); - - if (!newUrl.equals(uri.toString())) { - RequestBuilder builder = new RequestBuilder(request); - - logger.debug("Redirecting to {}", newUrl); - - request = builder.setUrl(newUrl).build(); - urlConnection = createUrlConnection(request); - terminate = false; - return call(); - } - } else { - throw new MaxRedirectException("Maximum redirect reached: " + config.getMaxRedirects()); - } - } - - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - if (statusCode == 401 && !isAuth.getAndSet(true) && realm != null) { - String wwwAuth = urlConnection.getHeaderField("WWW-Authenticate"); - - logger.debug("Sending authentication to {}", request.getUrl()); - - Realm nr = new Realm.RealmBuilder().clone(realm) - .parseWWWAuthenticateHeader(wwwAuth) - .setUri(URI.create(request.getUrl()).getPath()) - .setMethodName(request.getMethod()) - .setUsePreemptiveAuth(true) - .build(); - RequestBuilder builder = new RequestBuilder(request); - request = builder.setRealm(nr).build(); - urlConnection = createUrlConnection(request); - terminate = false; - return call(); - } - - state = asyncHandler.onStatusReceived(status); - if (state == AsyncHandler.STATE.CONTINUE) { - state = asyncHandler.onHeadersReceived(new ResponseHeaders(uri, urlConnection, JDKAsyncHttpProvider.this)); - } - - if (state == AsyncHandler.STATE.CONTINUE) { - InputStream is = getInputStream(urlConnection); - String contentEncoding = urlConnection.getHeaderField("Content-Encoding"); - boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase(contentEncoding); - if (isGZipped) { - is = new GZIPInputStream(is); - } - - int byteToRead = urlConnection.getContentLength(); - InputStream stream = is; - if (bufferResponseInMemory || byteToRead <= 0) { - int[] lengthWrapper = new int[1]; - byte[] bytes = readFully(is, lengthWrapper); - stream = new ByteArrayInputStream(bytes, 0, lengthWrapper[0]); - byteToRead = lengthWrapper[0]; - } - - if (byteToRead > 0) { - int minBytes = Math.min(8192, byteToRead); - byte[] bytes = new byte[minBytes]; - int leftBytes = minBytes < 8192 ? minBytes : byteToRead; - int read = 0; - while (leftBytes > -1) { - - read = stream.read(bytes); - if (read == -1) { - break; - } - - future.touch(); - - byte[] b = new byte[read]; - System.arraycopy(bytes, 0, b, 0, read); - leftBytes -= read; - asyncHandler.onBodyPartReceived(new ResponseBodyPart(uri, b, JDKAsyncHttpProvider.this, leftBytes > -1)); - } - } - - if (request.getMethod().equalsIgnoreCase("HEAD")) { - asyncHandler.onBodyPartReceived(new ResponseBodyPart(uri, "".getBytes(), JDKAsyncHttpProvider.this, true)); - } - } - - if (asyncHandler instanceof ProgressAsyncHandler) { - ProgressAsyncHandler progressAsyncHandler = ProgressAsyncHandler.class.cast(asyncHandler); - progressAsyncHandler.onHeaderWriteCompleted(); - progressAsyncHandler.onContentWriteCompleted(); - } - try { - T t = asyncHandler.onCompleted(); - future.content(t); - future.done(); - return t; - } catch (Throwable t) { - RuntimeException ex = new RuntimeException(); - ex.initCause(t); - throw ex; - } - } catch (Throwable t) { - logger.debug(t.getMessage(), t); - - if (t instanceof IOException && !config.getIOExceptionFilters().isEmpty()) { - FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(asyncHandler) - .request(request).ioException(IOException.class.cast(t)).build(); - - try { - fc = handleIoException(fc); - } catch (FilterException e) { - if (config.getMaxTotalConnections() != -1) { - maxConnections.decrementAndGet(); - } - future.done(); - } - - if (fc.replayRequest()) { - request = fc.getRequest(); - urlConnection = createUrlConnection(request); - return call(); - } - } - - try { - future.abort(filterException(t)); - } catch (Throwable t2) { - logger.error(t2.getMessage(), t2); - } - } finally { - if (terminate) { - if (config.getMaxTotalConnections() != -1) { - maxConnections.decrementAndGet(); - } - urlConnection.disconnect(); - if (jdkNtlmDomain != null) { - System.setProperty(NTLM_DOMAIN, jdkNtlmDomain); - } - Authenticator.setDefault(jdkAuthenticator); - } - } - return null; - } - - // FIXME Streams should be streamed, not turned into byte arrays - private final byte[] readFully(InputStream in, int[] lengthWrapper) throws IOException { - // just in case available() returns bogus (or -1), allocate non-trivial chunk - byte[] b = new byte[Math.max(512, in.available())]; - int offset = 0; - while (true) { - int left = b.length - offset; - int count = in.read(b, offset, left); - if (count < 0) { // EOF - break; - } - offset += count; - if (count == left) { // full buffer, need to expand - b = doubleUp(b); - } - } - // wish Java had Tuple return type... - lengthWrapper[0] = offset; - return b; - } - - private final byte[] doubleUp(byte[] b) { - int len = b.length; - byte[] b2 = new byte[len + len]; - System.arraycopy(b, 0, b2, 0, len); - return b2; - } - - private FilterContext handleIoException(FilterContext fc) throws FilterException { - for (IOExceptionFilter asyncFilter : config.getIOExceptionFilters()) { - fc = asyncFilter.filter(fc); - if (fc == null) { - throw new NullPointerException("FilterContext is null"); - } - } - return fc; - } - - private Throwable filterException(Throwable t) { - if (t instanceof UnknownHostException) { - t = new ConnectException(t.getMessage()); - - } else if (t instanceof SocketTimeoutException) { - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); - t = new TimeoutException("No response received after " + requestTimeout); - - } else if (t instanceof SSLHandshakeException) { - Throwable t2 = new ConnectException(); - t2.initCause(t); - t = t2; - } - - return t; - } - - private void configure(URI uri, HttpURLConnection urlConnection, Request request) throws IOException, AuthenticationException { - - int requestTimeout = AsyncHttpProviderUtils.requestTimeout(config, request); - - if (requestTimeout != 0) { - urlConnection.setConnectTimeout(requestTimeout); - urlConnection.setReadTimeout(requestTimeout); - } - - urlConnection.setInstanceFollowRedirects(false); - String host = uri.getHost(); - String method = request.getMethod(); - - if (request.getVirtualHost() != null) { - host = request.getVirtualHost(); - } - - if (uri.getPort() == -1 || request.getVirtualHost() != null) { - urlConnection.setRequestProperty("Host", host); - } else { - urlConnection.setRequestProperty("Host", host + ":" + uri.getPort()); - } - - - if (config.isCompressionEnabled()) { - urlConnection.setRequestProperty("Accept-Encoding", "gzip"); - } - - if (!method.equalsIgnoreCase("CONNECT")) { - FluentCaseInsensitiveStringsMap h = request.getHeaders(); - if (h != null) { - for (String name : h.keySet()) { - if (!"host".equalsIgnoreCase(name)) { - for (String value : h.get(name)) { - urlConnection.setRequestProperty(name, value); - if (name.equalsIgnoreCase("Expect")) { - throw new IllegalStateException("Expect: 100-Continue not supported"); - } - } - } - } - } - } - - String ka = AsyncHttpProviderUtils.keepAliveHeaderValue(config); - urlConnection.setRequestProperty("Connection", ka); - ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); - if (proxyServer != null) { - urlConnection.setRequestProperty("Proxy-Connection", ka); - if (proxyServer.getPrincipal() != null) { - urlConnection.setRequestProperty("Proxy-Authorization", AuthenticatorUtils.computeBasicAuthentication(proxyServer)); - } - - if (proxyServer.getProtocol().equals(ProxyServer.Protocol.NTLM)) { - jdkNtlmDomain = System.getProperty(NTLM_DOMAIN); - System.setProperty(NTLM_DOMAIN, proxyServer.getNtlmDomain()); - } - } - - Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); - if (realm != null && realm.getUsePreemptiveAuth()) { - switch (realm.getAuthScheme()) { - case BASIC: - urlConnection.setRequestProperty("Authorization", - AuthenticatorUtils.computeBasicAuthentication(realm)); - break; - case DIGEST: - if (isNonEmpty(realm.getNonce())) { - try { - urlConnection.setRequestProperty("Authorization", - AuthenticatorUtils.computeDigestAuthentication(realm)); - } catch (NoSuchAlgorithmException e) { - throw new SecurityException(e); - } - } - break; - case NTLM: - jdkNtlmDomain = System.getProperty(NTLM_DOMAIN); - System.setProperty(NTLM_DOMAIN, realm.getNtlmDomain()); - break; - case NONE: - break; - default: - throw new IllegalStateException(String.format("Invalid Authentication %s", realm.toString())); - } - - } - - // Add default accept headers. - if (request.getHeaders().getFirstValue("Accept") == null) { - urlConnection.setRequestProperty("Accept", "*/*"); - } - - if (request.getHeaders().getFirstValue("User-Agent") != null) { - urlConnection.setRequestProperty("User-Agent", request.getHeaders().getFirstValue("User-Agent")); - } else if (config.getUserAgent() != null) { - urlConnection.setRequestProperty("User-Agent", config.getUserAgent()); - } else { - urlConnection.setRequestProperty("User-Agent", - AsyncHttpProviderUtils.constructUserAgent(JDKAsyncHttpProvider.class, - config)); - } - - if (isNonEmpty(request.getCookies())) { - urlConnection.setRequestProperty("Cookie", AsyncHttpProviderUtils.encodeCookies(request.getCookies())); - } - - String reqType = request.getMethod(); - urlConnection.setRequestMethod(reqType); - - if ("POST".equals(reqType) || "PUT".equals(reqType)) { - urlConnection.setRequestProperty("Content-Length", "0"); - urlConnection.setDoOutput(true); - String bodyCharset = request.getBodyEncoding() == null ? DEFAULT_CHARSET : request.getBodyEncoding(); - - if (cachedBytes != null) { - urlConnection.setRequestProperty("Content-Length", String.valueOf(cachedBytesLenght)); - urlConnection.setFixedLengthStreamingMode(cachedBytesLenght); - urlConnection.getOutputStream().write(cachedBytes, 0, cachedBytesLenght); - } else if (request.getByteData() != null) { - urlConnection.setRequestProperty("Content-Length", String.valueOf(request.getByteData().length)); - urlConnection.setFixedLengthStreamingMode(request.getByteData().length); - - urlConnection.getOutputStream().write(request.getByteData()); - } else if (request.getStringData() != null) { - if (!request.getHeaders().containsKey("Content-Type")) { - urlConnection.setRequestProperty("Content-Type", "text/html;" + bodyCharset); - } - byte[] b = request.getStringData().getBytes(bodyCharset); - urlConnection.setRequestProperty("Content-Length", String.valueOf(b.length)); - urlConnection.getOutputStream().write(b); - } else if (request.getStreamData() != null) { - int[] lengthWrapper = new int[1]; - cachedBytes = readFully(request.getStreamData(), lengthWrapper); - cachedBytesLenght = lengthWrapper[0]; - urlConnection.setRequestProperty("Content-Length", String.valueOf(cachedBytesLenght)); - urlConnection.setFixedLengthStreamingMode(cachedBytesLenght); - - urlConnection.getOutputStream().write(cachedBytes, 0, cachedBytesLenght); - } else if (request.getParams() != null) { - StringBuilder sb = new StringBuilder(); - for (final Map.Entry> paramEntry : request.getParams()) { - final String key = paramEntry.getKey(); - for (final String value : paramEntry.getValue()) { - if (sb.length() > 0) { - sb.append("&"); - } - UTF8UrlEncoder.appendEncoded(sb, key); - sb.append("="); - UTF8UrlEncoder.appendEncoded(sb, value); - } - } - urlConnection.setRequestProperty("Content-Length", String.valueOf(sb.length())); - urlConnection.setFixedLengthStreamingMode(sb.length()); - - if (!request.getHeaders().containsKey("Content-Type")) { - urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - } - urlConnection.getOutputStream().write(sb.toString().getBytes(bodyCharset)); - } else if (request.getParts() != null) { - int lenght = (int) request.getContentLength(); - if (lenght != -1) { - urlConnection.setRequestProperty("Content-Length", String.valueOf(lenght)); - urlConnection.setFixedLengthStreamingMode(lenght); - } - - if (lenght == -1) { - lenght = MAX_BUFFERED_BYTES; - } - - MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); - - urlConnection.setRequestProperty("Content-Type", mre.getContentType()); - urlConnection.setRequestProperty("Content-Length", String.valueOf(mre.getContentLength())); - - mre.writeRequest(urlConnection.getOutputStream()); - } else if (request.getFile() != null) { - File file = request.getFile(); - if (!file.isFile()) { - throw new IOException(String.format(Thread.currentThread() - + "File %s is not a file or doesn't exist", file.getAbsolutePath())); - } - urlConnection.setRequestProperty("Content-Length", String.valueOf(file.length())); - urlConnection.setFixedLengthStreamingMode((int) file.length()); - - FileInputStream fis = new FileInputStream(file); - try { - OutputStream os = urlConnection.getOutputStream(); - for (final byte[] buffer = new byte[1024 * 16]; ; ) { - int read = fis.read(buffer); - if (read < 0) { - break; - } - os.write(buffer, 0, read); - } - } finally { - fis.close(); - } - } else if (request.getBodyGenerator() != null) { - Body body = request.getBodyGenerator().createBody(); - try { - int length = (int) body.getContentLength(); - if (length < 0) { - length = (int) request.getContentLength(); - } - if (length >= 0) { - urlConnection.setRequestProperty("Content-Length", String.valueOf(length)); - urlConnection.setFixedLengthStreamingMode(length); - } - OutputStream os = urlConnection.getOutputStream(); - for (ByteBuffer buffer = ByteBuffer.allocate(1024 * 8); ; ) { - buffer.clear(); - if (body.read(buffer) < 0) { - break; - } - os.write(buffer.array(), buffer.arrayOffset(), buffer.position()); - } - } finally { - try { - body.close(); - } catch (IOException e) { - logger.warn("Failed to close request body: {}", e.getMessage(), e); - } - } - } - } - } - } - - private Proxy configureProxyAndAuth(final ProxyServer proxyServer, final Realm realm) throws AuthenticationException { - - Proxy proxy = null; - if (proxyServer != null) { - - String proxyHost = proxyServer.getHost().startsWith("http://") - ? proxyServer.getHost().substring("http://".length()) : proxyServer.getHost(); - - SocketAddress addr = new InetSocketAddress(proxyHost, proxyServer.getPort()); - proxy = new Proxy(Proxy.Type.HTTP, addr); - } - - final boolean hasProxy = (proxyServer != null && proxyServer.getPrincipal() != null); - final boolean hasAuthentication = (realm != null && realm.getPrincipal() != null); - if (hasProxy || hasAuthentication) { - - Field f = null; - try { - f = Authenticator.class.getDeclaredField("theAuthenticator"); - - f.setAccessible(true); - jdkAuthenticator = (Authenticator) f.get(Authenticator.class); - } catch (NoSuchFieldException e) { - } catch (IllegalAccessException e) { - } - - - Authenticator.setDefault(new Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - if (hasProxy && getRequestingHost().equals(proxyServer.getHost()) - && getRequestingPort() == proxyServer.getPort()) { - String password = ""; - if (proxyServer.getPassword() != null) { - password = proxyServer.getPassword(); - } - return new PasswordAuthentication(proxyServer.getPrincipal(), password.toCharArray()); - } - - if (hasAuthentication) { - return new PasswordAuthentication(realm.getPrincipal(), realm.getPassword().toCharArray()); - } - - return super.getPasswordAuthentication(); - } - }); - } else { - Authenticator.setDefault(null); - } - return proxy; - } - - private InputStream getInputStream(HttpURLConnection urlConnection) throws IOException { - if (urlConnection.getResponseCode() < 400) { - return urlConnection.getInputStream(); - } else { - InputStream ein = urlConnection.getErrorStream(); - return (ein != null) - ? ein : new ByteArrayInputStream(new byte[0]); - } - } - -} diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProviderConfig.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProviderConfig.java deleted file mode 100644 index 8d743a21a5..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKAsyncHttpProviderConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import org.asynchttpclient.AsyncHttpProviderConfig; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -public class JDKAsyncHttpProviderConfig implements AsyncHttpProviderConfig { - - public static final String FORCE_RESPONSE_BUFFERING = "bufferResponseInMemory"; - - private final ConcurrentHashMap properties = new ConcurrentHashMap(); - - @Override - public JDKAsyncHttpProviderConfig addProperty(String name, String value) { - properties.put(name, value); - return this; - } - - public String getProperty(String name) { - return properties.get(name); - } - - public String removeProperty(String name) { - return properties.remove(name); - } - - public Set> propertiesSet() { - return properties.entrySet(); - } -} diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java deleted file mode 100644 index 1b4dd34ea0..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKDelegateFuture.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import static org.asynchttpclient.util.DateUtil.millisTime; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.ListenableFuture; - -import java.net.HttpURLConnection; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -public class JDKDelegateFuture extends JDKFuture { - - private final ListenableFuture delegateFuture; - - public JDKDelegateFuture(AsyncHandler asyncHandler, int responseTimeoutInMs, - ListenableFuture delegateFuture, HttpURLConnection urlConnection) { - super(asyncHandler, responseTimeoutInMs, urlConnection); - this.delegateFuture = delegateFuture; - } - - public void done() { - delegateFuture.done(); - runListeners(); - } - - public void abort(Throwable t) { - if (innerFuture != null) { - innerFuture.cancel(true); - } - delegateFuture.abort(t); - } - - public boolean cancel(boolean mayInterruptIfRunning) { - delegateFuture.cancel(mayInterruptIfRunning); - if (innerFuture != null) { - return innerFuture.cancel(mayInterruptIfRunning); - } else { - return false; - } - } - - public boolean isCancelled() { - if (innerFuture != null) { - return innerFuture.isCancelled(); - } else { - return false; - } - } - - public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - V content = null; - try { - if (innerFuture != null) { - content = innerFuture.get(timeout, unit); - } - } catch (Throwable t) { - if (!contentProcessed.get() && timeout != -1 && ((millisTime() - touch.get()) <= responseTimeoutInMs)) { - return get(timeout, unit); - } - timedOut.set(true); - delegateFuture.abort(t); - } - - if (exception.get() != null) { - delegateFuture.abort(new ExecutionException(exception.get())); - } - delegateFuture.content(content); - delegateFuture.done(); - return content; - } -} diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java deleted file mode 100644 index 893312cfcb..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKFuture.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import static org.asynchttpclient.util.DateUtil.millisTime; -import org.asynchttpclient.AsyncHandler; -import org.asynchttpclient.listenable.AbstractListenableFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.HttpURLConnection; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; - - -public class JDKFuture extends AbstractListenableFuture { - - private final static Logger logger = LoggerFactory.getLogger(JDKFuture.class); - - protected Future innerFuture; - protected final AsyncHandler asyncHandler; - protected final int responseTimeoutInMs; - protected final AtomicBoolean cancelled = new AtomicBoolean(false); - protected final AtomicBoolean timedOut = new AtomicBoolean(false); - protected final AtomicBoolean isDone = new AtomicBoolean(false); - protected final AtomicReference exception = new AtomicReference(); - protected final AtomicLong touch = new AtomicLong(millisTime()); - protected final AtomicBoolean contentProcessed = new AtomicBoolean(false); - protected final HttpURLConnection urlConnection; - private boolean writeHeaders; - private boolean writeBody; - - public JDKFuture(AsyncHandler asyncHandler, int responseTimeoutInMs, HttpURLConnection urlConnection) { - this.asyncHandler = asyncHandler; - this.responseTimeoutInMs = responseTimeoutInMs; - this.urlConnection = urlConnection; - writeHeaders = true; - writeBody = true; - } - - protected void setInnerFuture(Future innerFuture) { - this.innerFuture = innerFuture; - } - - public void done() { - isDone.set(true); - runListeners(); - } - - public void abort(Throwable t) { - exception.set(t); - if (innerFuture != null) { - innerFuture.cancel(true); - } - if (!timedOut.get() && !cancelled.get()) { - try { - asyncHandler.onThrowable(t); - } catch (Throwable te) { - logger.debug("asyncHandler.onThrowable", te); - } - } - runListeners(); - } - - public void content(V v) { - } - - public boolean cancel(boolean mayInterruptIfRunning) { - if (!cancelled.get() && innerFuture != null) { - urlConnection.disconnect(); - try { - asyncHandler.onThrowable(new CancellationException()); - } catch (Throwable te) { - logger.debug("asyncHandler.onThrowable", te); - } - cancelled.set(true); - runListeners(); - return innerFuture.cancel(mayInterruptIfRunning); - } else { - runListeners(); - return false; - } - } - - public boolean isCancelled() { - if (innerFuture != null) { - return innerFuture.isCancelled(); - } else { - return false; - } - } - - public boolean isDone() { - contentProcessed.set(true); - return innerFuture.isDone(); - } - - public V get() throws InterruptedException, ExecutionException { - try { - return get(responseTimeoutInMs, TimeUnit.MILLISECONDS); - } catch (TimeoutException e) { - throw new ExecutionException(e); - } - } - - public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { - V content = null; - try { - if (innerFuture != null) { - content = innerFuture.get(timeout, unit); - } - } catch (TimeoutException t) { - if (!contentProcessed.get() && timeout != -1 && ((millisTime() - touch.get()) <= responseTimeoutInMs)) { - return get(timeout, unit); - } - - if (exception.get() == null) { - timedOut.set(true); - throw new ExecutionException(new TimeoutException(String.format("No response received after %s", responseTimeoutInMs))); - } - } catch (CancellationException ce) { - } - - if (exception.get() != null) { - throw new ExecutionException(exception.get()); - } - return content; - } - - /** - * Is the Future still valid - * - * @return true if response has expired and should be terminated. - */ - public boolean hasExpired() { - return responseTimeoutInMs != -1 && ((millisTime() - touch.get()) > responseTimeoutInMs); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public void touch() { - touch.set(millisTime()); - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean getAndSetWriteHeaders(boolean writeHeaders) { - boolean b = this.writeHeaders; - this.writeHeaders = writeHeaders; - return b; - } - - /** - * {@inheritDoc} - */ - /* @Override */ - public boolean getAndSetWriteBody(boolean writeBody) { - boolean b = this.writeBody; - this.writeBody = writeBody; - return b; - } -} diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java b/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java deleted file mode 100644 index c3b536e971..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/JDKResponse.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; -import org.asynchttpclient.Cookie; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.providers.ResponseBase; -import org.asynchttpclient.util.AsyncHttpProviderUtils; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -public class JDKResponse extends ResponseBase { - - public JDKResponse(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts) { - super(status, headers, bodyParts); - } - - /* @Override */ - - public String getResponseBodyExcerpt(int maxLength) throws IOException { - return getResponseBodyExcerpt(maxLength, DEFAULT_CHARSET); - } - - public String getResponseBodyExcerpt(int maxLength, String charset) throws IOException { - // should be fine; except that it may split multi-byte chars (last char may become '?') - byte[] b = AsyncHttpProviderUtils.contentToBytes(bodyParts, maxLength); - return new String(b, charset); - } - - /* @Override */ - public List buildCookies() { - List cookies = new ArrayList(); - for (Map.Entry> header : headers.getHeaders().entrySet()) { - if (header.getKey().equalsIgnoreCase("Set-Cookie")) { - // TODO: ask for parsed header - List v = header.getValue(); - for (String value : v) { - cookies.addAll(CookieDecoder.decode(value)); - } - } - } - return Collections.unmodifiableList(cookies); - } -} diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java deleted file mode 100644 index b80ced8345..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseBodyPart.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.nio.ByteBuffer; - -/** - * A callback class used when an HTTP response body is received. - */ -public class ResponseBodyPart extends HttpResponseBodyPart { - - private final byte[] chunk; - private final boolean isLast; - private boolean closeConnection; - - public ResponseBodyPart(URI uri, byte[] chunk, AsyncHttpProvider provider, boolean last) { - this.chunk = chunk; - isLast = last; - } - - /** - * Return the response body's part bytes received. - * - * @return the response body's part bytes received. - */ - public byte[] getBodyPartBytes() { - return chunk; - } - - @Override - public InputStream readBodyPartBytes() { - return new ByteArrayInputStream(chunk); - } - - @Override - public int length() { - return chunk.length; - } - - @Override - public int writeTo(OutputStream outputStream) throws IOException { - outputStream.write(chunk); - return chunk.length; - } - - @Override - public ByteBuffer getBodyByteBuffer() { - return ByteBuffer.wrap(chunk); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isLast() { - return isLast; - } - - /** - * {@inheritDoc} - */ - @Override - public void markUnderlyingConnectionAsClosed() { - closeConnection = true; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean closeUnderlyingConnection() { - return closeConnection; - } -} \ No newline at end of file diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java deleted file mode 100644 index ed71a96aa7..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseHeaders.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; -import org.asynchttpclient.HttpResponseHeaders; - -import java.net.HttpURLConnection; -import java.net.URI; -import java.util.List; -import java.util.Map; - -/** - * A class that represent the HTTP headers. - */ -public class ResponseHeaders extends HttpResponseHeaders { - - private final HttpURLConnection urlConnection; - private final FluentCaseInsensitiveStringsMap headers; - - public ResponseHeaders(URI uri, HttpURLConnection urlConnection, AsyncHttpProvider provider) { - this.urlConnection = urlConnection; - headers = computerHeaders(); - } - - private FluentCaseInsensitiveStringsMap computerHeaders() { - FluentCaseInsensitiveStringsMap h = new FluentCaseInsensitiveStringsMap(); - - Map> uh = urlConnection.getHeaderFields(); - - for (Map.Entry> e : uh.entrySet()) { - if (e.getKey() != null) { - h.add(e.getKey(), e.getValue()); - } - } - return h; - } - - /** - * Return the HTTP header - * - * @return an {@link org.asynchttpclient.FluentCaseInsensitiveStringsMap} - */ - @Override - public FluentCaseInsensitiveStringsMap getHeaders() { - return headers; - } -} \ No newline at end of file diff --git a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java b/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java deleted file mode 100644 index b5cbc7094a..0000000000 --- a/api/src/main/java/org/asynchttpclient/providers/jdk/ResponseStatus.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. - * - * This program is licensed to you under the Apache License Version 2.0, - * and you may not use this file except in compliance with the Apache License Version 2.0. - * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the Apache License Version 2.0 is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. - */ -package org.asynchttpclient.providers.jdk; - -import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; -import org.asynchttpclient.Response; - -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URI; -import java.util.List; - -/** - * A class that represent the HTTP response' status line (code + text) - */ -public class ResponseStatus extends HttpResponseStatus { - - private final HttpURLConnection urlConnection; - - public ResponseStatus(URI uri, HttpURLConnection urlConnection, AsyncHttpClientConfig config) { - super(uri, config); - this.urlConnection = urlConnection; - } - - @Override - public Response prepareResponse(HttpResponseHeaders headers, List bodyParts) { - return new JDKResponse(this, headers, bodyParts); - } - - /** - * Return the response status code - * - * @return the response status code - */ - public int getStatusCode() { - try { - return urlConnection.getResponseCode(); - } catch (IOException e) { - return 500; - } - } - - /** - * Return the response status text - * - * @return the response status text - */ - public String getStatusText() { - try { - return urlConnection.getResponseMessage(); - } catch (IOException e) { - return "Internal Error"; - } - } - - @Override - public String getProtocolName() { - return "http"; - } - - @Override - public int getProtocolMajorVersion() { - return 1; - } - - @Override - public int getProtocolMinorVersion() { - return 1; //TODO - } - - @Override - public String getProtocolText() { - return ""; //TODO - } - -} \ No newline at end of file From 5a636c71913c901fc3952da427062e420b669893 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 15:29:12 +0200 Subject: [PATCH 0146/2389] Remove useless URI parameter --- .../asynchttpclient/providers/netty/handler/HttpProtocol.java | 2 +- .../providers/netty/handler/WebSocketProtocol.java | 2 +- .../providers/netty/response/ResponseBodyPart.java | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java index 0b871daf61..e768c2f576 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -417,7 +417,7 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu if (!interrupt && chunk.content().readableBytes() > 0) { // FIXME why - interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(future.getURI(), chunk.content(), last)); + interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(chunk.content(), last)); } if (interrupt || last) { diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java index 49bdadc313..103a677abd 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java @@ -155,7 +155,7 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object } if (frame.content() != null && frame.content().readableBytes() > 0) { - ResponseBodyPart rp = new ResponseBodyPart(future.getURI(), frame.content(), frame.isFinalFragment()); + ResponseBodyPart rp = new ResponseBodyPart(frame.content(), frame.isFinalFragment()); h.onBodyPartReceived(rp); if (pendingOpcode == OPCODE_BINARY) { diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java index e50d36faa8..5248c64d7d 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; import java.nio.ByteBuffer; import org.asynchttpclient.HttpResponseBodyPart; @@ -36,7 +35,7 @@ public class ResponseBodyPart extends HttpResponseBodyPart { private final boolean last; private boolean closeConnection = false; - public ResponseBodyPart(URI uri, ByteBuf buf, boolean last) { + public ResponseBodyPart(ByteBuf buf, boolean last) { bytes = ByteBufUtil.byteBuf2bytes(buf); this.last = last; } From f2e8218e96a0f7e29b57ab79d49b7848a407c12f Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 15:57:57 +0200 Subject: [PATCH 0147/2389] Minor clean up --- .../netty/future/NettyResponseFuture.java | 62 +++++++++++-------- .../providers/netty/handler/HttpProtocol.java | 15 ++--- .../netty/request/NettyRequestSender.java | 4 +- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java index ff5790ca3a..9e15cc652f 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java @@ -57,39 +57,43 @@ public enum STATE { NEW, POOLED, RECONNECTED, CLOSED, } + private final int requestTimeoutInMs; + private final AsyncHttpClientConfig config; + private final long start = millisTime(); + private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy; + private final ProxyServer proxyServer; + private final int maxRetry; private final CountDownLatch latch = new CountDownLatch(1); + + // state mutated from outside the event loop private final AtomicBoolean isDone = new AtomicBoolean(false); private final AtomicBoolean isCancelled = new AtomicBoolean(false); - private AsyncHandler asyncHandler; - private final int requestTimeoutInMs; - private final AsyncHttpClientConfig config; - private Request request; - private HttpRequest nettyRequest; - private final AtomicReference content = new AtomicReference(); - private URI uri; - private boolean keepAlive = true; - private HttpResponse httpResponse; - private final AtomicReference exEx = new AtomicReference(); private final AtomicInteger redirectCount = new AtomicInteger(); - private volatile FutureReaper reaperFuture; private final AtomicBoolean inAuth = new AtomicBoolean(false); private final AtomicBoolean statusReceived = new AtomicBoolean(false); private final AtomicLong touch = new AtomicLong(millisTime()); - private final long start = millisTime(); private final AtomicReference state = new AtomicReference(STATE.NEW); private final AtomicBoolean contentProcessed = new AtomicBoolean(false); - private Channel channel; - private boolean reuseChannel = false; private final AtomicInteger currentRetry = new AtomicInteger(0); - private final int maxRetry; + private final AtomicBoolean throwableCalled = new AtomicBoolean(false); + private final AtomicReference content = new AtomicReference(); + private final AtomicReference exEx = new AtomicReference(); + private volatile FutureReaper reaperFuture; + + // state mutated only inside the event loop + private Channel channel; + private URI uri; + private boolean keepAlive = true; + private Request request; + private HttpRequest nettyRequest; + private HttpResponse httpResponse; + private AsyncHandler asyncHandler; + private HttpResponse pendingResponse; + private boolean streamWasAlreadyConsumed; + private boolean reuseChannel; private boolean writeHeaders; private boolean writeBody; - private final AtomicBoolean throwableCalled = new AtomicBoolean(false); - private boolean allowConnect = false; - private final ConnectionPoolKeyStrategy connectionPoolKeyStrategy; - private final ProxyServer proxyServer; - private final AtomicReference pendingResponse = new AtomicReference(); - private final AtomicBoolean streamWasAlreadyConsumed = new AtomicBoolean(false); + private boolean allowConnect; public NettyResponseFuture(URI uri,// Request request,// @@ -247,7 +251,7 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, return getContent(); } - public V getContent() throws ExecutionException { + private V getContent() throws ExecutionException { ExecutionException e = exEx.getAndSet(null); if (e != null) { throw e; @@ -383,12 +387,20 @@ public boolean getAndSetStatusReceived(boolean sr) { return statusReceived.getAndSet(sr); } - public AtomicReference getPendingResponse() { + public HttpResponse getPendingResponse() { return pendingResponse; } - public boolean getAndSetStreamWasAlreadyConsumed() { - return streamWasAlreadyConsumed.getAndSet(true); + public void setPendingResponse(HttpResponse pendingResponse) { + this.pendingResponse = pendingResponse; + } + + public boolean isStreamWasAlreadyConsumed() { + return streamWasAlreadyConsumed; + } + + public void setStreamWasAlreadyConsumed(boolean streamWasAlreadyConsumed) { + this.streamWasAlreadyConsumed = streamWasAlreadyConsumed; } @Override diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java index e768c2f576..6aa436f40a 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; -import java.util.concurrent.atomic.AtomicReference; import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; @@ -227,8 +226,7 @@ private boolean applyResponseFiltersAndReplayRequest(ChannelHandlerContext ctx, } // The handler may have been wrapped. - handler = fc.getAsyncHandler(); - future.setAsyncHandler(handler); + future.setAsyncHandler(fc.getAsyncHandler()); // The request has changed if (fc.replayRequest()) { @@ -379,20 +377,19 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu HttpRequest nettyRequest = future.getNettyRequest(); AsyncHandler handler = future.getAsyncHandler(); - Request request = future.getRequest(); ProxyServer proxyServer = future.getProxyServer(); try { if (e instanceof HttpResponse) { HttpResponse response = (HttpResponse) e; NettyChannelHandler.LOGGER.debug("\n\nRequest {}\n\nResponse {}\n", nettyRequest, response); - future.getPendingResponse().set(response); + future.setPendingResponse(response); return; } if (e instanceof HttpContent) { - AtomicReference responseRef = future.getPendingResponse(); - HttpResponse response = responseRef.getAndSet(null); + HttpResponse response = future.getPendingResponse(); + future.setPendingResponse(null); if (handler != null) { if (response != null && handleResponseAndExit(ctx, future, handler, nettyRequest, proxyServer, response)) { return; @@ -403,10 +400,6 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu boolean interrupt = false; boolean last = chunk instanceof LastHttpContent; - // FIXME - // Netty 3 provider is broken: in case of trailing headers, - // onHeadersReceived should be called before - // updateBodyAndInterrupt if (last) { LastHttpContent lastChunk = (LastHttpContent) chunk; HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java index 8dd47cbae2..5c049d70ba 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java @@ -358,13 +358,15 @@ public void operationComplete(ChannelProgressiveFuture cf) { private boolean sendStreamAndExit(Channel channel, final InputStream is, NettyResponseFuture future) throws IOException { - if (future.getAndSetStreamWasAlreadyConsumed()) { + if (future.isStreamWasAlreadyConsumed()) { if (is.markSupported()) is.reset(); else { LOGGER.warn("Stream has already been consumed and cannot be reset"); return true; } + } else { + future.setStreamWasAlreadyConsumed(true); } channel.write(new ChunkedStream(is), channel.newProgressivePromise()).addListener(new ProgressListener(config, false, future.getAsyncHandler(), future) { From deb72bdfb9e463adf9da991ce7490dbe4f9dcb81 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 16:05:33 +0200 Subject: [PATCH 0148/2389] Minor clean up --- .../providers/netty/future/NettyResponseFuture.java | 1 + .../providers/netty/handler/HttpProtocol.java | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java index 9e15cc652f..73e3027bc0 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java @@ -66,6 +66,7 @@ public enum STATE { private final CountDownLatch latch = new CountDownLatch(1); // state mutated from outside the event loop + // TODO check if they are indeed mutated outside the event loop private final AtomicBoolean isDone = new AtomicBoolean(false); private final AtomicBoolean isCancelled = new AtomicBoolean(false); private final AtomicInteger redirectCount = new AtomicInteger(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java index 6aa436f40a..a16e2d061a 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -170,7 +170,7 @@ private List getAuthorizationToken(Iterable> list, return l; } - private void finishUpdate(final NettyResponseFuture future, final ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { + private void finishUpdate(final NettyResponseFuture future, ChannelHandlerContext ctx, boolean lastValidChunk) throws IOException { if (lastValidChunk && future.isKeepAlive()) { channels.drainChannel(ctx, future); } else { @@ -183,7 +183,7 @@ private void finishUpdate(final NettyResponseFuture future, final ChannelHand markAsDone(future, ctx); } - private final boolean updateBodyAndInterrupt(final NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { + private final boolean updateBodyAndInterrupt(NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; if (c.closeUnderlyingConnection()) { future.setKeepAlive(false); @@ -191,7 +191,7 @@ private final boolean updateBodyAndInterrupt(final NettyResponseFuture future return state; } - private void markAsDone(final NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { + private void markAsDone(NettyResponseFuture future, final ChannelHandlerContext ctx) throws MalformedURLException { // We need to make sure everything is OK before adding the // connection back to the pool. try { @@ -409,7 +409,6 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu } if (!interrupt && chunk.content().readableBytes() > 0) { - // FIXME why interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(chunk.content(), last)); } From 1cc86aea143a53dbbaafcd3f351fe933fad0ea60 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 16:39:38 +0200 Subject: [PATCH 0149/2389] Remove ListenableFuture.content, close #393 --- .../main/java/org/asynchttpclient/ListenableFuture.java | 7 ------- .../providers/grizzly/GrizzlyResponseFuture.java | 8 -------- .../providers/netty/future/NettyResponseFuture.java | 4 ---- 3 files changed, 19 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/ListenableFuture.java b/api/src/main/java/org/asynchttpclient/ListenableFuture.java index b7593b0e93..04a636229e 100755 --- a/api/src/main/java/org/asynchttpclient/ListenableFuture.java +++ b/api/src/main/java/org/asynchttpclient/ListenableFuture.java @@ -54,13 +54,6 @@ public interface ListenableFuture extends Future { */ void abort(Throwable t); - /** - * Set the content that will be returned by this instance - * - * @param v the content that will be returned by this instance - */ - void content(V v); - /** * Touch the current instance to prevent external service to times out. */ diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java index b53c55fe61..51fcd5c663 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseFuture.java @@ -92,14 +92,6 @@ public void abort(Throwable t) { } - - public void content(V v) { - - delegate.result(v); - - } - - public void touch() { provider.touchConnection(connection, request); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java index 73e3027bc0..2a7868a9ff 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java @@ -323,10 +323,6 @@ public final void abort(final Throwable t) { runListeners(); } - public void content(V v) { - content.set(v); - } - public final Request getRequest() { return request; } From e67638f5cbd081952f1ebdd59d37823631f60c59 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 17:47:49 +0200 Subject: [PATCH 0150/2389] Extract HttpResponseBodyPart creation into a factory so one can chose to bypass auto bytes extraction --- .../asynchttpclient/HttpResponseBodyPart.java | 4 +- .../async/AsyncStreamHandlerTest.java | 2 +- .../grizzly/GrizzlyResponseBodyPart.java | 4 +- .../netty/NettyAsyncHttpProvider.java | 10 +-- .../netty/NettyAsyncHttpProviderConfig.java | 40 +++++++++- .../providers/netty/handler/HttpProtocol.java | 24 +++--- .../netty/handler/NettyChannelHandler.java | 7 +- .../providers/netty/handler/Protocol.java | 5 +- .../netty/handler/WebSocketProtocol.java | 17 +++-- .../response/DefaultResponseBodyPart.java | 66 +++++++++++++++++ .../netty/response/LazyResponseBodyPart.java | 73 +++++++++++++++++++ .../netty/response/ResponseBodyPart.java | 52 ++----------- .../providers/netty/util/ByteBufUtil.java | 43 +++++++++-- 13 files changed, 259 insertions(+), 88 deletions(-) create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/DefaultResponseBodyPart.java create mode 100644 providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/LazyResponseBodyPart.java diff --git a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java index 42bb8c8158..173f4d384a 100644 --- a/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java +++ b/api/src/main/java/org/asynchttpclient/HttpResponseBodyPart.java @@ -75,13 +75,13 @@ public abstract class HttpResponseBodyPart { * underlying TCP connection will be closed as soon as the processing of the response is completed. That * means the underlying connection will never get pooled. */ - public abstract void markUnderlyingConnectionAsClosed(); + public abstract void markUnderlyingConnectionAsToBeClosed(); /** * Return true of the underlying connection will be closed once the response has been fully processed. * * @return true of the underlying connection will be closed once the response has been fully processed. */ - public abstract boolean closeUnderlyingConnection(); + public abstract boolean isUnderlyingConnectionToBeClosed(); } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index 1d31d21ac7..7147487156 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -546,7 +546,7 @@ public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception { builder.accumulate(content); if (content.isLast()) { - content.markUnderlyingConnectionAsClosed(); + content.markUnderlyingConnectionAsToBeClosed(); } return STATE.CONTINUE; } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java index 4f2236e321..b010cd3c3d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java @@ -122,7 +122,7 @@ public boolean isLast() { * {@inheritDoc} */ @Override - public void markUnderlyingConnectionAsClosed() { + public void markUnderlyingConnectionAsToBeClosed() { ConnectionManager.markConnectionAsDoNotCache(connection); } @@ -130,7 +130,7 @@ public void markUnderlyingConnectionAsClosed() { * {@inheritDoc} */ @Override - public boolean closeUnderlyingConnection() { + public boolean isUnderlyingConnectionToBeClosed() { return !ConnectionManager.isConnectionCacheable(connection); } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index f8348abde6..d67821c497 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -34,7 +34,7 @@ public class NettyAsyncHttpProvider implements AsyncHttpProvider { private static final Logger LOGGER = LoggerFactory.getLogger(NettyAsyncHttpProvider.class); private final AsyncHttpClientConfig config; - private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; + private final NettyAsyncHttpProviderConfig nettyConfig; private final AtomicBoolean closed = new AtomicBoolean(false); private final Channels channels; private final NettyRequestSender requestSender; @@ -43,13 +43,13 @@ public class NettyAsyncHttpProvider implements AsyncHttpProvider { public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { this.config = config; - asyncHttpProviderConfig = config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig ? // + nettyConfig = config.getAsyncHttpProviderConfig() instanceof NettyAsyncHttpProviderConfig ? // NettyAsyncHttpProviderConfig.class.cast(config.getAsyncHttpProviderConfig()) : new NettyAsyncHttpProviderConfig(); - channels = new Channels(config, asyncHttpProviderConfig); + channels = new Channels(config, nettyConfig); requestSender = new NettyRequestSender(closed, config, channels); - channelHandler = new NettyChannelHandler(config, requestSender, channels, closed); + channelHandler = new NettyChannelHandler(config, nettyConfig, requestSender, channels, closed); channels.configure(channelHandler); } @@ -72,6 +72,6 @@ public void close() { @Override public ListenableFuture execute(Request request, final AsyncHandler asyncHandler) throws IOException { - return requestSender.sendRequest(request, asyncHandler, null, asyncHttpProviderConfig.isAsyncConnect(), false); + return requestSender.sendRequest(request, asyncHandler, null, nettyConfig.isAsyncConnect(), false); } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java index 210f1dc8a9..da6af380e2 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java @@ -16,6 +16,7 @@ */ package org.asynchttpclient.providers.netty; +import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; @@ -25,6 +26,10 @@ import java.util.Set; import org.asynchttpclient.AsyncHttpProviderConfig; +import org.asynchttpclient.providers.netty.response.DefaultResponseBodyPart; +import org.asynchttpclient.providers.netty.response.LazyResponseBodyPart; +import org.asynchttpclient.providers.netty.response.ResponseBodyPart; +import org.asynchttpclient.providers.netty.util.ByteBufUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +49,7 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig properties = new HashMap(); + private ResponseBodyPartFactory bodyPartFactory = new DefaultResponseBodyPartFactory(); + public NettyAsyncHttpProviderConfig() { properties.put(REUSE_ADDRESS, Boolean.FALSE); } @@ -219,9 +226,38 @@ public AdditionalChannelInitializer getWssAdditionalChannelInitializer() { public void setWssAdditionalChannelInitializer(AdditionalChannelInitializer wssAdditionalChannelInitializer) { this.wssAdditionalChannelInitializer = wssAdditionalChannelInitializer; } - + + public ResponseBodyPartFactory getBodyPartFactory() { + return bodyPartFactory; + } + + public void setBodyPartFactory(ResponseBodyPartFactory bodyPartFactory) { + this.bodyPartFactory = bodyPartFactory; + } + public static interface AdditionalChannelInitializer { void initChannel(Channel ch) throws Exception; } + + public static interface ResponseBodyPartFactory { + + ResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last); + } + + public static class DefaultResponseBodyPartFactory implements ResponseBodyPartFactory { + + @Override + public ResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) { + return new DefaultResponseBodyPart(ByteBufUtil.byteBuf2Bytes(buf), last); + } + } + + public static class LazyResponseBodyPartFactory implements ResponseBodyPartFactory { + + @Override + public ResponseBodyPart newResponseBodyPart(ByteBuf buf, boolean last) { + return new LazyResponseBodyPart(buf, last); + } + } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java index a16e2d061a..a595e98cbb 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/HttpProtocol.java @@ -16,7 +16,8 @@ package org.asynchttpclient.providers.netty.handler; import static io.netty.handler.codec.http.HttpResponseStatus.*; -import static org.asynchttpclient.providers.netty.util.HttpUtil.isNTLM; +import static org.asynchttpclient.providers.netty.util.HttpUtil.*; +import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpHeaders; @@ -33,6 +34,7 @@ import java.util.Map.Entry; import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHandler.STATE; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.HttpResponseBodyPart; @@ -42,26 +44,25 @@ import org.asynchttpclient.Realm; import org.asynchttpclient.Request; import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.AsyncHandler.STATE; import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.ResponseFilter; import org.asynchttpclient.ntlm.NTLMEngine; import org.asynchttpclient.ntlm.NTLMEngineException; -import org.asynchttpclient.spnego.SpnegoEngine; import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; import org.asynchttpclient.providers.netty.channel.Channels; import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.asynchttpclient.providers.netty.request.NettyRequestSender; -import org.asynchttpclient.providers.netty.response.ResponseBodyPart; import org.asynchttpclient.providers.netty.response.ResponseHeaders; import org.asynchttpclient.providers.netty.response.ResponseStatus; +import org.asynchttpclient.spnego.SpnegoEngine; import org.asynchttpclient.util.AsyncHttpProviderUtils; final class HttpProtocol extends Protocol { - public HttpProtocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { - super(channels, config, requestSender); + public HttpProtocol(Channels channels, AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, NettyRequestSender requestSender) { + super(channels, config, nettyConfig, requestSender); } private Realm kerberosChallenge(List proxyAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, Realm realm, @@ -183,9 +184,9 @@ private void finishUpdate(final NettyResponseFuture future, ChannelHandlerCon markAsDone(future, ctx); } - private final boolean updateBodyAndInterrupt(NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart c) throws Exception { - boolean state = handler.onBodyPartReceived(c) != STATE.CONTINUE; - if (c.closeUnderlyingConnection()) { + private final boolean updateBodyAndInterrupt(NettyResponseFuture future, AsyncHandler handler, HttpResponseBodyPart bodyPart) throws Exception { + boolean state = handler.onBodyPartReceived(bodyPart) != STATE.CONTINUE; + if (bodyPart.isUnderlyingConnectionToBeClosed()) { future.setKeepAlive(false); } return state; @@ -408,8 +409,9 @@ public void handle(final ChannelHandlerContext ctx, final NettyResponseFuture fu } } - if (!interrupt && chunk.content().readableBytes() > 0) { - interrupt = updateBodyAndInterrupt(future, handler, new ResponseBodyPart(chunk.content(), last)); + ByteBuf buf = chunk.content(); + if (!interrupt && buf.readableBytes() > 0) { + interrupt = updateBodyAndInterrupt(future, handler, nettyConfig.getBodyPartFactory().newResponseBodyPart(buf, last)); } if (interrupt || last) { diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java index fb47346455..03f68ae246 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java @@ -30,6 +30,7 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.providers.netty.Callback; import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; import org.asynchttpclient.providers.netty.channel.Channels; import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.asynchttpclient.providers.netty.future.NettyResponseFutures; @@ -49,13 +50,13 @@ public class NettyChannelHandler extends ChannelInboundHandlerAdapter { private final Protocol httpProtocol; private final Protocol webSocketProtocol; - public NettyChannelHandler(AsyncHttpClientConfig config, NettyRequestSender requestSender, Channels channels, AtomicBoolean isClose) { + public NettyChannelHandler(AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, NettyRequestSender requestSender, Channels channels, AtomicBoolean isClose) { this.config = config; this.requestSender = requestSender; this.channels = channels; this.closed = isClose; - httpProtocol = new HttpProtocol(channels, config, requestSender); - webSocketProtocol = new WebSocketProtocol(channels, config, requestSender); + httpProtocol = new HttpProtocol(channels, config, nettyConfig, requestSender); + webSocketProtocol = new WebSocketProtocol(channels, config, nettyConfig, requestSender); } @Override diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java index dcd456f41d..500a2bc729 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java @@ -28,6 +28,7 @@ import org.asynchttpclient.RequestBuilder; import org.asynchttpclient.org.jboss.netty.handler.codec.http.CookieDecoder; import org.asynchttpclient.providers.netty.Callback; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; import org.asynchttpclient.providers.netty.channel.Channels; import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.asynchttpclient.providers.netty.request.NettyRequestSender; @@ -42,10 +43,12 @@ public abstract class Protocol { protected final Channels channels; protected final AsyncHttpClientConfig config; protected final NettyRequestSender requestSender; + protected final NettyAsyncHttpProviderConfig nettyConfig; - public Protocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { + public Protocol(Channels channels, AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, NettyRequestSender requestSender) { this.channels = channels; this.config = config; + this.nettyConfig = nettyConfig; this.requestSender = requestSender; } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java index 103a677abd..07c59b9e64 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/WebSocketProtocol.java @@ -15,7 +15,8 @@ */ package org.asynchttpclient.providers.netty.handler; -import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS; +import static io.netty.handler.codec.http.HttpResponseStatus.*; +import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpResponse; @@ -27,16 +28,17 @@ import java.io.IOException; +import org.asynchttpclient.AsyncHandler.STATE; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.HttpResponseHeaders; import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.Request; -import org.asynchttpclient.AsyncHandler.STATE; import org.asynchttpclient.filter.FilterContext; import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.ResponseFilter; import org.asynchttpclient.providers.netty.Constants; import org.asynchttpclient.providers.netty.DiscardEvent; +import org.asynchttpclient.providers.netty.NettyAsyncHttpProviderConfig; import org.asynchttpclient.providers.netty.channel.Channels; import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.asynchttpclient.providers.netty.request.NettyRequestSender; @@ -54,8 +56,8 @@ final class WebSocketProtocol extends Protocol { private static final byte OPCODE_UNKNOWN = -1; protected byte pendingOpcode = OPCODE_UNKNOWN; - public WebSocketProtocol(Channels channels, AsyncHttpClientConfig config, NettyRequestSender requestSender) { - super(channels, config, requestSender); + public WebSocketProtocol(Channels channels, AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig nettyConfig, NettyRequestSender requestSender) { + super(channels, config, nettyConfig, requestSender); } // We don't need to synchronize as replacing the "ws-decoder" will @@ -154,14 +156,15 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object pendingOpcode = OPCODE_BINARY; } - if (frame.content() != null && frame.content().readableBytes() > 0) { - ResponseBodyPart rp = new ResponseBodyPart(frame.content(), frame.isFinalFragment()); + ByteBuf buf = frame.content(); + if (buf != null && buf.readableBytes() > 0) { + ResponseBodyPart rp = nettyConfig.getBodyPartFactory().newResponseBodyPart(buf, frame.isFinalFragment()); h.onBodyPartReceived(rp); if (pendingOpcode == OPCODE_BINARY) { webSocket.onBinaryFragment(rp.getBodyPartBytes(), frame.isFinalFragment()); } else { - webSocket.onTextFragment(frame.content().toString(Constants.UTF8), frame.isFinalFragment()); + webSocket.onTextFragment(buf.toString(Constants.UTF8), frame.isFinalFragment()); } } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/DefaultResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/DefaultResponseBodyPart.java new file mode 100644 index 0000000000..80cc12396b --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/DefaultResponseBodyPart.java @@ -0,0 +1,66 @@ +/* + * Copyright 2010 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.response; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +/** + * A callback class used when an HTTP response body is received. + */ +public class DefaultResponseBodyPart extends ResponseBodyPart { + + private final byte[] bytes; + + public DefaultResponseBodyPart(byte[] bytes, boolean last) { + super(last); + this.bytes = bytes; + } + + /** + * Return the response body's part bytes received. + * + * @return the response body's part bytes received. + */ + @Override + public byte[] getBodyPartBytes() { + return bytes; + } + + @Override + public InputStream readBodyPartBytes() { + return new ByteArrayInputStream(bytes); + } + + @Override + public int length() { + return bytes.length; + } + + @Override + public int writeTo(OutputStream outputStream) throws IOException { + outputStream.write(bytes); + return length(); + } + + @Override + public ByteBuffer getBodyByteBuffer() { + return ByteBuffer.wrap(bytes); + } +} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/LazyResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/LazyResponseBodyPart.java new file mode 100644 index 0000000000..eae64b291a --- /dev/null +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/LazyResponseBodyPart.java @@ -0,0 +1,73 @@ +/* + * Copyright 2010 Ning, Inc. + * + * Ning 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. + */ +package org.asynchttpclient.providers.netty.response; + +import io.netty.buffer.ByteBuf; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +/** + * A callback class used when an HTTP response body is received. + */ +public class LazyResponseBodyPart extends ResponseBodyPart { + + private static final String ERROR_MESSAGE = "This implementation is intended for one to directly read from the underlying ByteBuf and release after usage. Not for the fainted heart!"; + + private final ByteBuf buf; + + public LazyResponseBodyPart(ByteBuf buf, boolean last) { + super(last); + buf.retain(); + this.buf = buf; + } + + public ByteBuf getBuf() { + return buf; + } + + /** + * Return the response body's part bytes received. + * + * @return the response body's part bytes received. + */ + @Override + public byte[] getBodyPartBytes() { + throw new UnsupportedOperationException(ERROR_MESSAGE); + } + + @Override + public InputStream readBodyPartBytes() { + throw new UnsupportedOperationException(ERROR_MESSAGE); + } + + @Override + public int length() { + throw new UnsupportedOperationException(ERROR_MESSAGE); + } + + @Override + public int writeTo(OutputStream outputStream) throws IOException { + throw new UnsupportedOperationException(ERROR_MESSAGE); + } + + @Override + public ByteBuffer getBodyByteBuffer() { + throw new UnsupportedOperationException(ERROR_MESSAGE); + } +} diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java index 5248c64d7d..749433d5c6 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/ResponseBodyPart.java @@ -15,62 +15,20 @@ */ package org.asynchttpclient.providers.netty.response; -import io.netty.buffer.ByteBuf; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; - import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.providers.netty.util.ByteBufUtil; /** * A callback class used when an HTTP response body is received. */ -public class ResponseBodyPart extends HttpResponseBodyPart { +public abstract class ResponseBodyPart extends HttpResponseBodyPart { - private final byte[] bytes; private final boolean last; - private boolean closeConnection = false; + private boolean closeConnection; - public ResponseBodyPart(ByteBuf buf, boolean last) { - bytes = ByteBufUtil.byteBuf2bytes(buf); + public ResponseBodyPart(boolean last) { this.last = last; } - /** - * Return the response body's part bytes received. - * - * @return the response body's part bytes received. - */ - @Override - public byte[] getBodyPartBytes() { - return bytes; - } - - @Override - public InputStream readBodyPartBytes() { - return new ByteArrayInputStream(bytes); - } - - @Override - public int length() { - return bytes.length; - } - - @Override - public int writeTo(OutputStream outputStream) throws IOException { - outputStream.write(bytes); - return length(); - } - - @Override - public ByteBuffer getBodyByteBuffer() { - return ByteBuffer.wrap(bytes); - } - /** * {@inheritDoc} */ @@ -83,7 +41,7 @@ public boolean isLast() { * {@inheritDoc} */ @Override - public void markUnderlyingConnectionAsClosed() { + public void markUnderlyingConnectionAsToBeClosed() { closeConnection = true; } @@ -91,7 +49,7 @@ public void markUnderlyingConnectionAsClosed() { * {@inheritDoc} */ @Override - public boolean closeUnderlyingConnection() { + public boolean isUnderlyingConnectionToBeClosed() { return closeConnection; } } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java index fa64563e70..e6998fca21 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/util/ByteBufUtil.java @@ -17,19 +17,48 @@ import io.netty.buffer.ByteBuf; +import java.util.List; + public class ByteBufUtil { - public static byte[] byteBuf2bytes(ByteBuf b) { - int readable = b.readableBytes(); - int readerIndex = b.readerIndex(); - if (b.hasArray()) { - byte[] array = b.array(); - if (b.arrayOffset() == 0 && readerIndex == 0 && array.length == readable) { + public static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; + + public static byte[] byteBuf2Bytes(ByteBuf buf) { + int readable = buf.readableBytes(); + int readerIndex = buf.readerIndex(); + if (buf.hasArray()) { + byte[] array = buf.array(); + if (buf.arrayOffset() == 0 && readerIndex == 0 && array.length == readable) { return array; } } byte[] array = new byte[readable]; - b.getBytes(readerIndex, array); + buf.getBytes(readerIndex, array); return array; } + + public static byte[] byteBufs2Bytes(List bufs) { + + if (bufs.isEmpty()) { + return EMPTY_BYTE_ARRAY; + + } else if (bufs.size() == 1) { + return byteBuf2Bytes(bufs.get(0)); + + } else { + int totalSize = 0; + for (ByteBuf buf : bufs) { + totalSize += buf.readableBytes(); + } + + byte[] bytes = new byte[totalSize]; + int offset = 0; + for (ByteBuf buf : bufs) { + int readable = buf.readableBytes(); + buf.getBytes(buf.readerIndex(), bytes, offset, readable); + offset += readable; + } + return bytes; + } + } } From 51f6ec2e213feee90d085cbb12e620c01934e053 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 17:56:57 +0200 Subject: [PATCH 0151/2389] Fix test: should define a provider --- .../SimpleAsyncClientErrorBehaviourTest.java | 21 +++++-------- ...lySimpleAsyncClientErrorBehaviourTest.java | 30 +++++++++++++++++++ .../GrizzlySimpleAsyncHttpClientTest.java | 9 ------ ...tySimpleAsyncClientErrorBehaviourTest.java | 30 +++++++++++++++++++ 4 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncClientErrorBehaviourTest.java create mode 100644 providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java diff --git a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java index 76dac21427..b359058ac0 100644 --- a/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java +++ b/api/src/test/java/org/asynchttpclient/async/SimpleAsyncClientErrorBehaviourTest.java @@ -22,25 +22,24 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.testng.annotations.Test; - -import org.asynchttpclient.AsyncHttpClient; -import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Response; import org.asynchttpclient.SimpleAsyncHttpClient; import org.asynchttpclient.SimpleAsyncHttpClient.ErrorDocumentBehaviour; import org.asynchttpclient.consumers.OutputStreamBodyConsumer; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.testng.annotations.Test; /** * @author Benjamin Hanzelmann * */ -public class SimpleAsyncClientErrorBehaviourTest extends AbstractBasicTest { +public abstract class SimpleAsyncClientErrorBehaviourTest extends AbstractBasicTest { + + public abstract String getProviderClass(); @Test(groups = { "standalone", "default_provider" }) public void testAccumulateErrorBody() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.ACCUMULATE).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.ACCUMULATE).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.get(new OutputStreamBodyConsumer(o)); @@ -57,7 +56,7 @@ public void testAccumulateErrorBody() throws Exception { @Test(groups = { "standalone", "default_provider" }) public void testOmitErrorBody() throws Exception { - SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.OMIT).build(); + SimpleAsyncHttpClient client = new SimpleAsyncHttpClient.Builder().setProviderClass(getProviderClass()).setUrl(getTargetUrl() + "/nonexistent").setErrorDocumentBehaviour(ErrorDocumentBehaviour.OMIT).build(); try { ByteArrayOutputStream o = new ByteArrayOutputStream(10); Future future = client.get(new OutputStreamBodyConsumer(o)); @@ -72,12 +71,6 @@ public void testOmitErrorBody() throws Exception { } } - @Override - public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { - // disabled - return null; - } - @Override public AbstractHandler configureHandler() throws Exception { return new AbstractHandler() { diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncClientErrorBehaviourTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncClientErrorBehaviourTest.java new file mode 100644 index 0000000000..db9a6a1579 --- /dev/null +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncClientErrorBehaviourTest.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.grizzly; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.async.SimpleAsyncClientErrorBehaviourTest; + +public class GrizzlySimpleAsyncClientErrorBehaviourTest extends SimpleAsyncClientErrorBehaviourTest { + + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return GrizzlyProviderUtil.grizzlyProvider(config); + } + + public String getProviderClass() { + return GrizzlyAsyncHttpProvider.class.getName(); + } +} diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java index af99dd39fb..dbd541b93b 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlySimpleAsyncHttpClientTest.java @@ -13,18 +13,10 @@ package org.asynchttpclient.providers.grizzly; -import org.asynchttpclient.AsyncCompletionHandler; -import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.Request; -import org.asynchttpclient.RequestBuilder; -import org.asynchttpclient.Response; import org.asynchttpclient.async.SimpleAsyncHttpClientTest; -import java.io.IOException; -import java.util.concurrent.Future; - public class GrizzlySimpleAsyncHttpClientTest extends SimpleAsyncHttpClientTest { @Override @@ -35,5 +27,4 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return GrizzlyAsyncHttpProvider.class.getName(); } - } diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java new file mode 100644 index 0000000000..830e721d0d --- /dev/null +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2012 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ + +package org.asynchttpclient.providers.netty; + +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.async.SimpleAsyncClientErrorBehaviourTest; + +public class NettySimpleAsyncClientErrorBehaviourTest extends SimpleAsyncClientErrorBehaviourTest { + + @Override + public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { + return NettyProviderUtil.nettyProvider(config); + } + + public String getProviderClass() { + return NettyProviderUtil.class.getName(); + } +} From 937bc35035dbdadda120e0dc3c1218f8faaf23bc Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 18:13:14 +0200 Subject: [PATCH 0152/2389] Doh! --- .../netty/NettySimpleAsyncClientErrorBehaviourTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java index 830e721d0d..c57b8b89d4 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettySimpleAsyncClientErrorBehaviourTest.java @@ -25,6 +25,6 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { } public String getProviderClass() { - return NettyProviderUtil.class.getName(); + return NettyAsyncHttpProvider.class.getName(); } } From 2deeffba2284bc362e0e1d0a973c6ee279823fb9 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 2 Oct 2013 22:51:25 +0200 Subject: [PATCH 0153/2389] No need to synchronize ResponseBuilder. bodyParts --- api/src/main/java/org/asynchttpclient/Response.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/Response.java b/api/src/main/java/org/asynchttpclient/Response.java index e8598013f4..bfb96bec5c 100644 --- a/api/src/main/java/org/asynchttpclient/Response.java +++ b/api/src/main/java/org/asynchttpclient/Response.java @@ -22,7 +22,6 @@ import java.net.URI; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -183,7 +182,7 @@ public interface Response { boolean hasResponseBody(); public static class ResponseBuilder { - private final List bodyParts = Collections.synchronizedList(new ArrayList()); + private final List bodyParts = new ArrayList(); private HttpResponseStatus status; private HttpResponseHeaders headers; From 3345697849c9265ecc311942e041f24b90388aed Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 3 Oct 2013 09:26:40 +0200 Subject: [PATCH 0154/2389] Uncomment @Override as AHC targets JDK6 --- .../AsyncCompletionHandlerBase.java | 2 +- .../org/asynchttpclient/ByteArrayPart.java | 2 +- .../FluentCaseInsensitiveStringsMap.java | 26 +++---- .../org/asynchttpclient/FluentStringsMap.java | 26 +++---- .../java/org/asynchttpclient/StringPart.java | 2 +- .../consumers/AppendableBodyConsumer.java | 4 +- .../consumers/ByteBufferBodyConsumer.java | 4 +- .../consumers/FileBodyConsumer.java | 8 +-- .../consumers/OutputStreamBodyConsumer.java | 4 +- .../extra/AsyncHandlerWrapper.java | 10 +-- .../extra/ThrottleRequestFilter.java | 2 +- .../generators/ByteArrayBodyGenerator.java | 2 +- .../generators/FileBodyGenerator.java | 2 +- .../generators/InputStreamBodyGenerator.java | 2 +- .../providers/ResponseBase.java | 70 +++++++++---------- .../PropertiesBasedResumableProcessor.java | 6 +- .../resumable/ResumableAsyncHandler.java | 10 +-- .../webdav/WebDavCompletionHandlerBase.java | 10 +-- .../webdav/WebDavResponse.java | 2 +- .../async/AsyncStreamHandlerTest.java | 10 +-- .../async/ByteBufferCapacityTest.java | 2 +- .../async/ConnectionPoolTest.java | 2 +- .../async/HostnameVerifierTest.java | 2 +- .../async/PostRedirectGetTest.java | 6 +- .../asynchttpclient/async/PostWithQSTest.java | 6 +- .../async/WebDavBasicTest.java | 2 +- .../netty/response/NettyResponse.java | 12 ++-- 27 files changed, 118 insertions(+), 118 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java b/api/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java index c98ee94507..cd5f0a6087 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java +++ b/api/src/main/java/org/asynchttpclient/AsyncCompletionHandlerBase.java @@ -36,7 +36,7 @@ public Response onCompleted(Response response) throws Exception { /** * {@inheritDoc} */ - /* @Override */ + @Override public void onThrowable(Throwable t) { log.debug(t.getMessage(), t); } diff --git a/api/src/main/java/org/asynchttpclient/ByteArrayPart.java b/api/src/main/java/org/asynchttpclient/ByteArrayPart.java index 87311f0f1b..3ed4d6e314 100644 --- a/api/src/main/java/org/asynchttpclient/ByteArrayPart.java +++ b/api/src/main/java/org/asynchttpclient/ByteArrayPart.java @@ -34,7 +34,7 @@ public ByteArrayPart(String name, String fileName, byte[] data, String mimeType, /** * {@inheritDoc} */ - /* @Override */ + @Override public String getName() { return name; } diff --git a/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java b/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java index 6e948c4d75..77a9e4e20f 100644 --- a/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java +++ b/api/src/main/java/org/asynchttpclient/FluentCaseInsensitiveStringsMap.java @@ -232,7 +232,7 @@ public FluentCaseInsensitiveStringsMap replaceAll(Map put(String key, List value) { if (key == null) { throw new NullPointerException("Null keys are not allowed"); @@ -247,7 +247,7 @@ public List put(String key, List value) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void putAll(Map> values) { replaceAll(values); } @@ -303,7 +303,7 @@ public FluentCaseInsensitiveStringsMap deleteAll(Collection keys) { /** * {@inheritDoc} */ - /* @Override */ + @Override public List remove(Object key) { if (key == null) { return null; @@ -318,7 +318,7 @@ public List remove(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void clear() { keyLookup.clear(); values.clear(); @@ -327,7 +327,7 @@ public void clear() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Iterator>> iterator() { return Collections.unmodifiableSet(values.entrySet()).iterator(); } @@ -335,7 +335,7 @@ public Iterator>> iterator() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Set keySet() { return new LinkedHashSet(keyLookup.values()); } @@ -343,7 +343,7 @@ public Set keySet() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Set>> entrySet() { return values.entrySet(); } @@ -351,7 +351,7 @@ public Set>> entrySet() { /** * {@inheritDoc} */ - /* @Override */ + @Override public int size() { return values.size(); } @@ -359,7 +359,7 @@ public int size() { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean isEmpty() { return values.isEmpty(); } @@ -367,7 +367,7 @@ public boolean isEmpty() { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean containsKey(Object key) { return key == null ? false : keyLookup.containsKey(key.toString().toLowerCase(Locale.ENGLISH)); } @@ -375,7 +375,7 @@ public boolean containsKey(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean containsValue(Object value) { return values.containsValue(value); } @@ -428,7 +428,7 @@ public String getJoinedValue(String key, String delimiter) { /** * {@inheritDoc} */ - /* @Override */ + @Override public List get(Object key) { if (key == null) { return null; @@ -447,7 +447,7 @@ public List get(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public Collection> values() { return values.values(); } diff --git a/api/src/main/java/org/asynchttpclient/FluentStringsMap.java b/api/src/main/java/org/asynchttpclient/FluentStringsMap.java index 2001413e18..336ffbbc97 100644 --- a/api/src/main/java/org/asynchttpclient/FluentStringsMap.java +++ b/api/src/main/java/org/asynchttpclient/FluentStringsMap.java @@ -184,7 +184,7 @@ public FluentStringsMap replaceAll(Map put(String key, List value) { if (key == null) { throw new NullPointerException("Null keys are not allowed"); @@ -199,7 +199,7 @@ public List put(String key, List value) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void putAll(Map> values) { replaceAll(values); } @@ -248,7 +248,7 @@ public FluentStringsMap deleteAll(Collection keys) { /** * {@inheritDoc} */ - /* @Override */ + @Override public List remove(Object key) { if (key == null) { return null; @@ -263,7 +263,7 @@ public List remove(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void clear() { values.clear(); } @@ -271,7 +271,7 @@ public void clear() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Iterator>> iterator() { return Collections.unmodifiableSet(values.entrySet()).iterator(); } @@ -279,7 +279,7 @@ public Iterator>> iterator() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Set keySet() { return Collections.unmodifiableSet(values.keySet()); } @@ -287,7 +287,7 @@ public Set keySet() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Set>> entrySet() { return values.entrySet(); } @@ -295,7 +295,7 @@ public Set>> entrySet() { /** * {@inheritDoc} */ - /* @Override */ + @Override public int size() { return values.size(); } @@ -303,7 +303,7 @@ public int size() { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean isEmpty() { return values.isEmpty(); } @@ -311,7 +311,7 @@ public boolean isEmpty() { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean containsKey(Object key) { return key == null ? false : values.containsKey(key.toString()); } @@ -319,7 +319,7 @@ public boolean containsKey(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public boolean containsValue(Object value) { return values.containsValue(value); } @@ -372,7 +372,7 @@ public String getJoinedValue(String key, String delimiter) { /** * {@inheritDoc} */ - /* @Override */ + @Override public List get(Object key) { if (key == null) { return null; @@ -384,7 +384,7 @@ public List get(Object key) { /** * {@inheritDoc} */ - /* @Override */ + @Override public Collection> values() { return values.values(); } diff --git a/api/src/main/java/org/asynchttpclient/StringPart.java b/api/src/main/java/org/asynchttpclient/StringPart.java index cd0c617c55..5323a67528 100644 --- a/api/src/main/java/org/asynchttpclient/StringPart.java +++ b/api/src/main/java/org/asynchttpclient/StringPart.java @@ -39,7 +39,7 @@ public StringPart(String name, String value) { /** * {@inheritDoc} */ - /* @Override */ + @Override public String getName() { return name; } diff --git a/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java b/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java index 4ddbde6f84..2f80f3428e 100644 --- a/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java +++ b/api/src/main/java/org/asynchttpclient/consumers/AppendableBodyConsumer.java @@ -39,7 +39,7 @@ public AppendableBodyConsumer(Appendable appendable) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void consume(ByteBuffer byteBuffer) throws IOException { appendable.append(new String(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), @@ -50,7 +50,7 @@ public void consume(ByteBuffer byteBuffer) throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public void close() throws IOException { if (appendable instanceof Closeable) { Closeable.class.cast(appendable).close(); diff --git a/api/src/main/java/org/asynchttpclient/consumers/ByteBufferBodyConsumer.java b/api/src/main/java/org/asynchttpclient/consumers/ByteBufferBodyConsumer.java index 8ab4641220..a8b4c748e9 100644 --- a/api/src/main/java/org/asynchttpclient/consumers/ByteBufferBodyConsumer.java +++ b/api/src/main/java/org/asynchttpclient/consumers/ByteBufferBodyConsumer.java @@ -31,7 +31,7 @@ public ByteBufferBodyConsumer(ByteBuffer byteBuffer) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void consume(ByteBuffer byteBuffer) throws IOException { byteBuffer.put(byteBuffer); } @@ -39,7 +39,7 @@ public void consume(ByteBuffer byteBuffer) throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public void close() throws IOException { byteBuffer.flip(); } diff --git a/api/src/main/java/org/asynchttpclient/consumers/FileBodyConsumer.java b/api/src/main/java/org/asynchttpclient/consumers/FileBodyConsumer.java index 531228bccb..8c5660b80b 100644 --- a/api/src/main/java/org/asynchttpclient/consumers/FileBodyConsumer.java +++ b/api/src/main/java/org/asynchttpclient/consumers/FileBodyConsumer.java @@ -32,7 +32,7 @@ public FileBodyConsumer(RandomAccessFile file) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void consume(ByteBuffer byteBuffer) throws IOException { // TODO: Channel.transferFrom may be a good idea to investigate. file.write(byteBuffer.array(), @@ -43,7 +43,7 @@ public void consume(ByteBuffer byteBuffer) throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public void close() throws IOException { file.close(); } @@ -51,7 +51,7 @@ public void close() throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public long getTransferredBytes() throws IOException { return file.length(); } @@ -59,7 +59,7 @@ public long getTransferredBytes() throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public void resume() throws IOException { file.seek(getTransferredBytes()); } diff --git a/api/src/main/java/org/asynchttpclient/consumers/OutputStreamBodyConsumer.java b/api/src/main/java/org/asynchttpclient/consumers/OutputStreamBodyConsumer.java index 7ab4d1184b..15f18ca0cc 100644 --- a/api/src/main/java/org/asynchttpclient/consumers/OutputStreamBodyConsumer.java +++ b/api/src/main/java/org/asynchttpclient/consumers/OutputStreamBodyConsumer.java @@ -32,7 +32,7 @@ public OutputStreamBodyConsumer(OutputStream outputStream) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void consume(ByteBuffer byteBuffer) throws IOException { outputStream.write(byteBuffer.array(), byteBuffer.arrayOffset() + byteBuffer.position(), @@ -42,7 +42,7 @@ public void consume(ByteBuffer byteBuffer) throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public void close() throws IOException { outputStream.close(); } diff --git a/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java b/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java index fcbce72bc4..a330dd00b2 100644 --- a/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java +++ b/api/src/main/java/org/asynchttpclient/extra/AsyncHandlerWrapper.java @@ -23,7 +23,7 @@ public AsyncHandlerWrapper(AsyncHandler asyncHandler, Semaphore available) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void onThrowable(Throwable t) { try { asyncHandler.onThrowable(t); @@ -38,7 +38,7 @@ public void onThrowable(Throwable t) { /** * {@inheritDoc} */ - /* @Override */ + @Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { return asyncHandler.onBodyPartReceived(bodyPart); } @@ -46,7 +46,7 @@ public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception /** * {@inheritDoc} */ - /* @Override */ + @Override public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception { return asyncHandler.onStatusReceived(responseStatus); } @@ -54,7 +54,7 @@ public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio /** * {@inheritDoc} */ - /* @Override */ + @Override public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { return asyncHandler.onHeadersReceived(headers); } @@ -62,7 +62,7 @@ public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { /** * {@inheritDoc} */ - /* @Override */ + @Override public T onCompleted() throws Exception { available.release(); if (logger.isDebugEnabled()) { diff --git a/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java b/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java index 2dcb6087e2..186547b168 100644 --- a/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java +++ b/api/src/main/java/org/asynchttpclient/extra/ThrottleRequestFilter.java @@ -42,7 +42,7 @@ public ThrottleRequestFilter(int maxConnections, int maxWait) { /** * {@inheritDoc} */ - /* @Override */ + @Override public FilterContext filter(FilterContext ctx) throws FilterException { try { diff --git a/api/src/main/java/org/asynchttpclient/generators/ByteArrayBodyGenerator.java b/api/src/main/java/org/asynchttpclient/generators/ByteArrayBodyGenerator.java index 0ff4a346e6..f1e0a97752 100644 --- a/api/src/main/java/org/asynchttpclient/generators/ByteArrayBodyGenerator.java +++ b/api/src/main/java/org/asynchttpclient/generators/ByteArrayBodyGenerator.java @@ -64,7 +64,7 @@ public void close() throws IOException { /** * {@inheritDoc} */ - /* @Override */ + @Override public Body createBody() throws IOException { return new ByteBody(); } diff --git a/api/src/main/java/org/asynchttpclient/generators/FileBodyGenerator.java b/api/src/main/java/org/asynchttpclient/generators/FileBodyGenerator.java index dd6e88dbf9..7f412be62a 100644 --- a/api/src/main/java/org/asynchttpclient/generators/FileBodyGenerator.java +++ b/api/src/main/java/org/asynchttpclient/generators/FileBodyGenerator.java @@ -53,7 +53,7 @@ public FileBodyGenerator(File file, long regionSeek, long regionLength) { /** * {@inheritDoc} */ - /* @Override */ + @Override public RandomAccessBody createBody() throws IOException { return new FileBody(file, regionSeek, regionLength); diff --git a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java index fcb2176854..4a72f9a1ac 100644 --- a/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java +++ b/api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java @@ -54,7 +54,7 @@ public InputStream getInputStream() { /** * {@inheritDoc} */ - /* @Override */ + @Override public Body createBody() throws IOException { return new ISBody(); } diff --git a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java index b7f4dfd410..2a96b2880b 100644 --- a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java +++ b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java @@ -17,8 +17,7 @@ import org.asynchttpclient.Response; import org.asynchttpclient.util.AsyncHttpProviderUtils; -public abstract class ResponseBase implements Response -{ +public abstract class ResponseBase implements Response { protected final static String DEFAULT_CHARSET = "ISO-8859-1"; protected final List bodyParts; @@ -26,56 +25,65 @@ public abstract class ResponseBase implements Response protected final HttpResponseStatus status; private List cookies; - protected ResponseBase(HttpResponseStatus status, - HttpResponseHeaders headers, - List bodyParts) - { + protected ResponseBase(HttpResponseStatus status, HttpResponseHeaders headers, List bodyParts) { this.bodyParts = bodyParts; this.headers = headers; this.status = status; } - /* @Override */ + protected abstract List buildCookies(); + + protected String calculateCharset(String charset) { + + if (charset == null) { + String contentType = getContentType(); + if (contentType != null) + charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null + } + return charset != null ? charset : DEFAULT_CHARSET; + } + + @Override public final int getStatusCode() { return status.getStatusCode(); } - /* @Override */ + @Override public final String getStatusText() { return status.getStatusText(); } - /* @Override */ + @Override public final URI getUri() { return status.getUri(); } - /* @Override */ + @Override public final String getContentType() { - return headers != null? getHeader("Content-Type"): null; + return headers != null ? getHeader("Content-Type") : null; } - /* @Override */ + @Override public final String getHeader(String name) { - return headers != null? getHeaders().getFirstValue(name): null; + return headers != null ? getHeaders().getFirstValue(name) : null; } - /* @Override */ + @Override public final List getHeaders(String name) { - return headers != null? getHeaders().get(name): null; + return headers != null ? getHeaders().get(name) : null; } - /* @Override */ + @Override public final FluentCaseInsensitiveStringsMap getHeaders() { - return headers != null? headers.getHeaders(): new FluentCaseInsensitiveStringsMap(); + return headers != null ? headers.getHeaders() : new FluentCaseInsensitiveStringsMap(); } - /* @Override */ + @Override public final boolean isRedirected() { return (status.getStatusCode() >= 300) && (status.getStatusCode() <= 399); } - - /* @Override */ + + @Override public byte[] getResponseBodyAsBytes() throws IOException { return AsyncHttpProviderUtils.contentToBytes(bodyParts); } @@ -84,7 +92,7 @@ public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { return ByteBuffer.wrap(getResponseBodyAsBytes()); } - /* @Override */ + @Override public String getResponseBody() throws IOException { return getResponseBody(DEFAULT_CHARSET); } @@ -93,13 +101,12 @@ public String getResponseBody(String charset) throws IOException { return AsyncHttpProviderUtils.contentToString(bodyParts, calculateCharset(charset)); } - /* @Override */ + @Override public InputStream getResponseBodyAsStream() throws IOException { return AsyncHttpProviderUtils.contentAsStream(bodyParts); } - - protected abstract List buildCookies(); - + + @Override public List getCookies() { if (headers == null) { @@ -113,24 +120,17 @@ public List getCookies() { } - protected String calculateCharset(String charset) { - - if (charset == null) { - String contentType = getContentType(); - if (contentType != null) - charset = AsyncHttpProviderUtils.parseCharset(contentType); // parseCharset can return null - } - return charset != null? charset: DEFAULT_CHARSET; - } - + @Override public boolean hasResponseStatus() { return status != null; } + @Override public boolean hasResponseHeaders() { return headers != null && isNonEmpty(headers.getHeaders()); } + @Override public boolean hasResponseBody() { return isNonEmpty(bodyParts); } diff --git a/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java b/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java index 980869a5ad..85ebbeafdd 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java +++ b/api/src/main/java/org/asynchttpclient/resumable/PropertiesBasedResumableProcessor.java @@ -36,7 +36,7 @@ public class PropertiesBasedResumableProcessor implements ResumableAsyncHandler. /** * {@inheritDoc} */ - /* @Override */ + @Override public void put(String url, long transferredBytes) { properties.put(url, transferredBytes); } @@ -44,7 +44,7 @@ public void put(String url, long transferredBytes) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void remove(String uri) { if (uri != null) { properties.remove(uri); @@ -54,7 +54,7 @@ public void remove(String uri) { /** * {@inheritDoc} */ - /* @Override */ + @Override public void save(Map map) { log.debug("Saving current download state {}", properties.toString()); FileOutputStream os = null; diff --git a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java index 297ed0a0f4..446bc2403f 100644 --- a/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java +++ b/api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java @@ -102,7 +102,7 @@ public ResumableAsyncHandler(ResumableProcessor resumableProcessor, boolean accu /** * {@inheritDoc} */ - /* @Override */ + @Override public AsyncHandler.STATE onStatusReceived(final HttpResponseStatus status) throws Exception { responseBuilder.accumulate(status); if (status.getStatusCode() == 200 || status.getStatusCode() == 206) { @@ -121,7 +121,7 @@ public AsyncHandler.STATE onStatusReceived(final HttpResponseStatus status) thro /** * {@inheritDoc} */ - /* @Override */ + @Override public void onThrowable(Throwable t) { if (decoratedAsyncHandler != null) { decoratedAsyncHandler.onThrowable(t); @@ -133,7 +133,7 @@ public void onThrowable(Throwable t) { /** * {@inheritDoc} */ - /* @Override */ + @Override public AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { if (accumulateBody) { @@ -160,7 +160,7 @@ public AsyncHandler.STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) thro /** * {@inheritDoc} */ - /* @Override */ + @Override public Response onCompleted() throws Exception { resumableProcessor.remove(url); resumableListener.onAllBytesReceived(); @@ -175,7 +175,7 @@ public Response onCompleted() throws Exception { /** * {@inheritDoc} */ - /* @Override */ + @Override public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { responseBuilder.accumulate(headers); String contentLengthHeader = headers.getHeaders().getFirstValue("Content-Length"); diff --git a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java index 1386adb160..fb99f6b63b 100644 --- a/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java +++ b/api/src/main/java/org/asynchttpclient/webdav/WebDavCompletionHandlerBase.java @@ -57,7 +57,7 @@ public abstract class WebDavCompletionHandlerBase implements AsyncHandler /** * {@inheritDoc} */ - /* @Override */ + @Override public final STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { bodies.add(content); return STATE.CONTINUE; @@ -66,7 +66,7 @@ public final STATE onBodyPartReceived(final HttpResponseBodyPart content) throws /** * {@inheritDoc} */ - /* @Override */ + @Override public final STATE onStatusReceived(final HttpResponseStatus status) throws Exception { this.status = status; return STATE.CONTINUE; @@ -75,7 +75,7 @@ public final STATE onStatusReceived(final HttpResponseStatus status) throws Exce /** * {@inheritDoc} */ - /* @Override */ + @Override public final STATE onHeadersReceived(final HttpResponseHeaders headers) throws Exception { this.headers = headers; return STATE.CONTINUE; @@ -84,7 +84,7 @@ public final STATE onHeadersReceived(final HttpResponseHeaders headers) throws E /** * {@inheritDoc} */ - /* @Override */ + @Override public final T onCompleted() throws Exception { if (status != null) { Response response = status.prepareResponse(headers, bodies); @@ -101,7 +101,7 @@ public final T onCompleted() throws Exception { /** * {@inheritDoc} */ - /* @Override */ + @Override public void onThrowable(Throwable t) { logger.debug(t.getMessage(), t); } diff --git a/api/src/main/java/org/asynchttpclient/webdav/WebDavResponse.java b/api/src/main/java/org/asynchttpclient/webdav/WebDavResponse.java index 340e4be2eb..2c39c43f6b 100644 --- a/api/src/main/java/org/asynchttpclient/webdav/WebDavResponse.java +++ b/api/src/main/java/org/asynchttpclient/webdav/WebDavResponse.java @@ -45,7 +45,7 @@ public String getStatusText() { return response.getStatusText(); } - /* @Override */ + @Override public byte[] getResponseBodyAsBytes() throws IOException { return response.getResponseBodyAsBytes(); } diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java index 7147487156..20c36c5745 100644 --- a/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncStreamHandlerTest.java @@ -431,20 +431,20 @@ public void asyncStreamJustStatusLine() throws Exception { Future statusCode = client.prepareGet(getTargetUrl()).execute(new AsyncHandler() { private int status = -1; - /* @Override */ + @Override public void onThrowable(Throwable t) { whatCalled[OTHER] = true; latch.countDown(); } - /* @Override */ + @Override public STATE onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception { whatCalled[OTHER] = true; latch.countDown(); return STATE.ABORT; } - /* @Override */ + @Override public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exception { whatCalled[STATUS] = true; status = responseStatus.getStatusCode(); @@ -452,14 +452,14 @@ public STATE onStatusReceived(HttpResponseStatus responseStatus) throws Exceptio return STATE.ABORT; } - /* @Override */ + @Override public STATE onHeadersReceived(HttpResponseHeaders headers) throws Exception { whatCalled[OTHER] = true; latch.countDown(); return STATE.ABORT; } - /* @Override */ + @Override public Integer onCompleted() throws Exception { whatCalled[COMPLETED] = true; latch.countDown(); diff --git a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java index 47c453e886..d0ccfcee03 100644 --- a/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ByteBufferCapacityTest.java @@ -80,7 +80,7 @@ public void basicByteBufferTest() throws Exception { try { Response response = c.preparePut(getTargetUrl()).setBody(largeFile).execute(new AsyncCompletionHandlerAdapter() { - /* @Override */ + @Override public STATE onBodyPartReceived(final HttpResponseBodyPart content) throws Exception { byteReceived.addAndGet(content.getBodyByteBuffer().capacity()); return super.onBodyPartReceived(content); diff --git a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java index 8bce85b03f..107c8ed6a4 100644 --- a/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java +++ b/api/src/test/java/org/asynchttpclient/async/ConnectionPoolTest.java @@ -244,7 +244,7 @@ public Response onCompleted(Response response) throws Exception { }); client.prepareGet(getTargetUrl()).execute(new AsyncCompletionHandlerBase() { - /* @Override */ + @Override public void onThrowable(Throwable t) { if (t.getMessage() != null && t.getMessage().equalsIgnoreCase(THIS_IS_NOT_FOR_YOU)) { count.incrementAndGet(); diff --git a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java index 0e2fb055b9..82fc7cd3c0 100644 --- a/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java +++ b/api/src/test/java/org/asynchttpclient/async/HostnameVerifierTest.java @@ -43,7 +43,7 @@ public abstract class HostnameVerifierTest extends AbstractBasicHttpsTest { public static class EchoHandler extends AbstractHandler { - /* @Override */ + @Override public void handle(String pathInContext, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException, IOException { httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET); diff --git a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java index e6a338cfc0..af02a4ad17 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostRedirectGetTest.java @@ -94,7 +94,7 @@ public Integer onCompleted(Response response) throws Exception { return response.getStatusCode(); } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); fail("Unexpected exception: " + t.getMessage(), t); @@ -129,7 +129,7 @@ public Integer onCompleted(Response response) throws Exception { return response.getStatusCode(); } - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); fail("Unexpected exception: " + t.getMessage(), t); @@ -149,7 +149,7 @@ public static class PostRedirectGetHandler extends AbstractHandler { final AtomicInteger counter = new AtomicInteger(); - /* @Override */ + @Override public void handle(String pathInContext, org.eclipse.jetty.server.Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { final boolean expectGet = (httpRequest.getHeader("x-expect-get") != null); diff --git a/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java b/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java index 26d85587ac..49e4b2b6ea 100644 --- a/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java +++ b/api/src/test/java/org/asynchttpclient/async/PostWithQSTest.java @@ -89,7 +89,7 @@ public void postWithNulParamQS() throws IOException, ExecutionException, Timeout try { Future f = client.preparePost("http://127.0.0.1/" + port1 + "/?a=").setBody("abc".getBytes()).execute(new AsyncCompletionHandlerBase() { - /* @Override */ + @Override public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=")) { throw new IOException(status.getUri().toURL().toString()); @@ -112,7 +112,7 @@ public void postWithNulParamsQS() throws IOException, ExecutionException, Timeou try { Future f = client.preparePost("http://127.0.0.1/" + port1 + "/?a=b&c&d=e").setBody("abc".getBytes()).execute(new AsyncCompletionHandlerBase() { - /* @Override */ + @Override public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c&d=e")) { throw new IOException("failed to parse the query properly"); @@ -135,7 +135,7 @@ public void postWithEmptyParamsQS() throws IOException, ExecutionException, Time try { Future f = client.preparePost("http://127.0.0.1/" + port1 + "/?a=b&c=&d=e").setBody("abc".getBytes()).execute(new AsyncCompletionHandlerBase() { - /* @Override */ + @Override public STATE onStatusReceived(final HttpResponseStatus status) throws Exception { if (!status.getUri().toURL().toString().equals("http://127.0.0.1/" + port1 + "/?a=b&c=&d=e")) { throw new IOException("failed to parse the query properly"); diff --git a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java index 8959d7a8bc..ef16be723a 100644 --- a/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/WebDavBasicTest.java @@ -174,7 +174,7 @@ public void propFindCompletionHandlerWebDavTest() throws InterruptedException, I /** * {@inheritDoc} */ - /* @Override */ + @Override public void onThrowable(Throwable t) { t.printStackTrace(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java index 61b5f13671..63abfcc5c9 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/response/NettyResponse.java @@ -43,7 +43,7 @@ public NettyResponse(HttpResponseStatus status, super(status, headers, bodyParts); } - /* @Override */ + @Override public String getResponseBodyExcerpt(int maxLength) throws IOException { return getResponseBodyExcerpt(maxLength, null); } @@ -69,12 +69,12 @@ protected List buildCookies() { return Collections.unmodifiableList(cookies); } - /* @Override */ + @Override public byte[] getResponseBodyAsBytes() throws IOException { return getResponseBodyAsByteBuffer().array(); } - /* @Override */ + @Override public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { int length = 0; @@ -88,17 +88,17 @@ public ByteBuffer getResponseBodyAsByteBuffer() throws IOException { return target; } - /* @Override */ + @Override public String getResponseBody() throws IOException { return getResponseBody(null); } - /* @Override */ + @Override public String getResponseBody(String charset) throws IOException { return new String(getResponseBodyAsBytes(), calculateCharset(charset)); } - /* @Override */ + @Override public InputStream getResponseBodyAsStream() throws IOException { return new ByteArrayInputStream(getResponseBodyAsBytes()); } From 6a2567e2b3dfc48425914bd3bb5b60de1bf59f93 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 3 Oct 2013 11:10:58 +0200 Subject: [PATCH 0155/2389] Drop Netty Provider OIO support, close #398 --- .../netty/NettyAsyncHttpProviderConfig.java | 13 ------- .../providers/netty/channel/Channels.java | 39 ++++++------------- 2 files changed, 12 insertions(+), 40 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java index da6af380e2..592c9ca582 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java @@ -40,11 +40,6 @@ public class NettyAsyncHttpProviderConfig implements AsyncHttpProviderConfig> propertiesSet() { return properties.entrySet(); } - public boolean isUseBlockingIO() { - return useBlockingIO; - } - - public void setUseBlockingIO(boolean useBlockingIO) { - this.useBlockingIO = useBlockingIO; - } - public EventLoopGroup getEventLoopGroup() { return eventLoopGroup; } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java index 84e73efb71..bc1f091d02 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java @@ -25,10 +25,7 @@ import io.netty.channel.EventLoopGroup; import io.netty.channel.group.ChannelGroup; import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.oio.OioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.channel.socket.oio.OioSocketChannel; import io.netty.handler.codec.http.HttpClientCodec; import io.netty.handler.codec.http.HttpContentCompressor; import io.netty.handler.codec.http.HttpContentDecompressor; @@ -112,34 +109,22 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig this.config = config; this.asyncHttpProviderConfig = asyncHttpProviderConfig; - Class socketChannelClass = null; - if (asyncHttpProviderConfig.isUseBlockingIO()) { - socketChannelClass = OioSocketChannel.class; - eventLoopGroup = new OioEventLoopGroup(); - allowReleaseEventLoopGroup = true; + // check if external EventLoopGroup is defined + eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup(); + if (eventLoopGroup == null) { + eventLoopGroup = new NioEventLoopGroup(); + allowReleaseEventLoopGroup = true; } else { - // check if external EventLoopGroup is defined - eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup(); - if (eventLoopGroup instanceof OioEventLoopGroup) { - socketChannelClass = OioSocketChannel.class; - allowReleaseEventLoopGroup = false; - - } else if (eventLoopGroup instanceof NioEventLoopGroup) { - socketChannelClass = NioSocketChannel.class; - allowReleaseEventLoopGroup = false; - - } else { - socketChannelClass = NioSocketChannel.class; - eventLoopGroup = new NioEventLoopGroup(); - allowReleaseEventLoopGroup = true; - } + if (!(eventLoopGroup instanceof NioEventLoopGroup)) + throw new IllegalArgumentException("Only Nio is supported"); + allowReleaseEventLoopGroup = false; } - plainBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); - secureBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); - webSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); - secureWebSocketBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup); + plainBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup); + secureBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup); + webSocketBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup); + secureWebSocketBootstrap = new Bootstrap().channel(NioSocketChannel.class).group(eventLoopGroup); // This is dangerous as we can't catch a wrong typed ConnectionsPool ConnectionsPool cp = (ConnectionsPool) config.getConnectionsPool(); From 5eb0fd7828aa2c97b0ca69f5303879a94692eb40 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 3 Oct 2013 11:12:23 +0200 Subject: [PATCH 0156/2389] Fix previous commit --- .../netty/RetryNonBlockingIssue.java | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java index 09f89010cd..dd946b7bf1 100644 --- a/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java +++ b/providers/netty/src/test/java/org/asynchttpclient/providers/netty/RetryNonBlockingIssue.java @@ -156,48 +156,6 @@ public void testRetryNonBlockingAsyncConnect() throws IOException, InterruptedEx } } - @Test - public void testRetryBlocking() throws IOException, InterruptedException, ExecutionException { - - NettyAsyncHttpProviderConfig nettyConfig = new NettyAsyncHttpProviderConfig(); - nettyConfig.setUseBlockingIO(true); - - AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder()// - .setAllowPoolingConnection(true)// - .setMaximumConnectionsTotal(100)// - .setConnectionTimeoutInMs(60000)// - .setRequestTimeoutInMs(30000)// - .setAsyncHttpClientProviderConfig(nettyConfig)// - .build(); - - AsyncHttpClient client = getAsyncHttpClient(config); - - try { - List> res = new ArrayList>(); - for (int i = 0; i < 32; i++) { - res.add(testMethodRequest(client, 3, "servlet", UUID.randomUUID().toString())); - } - - StringBuilder b = new StringBuilder(); - for (ListenableFuture r : res) { - Response theres = r.get(); - assertEquals(theres.getStatusCode(), 200); - b.append("==============\r\n"); - b.append("Response Headers\r\n"); - Map> heads = theres.getHeaders(); - b.append(heads + "\r\n"); - b.append("==============\r\n"); - assertTrue(heads.size() > 0); - - } - System.out.println(b.toString()); - System.out.flush(); - - } finally { - client.close(); - } - } - @SuppressWarnings("serial") public class MockExceptionServlet extends HttpServlet { From 51597a7ef1eda2f2b569d65616863324bf50de62 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 3 Oct 2013 09:52:56 -0700 Subject: [PATCH 0157/2389] Honor the thread multiplier when a custom ExecutorService hasn't been provided. --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 9ef48ad96b..2639aadad3 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -440,6 +440,12 @@ private void doDefaultTransportConfig() { clientTransport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); if (service != null) { clientTransport.setWorkerThreadPool(service); + } else { + final int multiplier = clientConfig.getIoThreadMultiplier(); + final int threadCount = multiplier * Runtime.getRuntime().availableProcessors(); + clientTransport.getWorkerThreadPoolConfig() + .setCorePoolSize(threadCount) + .setMaxPoolSize(threadCount); } } From 71f72c168ad3180f7f9a69250d65548b6e9b836a Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 3 Oct 2013 10:58:42 -0700 Subject: [PATCH 0158/2389] Cleanup imports. --- .../providers/grizzly/GrizzlyAsyncHttpProvider.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java index 2639aadad3..efad63b22a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyAsyncHttpProvider.java @@ -16,13 +16,9 @@ import org.asynchttpclient.AsyncHandler; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.AsyncHttpProvider; -import org.asynchttpclient.HttpResponseBodyPart; -import org.asynchttpclient.HttpResponseHeaders; -import org.asynchttpclient.HttpResponseStatus; import org.asynchttpclient.ListenableFuture; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Request; -import org.asynchttpclient.Response; import org.asynchttpclient.ntlm.NTLMEngine; import org.asynchttpclient.providers.grizzly.filters.AsyncHttpClientEventFilter; import org.asynchttpclient.providers.grizzly.filters.AsyncHttpClientFilter; @@ -69,7 +65,6 @@ import javax.net.ssl.SSLEngine; import java.io.IOException; import java.util.LinkedHashSet; -import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; From 9bdc51fb37470bf1320ed95f364a9b6def2a26fd Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 3 Oct 2013 11:50:03 -0700 Subject: [PATCH 0159/2389] Use HTTP Method references vs raw string. --- .../org/asynchttpclient/providers/grizzly/EventHandler.java | 3 ++- .../grizzly/statushandler/ProxyAuthorizationHandler.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index 732697e3b5..a3f129cb5d 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -36,6 +36,7 @@ import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpHeader; import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.ProcessingState; import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.http.util.Header; @@ -471,7 +472,7 @@ public static Request newRequest(final URI uri, final RequestBuilder builder = new RequestBuilder(ctx.getRequest()); if (asGet) { - builder.setMethod("GET"); + builder.setMethod(Method.GET.getMethodString()); } builder.setUrl(uri.toString()); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index 4720763ca3..48d591566a 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -25,6 +25,7 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HttpStatus; import org.ietf.jgss.GSSContext; @@ -74,7 +75,7 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, Realm realm = new Realm.RealmBuilder().setPrincipal(principal) .setPassword(password) .setUri("/") - .setMethodName("CONNECT") + .setMethodName(Method.CONNECT.getMethodString()) .setUsePreemptiveAuth(true) .parseProxyAuthenticateHeader(proxyAuth) .build(); From d67e626d2cad29192d1476c73bd183773cf2e569 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 3 Oct 2013 11:53:37 -0700 Subject: [PATCH 0160/2389] Remove unused import. --- .../grizzly/statushandler/ProxyAuthorizationHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index 48d591566a..59708dcc55 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -23,7 +23,6 @@ import org.asynchttpclient.util.Base64; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.util.Header; From 7a79d25ca914f3e40341c57505608ba69a657047 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 3 Oct 2013 12:04:59 -0700 Subject: [PATCH 0161/2389] More cleanup: - unused imports - removed legacy classes --- .../providers/grizzly/EventHandler.java | 1 - .../grizzly/GrizzlyResponseBodyPart.java | 3 -- .../grizzly/GrizzlyResponseStatus.java | 2 +- .../filters/AsyncHttpClientEventFilter.java | 3 -- .../filters/AsyncHttpClientFilter.java | 1 - .../grizzly/filters/SwitchingSSLFilter.java | 49 +------------------ 6 files changed, 2 insertions(+), 57 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java index a3f129cb5d..8389637833 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/EventHandler.java @@ -108,7 +108,6 @@ public void onHttpContentParsed(HttpContent content, try { context.setCurrentState(handler.onBodyPartReceived( new GrizzlyResponseBodyPart(content, - context.getRequest().getURI(), ctx.getConnection()))); } catch (Exception e) { handler.onThrowable(e); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java index b010cd3c3d..f5443ab868 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseBodyPart.java @@ -13,7 +13,6 @@ package org.asynchttpclient.providers.grizzly; -import org.asynchttpclient.AsyncHttpProvider; import org.asynchttpclient.HttpResponseBodyPart; import org.glassfish.grizzly.Buffer; @@ -24,7 +23,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.net.URI; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicReference; @@ -47,7 +45,6 @@ class GrizzlyResponseBodyPart extends HttpResponseBodyPart { public GrizzlyResponseBodyPart(final HttpContent content, - final URI uri, final Connection connection) { this.content = content; this.connection = connection; diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java index 9bafb37be4..e24e9937f0 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/GrizzlyResponseStatus.java @@ -66,7 +66,7 @@ public Response prepareResponse(HttpResponseHeaders headers, List listeners = - new ConcurrentHashMap(); - - - // --------------------------------------- Method from HandshakeListener - - - @Override - public void onStart(Connection connection) { - // no-op - } - - @Override - public void onComplete(Connection connection) { - final HandshakeCompleteListener listener = listeners.get(connection); - if (listener != null) { - removeListener(connection); - listener.complete(); - } - } - - - // --------------------------------------------- Package Private Methods - - - public static void addListener(final Connection c, - final HandshakeCompleteListener listener) { - listeners.putIfAbsent(c, listener); - } - - static void removeListener(final Connection c) { - listeners.remove(c); - } - } - } From 71351fdbc528e3748a1e6d94c0e381af4f189305 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 3 Oct 2013 21:39:20 +0200 Subject: [PATCH 0162/2389] Upgrade Netty 4.0.10 --- providers/netty/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 8905736367..773dac96f4 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -39,7 +39,7 @@ io.netty netty-all - 4.0.10.Final-SNAPSHOT + 4.0.10.Final org.javassist From 9ee456fb7ff308b60e9565c4dba2531792ad6984 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 4 Oct 2013 01:06:18 +0200 Subject: [PATCH 0163/2389] Fix Response.isRedirected, close #391 --- .../org/asynchttpclient/providers/ResponseBase.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java index 2a96b2880b..3f010557b7 100644 --- a/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java +++ b/api/src/main/java/org/asynchttpclient/providers/ResponseBase.java @@ -80,7 +80,16 @@ public final FluentCaseInsensitiveStringsMap getHeaders() { @Override public final boolean isRedirected() { - return (status.getStatusCode() >= 300) && (status.getStatusCode() <= 399); + switch (status.getStatusCode()) { + case 301: + case 302: + case 303: + case 307: + case 308: + return true; + default: + return false; + } } @Override From 6e32eefd22688a6d1097b7f8194a51490be4a79a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 8 Oct 2013 23:13:23 +0200 Subject: [PATCH 0164/2389] Latest release is 1.7.20 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f258f4b1ac..82921e4652 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Async Http Client library purpose is to allow Java applications to easily execut com.ning async-http-client - 1.7.19 + 1.7.20 ``` From 0da1f10df65d2a5b94e68cd705d94c1d9daf43d2 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 9 Oct 2013 13:29:00 -0700 Subject: [PATCH 0165/2389] Ensure onStatusReceived() is invoked when there is no realm. --- .../grizzly/statushandler/AuthorizationHandler.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java index d9bf914507..369a9b7b7f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java @@ -58,6 +58,14 @@ public boolean handleStatus(final HttpResponsePacket responsePacket, } if (realm == null) { httpTransactionContext.setInvocationStatus(STOP); + if (httpTransactionContext.getHandler() != null) { + try { + httpTransactionContext.getHandler().onStatusReceived( + httpTransactionContext.getResponseStatus()); + } catch (Exception e) { + httpTransactionContext.abort(e); + } + } return true; } From 221df62e719aa25e9bc800dd93f644b059b8fd05 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 10 Oct 2013 15:00:29 -0700 Subject: [PATCH 0166/2389] Workaround issue discovered by Stephane after upgrading to Jetty 9. --- .../statushandler/AuthorizationHandler.java | 5 +++-- .../statushandler/ProxyAuthorizationHandler.java | 14 +++++++------- .../providers/grizzly/GrizzlyBasicAuthTest.java | 11 ----------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java index 369a9b7b7f..11b2a0c2df 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/AuthorizationHandler.java @@ -135,12 +135,13 @@ private Connection getConnectionForNextRequest(final FilterChainContext ctx, final HttpResponsePacket response, final HttpTxContext httpCtx) throws Exception { + /* if (response.getProcessingState().isKeepAlive()) { return ctx.getConnection(); - } else { + } else { */ final ConnectionManager m = httpCtx.getProvider().getConnectionManager(); return m.obtainConnection(request, httpCtx.getFuture()); - } + /* } */ } } // END AuthorizationHandler diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java index 59708dcc55..b8530f6014 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/statushandler/ProxyAuthorizationHandler.java @@ -224,13 +224,13 @@ private Connection getConnectionForNextRequest(final FilterChainContext ctx, final HttpResponsePacket response, final HttpTxContext httpCtx) throws Exception { - if (response.getProcessingState().isKeepAlive()) { - return ctx.getConnection(); - } else { - final ConnectionManager m = - httpCtx.getProvider().getConnectionManager(); - return m.obtainConnection(request, httpCtx.getFuture()); - } + /* + if (response.getProcessingState().isKeepAlive()) { + return ctx.getConnection(); + } else { */ + final ConnectionManager m = httpCtx.getProvider().getConnectionManager(); + return m.obtainConnection(request, httpCtx.getFuture()); + /* } */ } diff --git a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java index c7d077308f..b558e8cf61 100644 --- a/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java +++ b/providers/grizzly/src/test/java/org/asynchttpclient/providers/grizzly/GrizzlyBasicAuthTest.java @@ -29,16 +29,5 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) { public String getProviderClass() { return GrizzlyAsyncHttpProvider.class.getName(); } - - @Test(groups = { "standalone", "default_provider" }, enabled = false) - @Override - public void basicAuthFileTest() throws Exception { - // FIXME - } - @Test(groups = { "standalone", "default_provider" }, enabled = false) - @Override - public void basicAuthFileNoKeepAliveTest() throws Exception { - // FIXME - } } From d6e5c1589bf1d0ecfd5301a056004c1f9357add7 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 14 Oct 2013 23:31:55 +0200 Subject: [PATCH 0167/2389] Support multi valued headers, close #403 --- .../netty/request/NettyRequests.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java index ad2436db13..d5821471eb 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java @@ -37,7 +37,6 @@ import java.util.Map.Entry; import org.asynchttpclient.AsyncHttpClientConfig; -import org.asynchttpclient.FluentCaseInsensitiveStringsMap; import org.asynchttpclient.ProxyServer; import org.asynchttpclient.Realm; import org.asynchttpclient.Request; @@ -61,7 +60,7 @@ public static HttpRequest newNettyRequest(AsyncHttpClientConfig config, Request method = HttpMethod.CONNECT; else method = HttpMethod.valueOf(request.getMethod()); - + String host = null; HttpVersion httpVersion; String requestUri; @@ -107,18 +106,6 @@ else if (uri.getRawQuery() != null) } if (method != HttpMethod.CONNECT) { - FluentCaseInsensitiveStringsMap h = request.getHeaders(); - if (h != null) { - for (Entry> header : h) { - String name = header.getKey(); - if (!HttpHeaders.Names.HOST.equalsIgnoreCase(name)) { - for (String value : header.getValue()) { - headers.put(name, value); - } - } - } - } - if (config.isCompressionEnabled()) { headers.put(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); } @@ -186,6 +173,7 @@ else if (uri.getRawQuery() != null) } if (proxyServer != null) { + // FIXME Wikipedia says that Proxy-Connection was a misunderstanding of Connection http://en.wikipedia.org/wiki/List_of_HTTP_header_fields if (!request.getHeaders().containsKey("Proxy-Connection")) { headers.put("Proxy-Connection", AsyncHttpProviderUtils.keepAliveHeaderValue(config)); } @@ -297,6 +285,15 @@ else if (uri.getRawQuery() != null) } else { nettyRequest = new DefaultFullHttpRequest(httpVersion, method, requestUri); } + + // assign headers as configured on request + if (method != HttpMethod.CONNECT) { + for (Entry> header : request.getHeaders()) { + nettyRequest.headers().set(header.getKey(), header.getValue()); + } + } + + // override with computed ones for (Entry header : headers.entrySet()) { nettyRequest.headers().set(header.getKey(), header.getValue()); } From 48b75f5f7a703df4560835c82f49209903b4a131 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 14 Oct 2013 23:43:14 +0200 Subject: [PATCH 0168/2389] Add RequestBuilder.setURI, like setUrl, close #405 --- .../asynchttpclient/RequestBuilderBase.java | 34 ++++--------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index 0a0001f8bc..9b8f14baac 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -369,7 +369,12 @@ protected RequestBuilderBase(Class derived, Request prototype) { } public T setUrl(String url) { - request.originalUri = buildURI(url); + return setURI(URI.create(url)); + } + + public T setURI(URI uri) { + request.originalUri = uri; + addQueryParameters(request.originalUri); request.uri = null; request.rawUri = null; return derived.cast(this); @@ -385,31 +390,7 @@ public T setLocalInetAddress(InetAddress address) { return derived.cast(this); } - private URI buildURI(String url) { - URI uri = URI.create(url); - - if (uri.getRawPath() == null) { - // AHC-96 - // Let's try to derive it - StringBuilder buildedUrl = new StringBuilder(); - - if (uri.getScheme() != null) { - buildedUrl.append(uri.getScheme()); - buildedUrl.append("://"); - } - - if (uri.getAuthority() != null) { - buildedUrl.append(uri.getAuthority()); - } - if (url.indexOf("://") == -1) { - String s = buildedUrl.toString(); - url = s + url.substring(uri.getScheme().length() + 1); - return buildURI(url); - } else { - throw new IllegalArgumentException("Invalid url " + uri.toString()); - } - } - + private void addQueryParameters(URI uri) { if (isNonEmpty(uri.getRawQuery())) { String[] queries = uri.getRawQuery().split("&"); int pos; @@ -430,7 +411,6 @@ private URI buildURI(String url) { } } } - return uri; } public T setVirtualHost(String virtualHost) { From d55c4e01dbb1fcb71161df4d28a9bf96ab15a558 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 15 Oct 2013 10:47:48 -0700 Subject: [PATCH 0169/2389] Port changes from #402 to master. --- .../AsyncHttpClientConfig.java | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java index 3ce08af1ad..7cd7d7b027 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java @@ -503,12 +503,20 @@ public boolean isRemoveQueryParamOnRedirect() { } /** - * Return true if one of the {@link java.util.concurrent.ExecutorService} has been shutdown. - * - * @return true if one of the {@link java.util.concurrent.ExecutorService} has been shutdown. + * @return true if both the application and reaper thread pools + * haven't yet been shutdown. + * @since 1.7.21 */ - public boolean isClosed() { - return applicationThreadPool.isShutdown() || reaper.isShutdown(); + public boolean isValid() { + boolean atpRunning = true; + try { + atpRunning = applicationThreadPool.isShutdown(); + } catch (Exception ignore) { + // isShutdown() will thrown an exception in an EE7 environment + // when using a ManagedExecutorService. + // When this is the case, we assume it's running. + } + return (atpRunning && !reaper.isShutdown()); } /** @@ -1227,23 +1235,6 @@ public Thread newThread(Runnable r) { }); } -// if (applicationThreadPool == null) { -// applicationThreadPool = -// Executors.newCachedThreadPool(new ThreadFactory() { -// final AtomicInteger counter = new AtomicInteger(); -// public Thread newThread(Runnable r) { -// Thread t = new Thread(r, -// "AsyncHttpClient-Callback-" + counter.incrementAndGet()); -// t.setDaemon(true); -// return t; -// } -// }); -// } -// -// if (applicationThreadPool.isShutdown()) { -// throw new IllegalStateException("ExecutorServices closed"); -// } - if (proxyServerSelector == null && useProxySelector) { proxyServerSelector = ProxyUtils.getJdkDefaultProxyServerSelector(); } From 20deaa8344c47713a7b35c1101873db6a4bc008f Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 16 Oct 2013 08:28:29 +0200 Subject: [PATCH 0170/2389] Fix invalidUri test, crappy url format should be supported --- .../main/java/org/asynchttpclient/RequestBuilderBase.java | 2 ++ .../org/asynchttpclient/async/AsyncProvidersBasicTest.java | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index 9b8f14baac..d737158ade 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -373,6 +373,8 @@ public T setUrl(String url) { } public T setURI(URI uri) { + if (uri.getPath() == null) + throw new IllegalArgumentException("Unsupported uri format: " + uri); request.originalUri = uri; addQueryParameters(request.originalUri); request.uri = null; diff --git a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java index 0472ef6ba6..e865796391 100755 --- a/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java @@ -1556,12 +1556,11 @@ public void headShouldNotAllowBody() throws IllegalArgumentException, IOExceptio } } - @Test(groups = { "standalone", "default_provider" }) + @Test(groups = { "standalone", "default_provider" }, expectedExceptions = { IllegalArgumentException.class }) public void invalidUri() throws Exception { AsyncHttpClient client = getAsyncHttpClient(null); try { - Response response = client.executeRequest(client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build()).get(); - assertEquals(200, response.getStatusCode()); + client.prepareGet(String.format("http:127.0.0.1:%d/foo/test", port1)).build(); } finally { client.close(); } From 8add5878c241bddbf29bae6a5127abfb8f1cfc05 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 16 Oct 2013 12:55:05 +0200 Subject: [PATCH 0171/2389] Make sure a cancel exception won't hide the expected one --- .../netty/future/NettyResponseFuture.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java index 2a7868a9ff..7f0cb64a29 100755 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/future/NettyResponseFuture.java @@ -234,12 +234,15 @@ public V get(long l, TimeUnit tu) throws InterruptedException, TimeoutException, TimeoutException te = new TimeoutException(String.format("No response received after %s %s", l, tu.name().toLowerCase())); if (!throwableCalled.getAndSet(true)) { try { - asyncHandler.onThrowable(te); - } catch (Throwable t) { - logger.debug("asyncHandler.onThrowable", t); + try { + asyncHandler.onThrowable(te); + } catch (Throwable t) { + logger.debug("asyncHandler.onThrowable", t); + } + throw new ExecutionException(te); + } finally { + cancelReaper(); } - cancelReaper(); - throw new ExecutionException(te); } } isDone.set(true); @@ -267,12 +270,15 @@ private V getContent() throws ExecutionException { } catch (Throwable ex) { if (!throwableCalled.getAndSet(true)) { try { - asyncHandler.onThrowable(ex); - } catch (Throwable t) { - logger.debug("asyncHandler.onThrowable", t); + try { + asyncHandler.onThrowable(ex); + } catch (Throwable t) { + logger.debug("asyncHandler.onThrowable", t); + } + throw new RuntimeException(ex); + } finally { + cancelReaper(); } - cancelReaper(); - throw new RuntimeException(ex); } } content.compareAndSet(null, update); From ece093ae64e74a40c434e78991b367bb477d9458 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 16 Oct 2013 22:34:27 +0200 Subject: [PATCH 0172/2389] Minor removeQuotes optim --- .../util/AsyncHttpProviderUtils.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index 500ed4a290..e44b3a6c3c 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -46,6 +46,8 @@ import org.asynchttpclient.multipart.MultipartRequestEntity; import org.asynchttpclient.multipart.PartSource; +import com.ning.http.util.MiscUtil; + /** * {@link org.asynchttpclient.AsyncHttpProvider} common utilities. *

    @@ -530,13 +532,24 @@ public static int convertExpireField(String timestring) { throw new IllegalArgumentException("Not a valid expire field " + trimmedTimeString); } - private final static String removeQuote(String s) { + public final static String removeQuotes(String s) { if (MiscUtil.isNonEmpty(s)) { - if (s.charAt(0) == '"') - s = s.substring(1); + int start = 0; + int end = s.length(); + boolean changed = false; + + if (s.charAt(0) == '"') { + changed = true; + start++; + } + + if (s.charAt(s.length() - 1) == '"') { + changed = true; + end--; + } - if (s.charAt(s.length() - 1) == '"') - s = s.substring(0, s.length() - 1); + if (changed) + s = s.substring(start, end); } return s; } From 89410aa6c5cf375228fd85ab919d0d1497c99416 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 21 Oct 2013 10:38:19 +0200 Subject: [PATCH 0173/2389] Remove bad import --- .../java/org/asynchttpclient/util/AsyncHttpProviderUtils.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index e44b3a6c3c..4558844044 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -46,8 +46,6 @@ import org.asynchttpclient.multipart.MultipartRequestEntity; import org.asynchttpclient.multipart.PartSource; -import com.ning.http.util.MiscUtil; - /** * {@link org.asynchttpclient.AsyncHttpProvider} common utilities. *

    From 466bd55e92d40e7193aa1ffd28c823d66aeb0ab6 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 21 Oct 2013 10:44:32 +0200 Subject: [PATCH 0174/2389] Fix build --- .../java/org/asynchttpclient/util/AsyncHttpProviderUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index 4558844044..a0599eecf6 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -516,7 +516,7 @@ public static String parseCharset(String contentType) { } public static int convertExpireField(String timestring) { - String trimmedTimeString = removeQuote(timestring.trim()); + String trimmedTimeString = removeQuotes(timestring.trim()); for (SimpleDateFormat sdf : simpleDateFormat.get()) { Date date = sdf.parse(trimmedTimeString, new ParsePosition(0)); From 19cc544158cdb3f4c1fb98137ae40024f29939b6 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Mon, 21 Oct 2013 10:44:42 +0200 Subject: [PATCH 0175/2389] Upgrade Netty 4.0.11 --- providers/netty/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 773dac96f4..471355e0a0 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -39,7 +39,7 @@ io.netty netty-all - 4.0.10.Final + 4.0.11.Final org.javassist From b0249470340022918fcc2b412e2347c4ba4ac7c5 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Thu, 24 Oct 2013 18:50:26 -0700 Subject: [PATCH 0176/2389] Fix for #407. --- .../providers/grizzly/bodyhandler/BodyGeneratorBodyHandler.java | 2 +- .../providers/grizzly/filters/AsyncHttpClientFilter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyGeneratorBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyGeneratorBodyHandler.java index b8f3437c56..287f309da1 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyGeneratorBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/BodyGeneratorBodyHandler.java @@ -44,7 +44,7 @@ public boolean doHandle(final FilterChainContext ctx, final BodyGenerator generator = request.getBodyGenerator(); final Body bodyLocal = generator.createBody(); final long len = bodyLocal.getContentLength(); - if (len > 0) { + if (len >= 0) { requestPacket.setContentLengthLong(len); } else { requestPacket.setChunked(true); diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java index 4589f12261..942dc4208e 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/AsyncHttpClientFilter.java @@ -262,7 +262,7 @@ private boolean sendAsGrizzlyRequest(final RequestInfoHolder requestInfoHolder, if (Utils.requestHasEntityBody(request)) { final long contentLength = request.getContentLength(); - if (contentLength > 0) { + if (contentLength >= 0) { requestPacket.setContentLengthLong(contentLength); requestPacket.setChunked(false); } else { From d63637a844e4aa6d9141f6412885abbbdc5b6ed8 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Fri, 25 Oct 2013 09:47:30 -0700 Subject: [PATCH 0177/2389] Leverage utility class for determining thread type. --- .../providers/grizzly/FeedableBodyGenerator.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java index e359626b0f..58dbc72099 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/FeedableBodyGenerator.java @@ -31,6 +31,7 @@ import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.SelectorRunner; +import org.glassfish.grizzly.threadpool.Threads; import org.glassfish.grizzly.utils.Futures; import static java.lang.Boolean.TRUE; @@ -185,7 +186,7 @@ public void run() { // If the current thread is a selector thread, we need to execute // the remainder of the task on the worker thread to prevent // it from being blocked. - if (isCurrentThreadSelectorRunner()) { + if (isServiceThread()) { c.getTransport().getWorkerThreadPool().execute(r); } else { r.run(); @@ -196,10 +197,8 @@ public void run() { // --------------------------------------------------------- Private Methods - private boolean isCurrentThreadSelectorRunner() { - final NIOConnection c = (NIOConnection) context.getConnection(); - final SelectorRunner runner = c.getSelectorRunner(); - return (Thread.currentThread() == runner.getRunnerThread()); + private boolean isServiceThread() { + return Threads.isService(); } From edd600d162ff24b222d2a41c4397a3c712cad2cc Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Wed, 30 Oct 2013 10:38:07 -0700 Subject: [PATCH 0178/2389] Integrate 2.3.7. --- providers/grizzly/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/grizzly/pom.xml b/providers/grizzly/pom.xml index ab9d594d5b..097a903510 100644 --- a/providers/grizzly/pom.xml +++ b/providers/grizzly/pom.xml @@ -14,7 +14,7 @@ - 2.3.7-SNAPSHOT + 2.3.7 1.0 From e4c5c7793595ca58810100f90fe0596b227ff774 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Wed, 6 Nov 2013 21:36:58 +0100 Subject: [PATCH 0179/2389] Port 6f60a45d9ebe4ad0ebd6881746e1671f3a3a8317 on master --- .../multipart/MultipartBody.java | 16 ++- .../multipart/MultipartBodyTest.java | 109 ++++++++++++++++++ 2 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java index 70d15e21e2..af9df966e2 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java @@ -78,7 +78,7 @@ public long read(ByteBuffer buffer) throws IOException { try { int overallLength = 0; - int maxLength = buffer.capacity(); + int maxLength = buffer.remaining(); if (startPart == parts.size() && endWritten) { return overallLength; @@ -132,6 +132,7 @@ public long read(ByteBuffer buffer) throws IOException { initializeFileEnd(currentFilePart); } else if (fileLocation == FileLocation.END) { startPart++; + fileLocation = FileLocation.NONE; if (startPart == parts.size() && currentStream.available() == 0) { doneWritingParts = true; } @@ -146,6 +147,7 @@ public long read(ByteBuffer buffer) throws IOException { initializeFileEnd(currentFilePart); } else if (fileLocation == FileLocation.END) { startPart++; + fileLocation = FileLocation.NONE; if (startPart == parts.size() && currentStream.available() == 0) { doneWritingParts = true; } @@ -165,6 +167,7 @@ public long read(ByteBuffer buffer) throws IOException { initializeFileEnd(currentFilePart); } else if (fileLocation == FileLocation.END) { startPart++; + fileLocation = FileLocation.NONE; if (startPart == parts.size() && currentStream.available() == 0) { doneWritingParts = true; } @@ -202,7 +205,8 @@ public long read(ByteBuffer buffer) throws IOException { private void initializeByteArrayBody(FilePart filePart) throws IOException { - ByteArrayOutputStream output = generateByteArrayBody(filePart); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + filePart.sendData(output); initializeBuffer(output); @@ -388,15 +392,9 @@ private StringPart generateClientStringpart(org.asynchttpclient.Part part) { private long handleByteArrayPart(WritableByteChannel target, FilePart filePart, byte[] data) throws IOException { - ByteArrayOutputStream output = generateByteArrayBody(filePart); - return writeToTarget(target, output); - } - - private ByteArrayOutputStream generateByteArrayBody(FilePart filePart) - throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); Part.sendPart(output, filePart, boundary); - return output; + return writeToTarget(target, output); } private long handleFileEnd(WritableByteChannel target, FilePart filePart) diff --git a/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java new file mode 100644 index 0000000000..9cbccb9ac0 --- /dev/null +++ b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2013 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.asynchttpclient.multipart; + +import org.asynchttpclient.*; +import org.asynchttpclient.Part; +import org.asynchttpclient.util.AsyncHttpProviderUtils; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + +public class MultipartBodyTest { + + @Test(groups = "fast") + public void testBasics() { + final List parts = new ArrayList(); + + // add a file + final File testFile = getTestfile(); + try { + parts.add(new FilePart("filePart", testFile)); + } catch (FileNotFoundException fne) { + Assert.fail("file not found: " + testFile); + } + + // add a byte array + try { + parts.add(new ByteArrayPart("baPart", "fileName", "testMultiPart".getBytes("utf-8"), "application/test", "utf-8")); + } catch (UnsupportedEncodingException ignore) { + } + + // add a string + parts.add(new StringPart("stringPart", "testString", "utf-8")); + + compareContentLength(parts); + } + + private static File getTestfile() { + final ClassLoader cl = MultipartBodyTest.class.getClassLoader(); + final URL url = cl.getResource("textfile.txt"); + Assert.assertNotNull(url); + File file = null; + try { + file = new File(url.toURI()); + } catch (URISyntaxException use) { + Assert.fail("uri syntax error"); + } + return file; + } + + private static void compareContentLength(final List parts) { + Assert.assertNotNull(parts); + // get expected values + MultipartRequestEntity mre = null; + try { + mre = AsyncHttpProviderUtils.createMultipartRequestEntity(parts, new FluentCaseInsensitiveStringsMap()); + } catch (FileNotFoundException fne) { + Assert.fail("file not found: " + parts); + } + final long expectedContentLength = mre.getContentLength(); + + // get real bytes + final Body multipartBody = new MultipartBody(parts, mre.getContentType(), String.valueOf(expectedContentLength)); + try { + final ByteBuffer buffer = ByteBuffer.allocate(8192); + boolean last = false; + long totalBytes = 0; + while (!last) { + long readBytes = 0; + try { + readBytes = multipartBody.read(buffer); + } catch (IOException ie) { + Assert.fail("read failure"); + } + if (readBytes >= 0) { + totalBytes += readBytes; + } else { + last = true; + } + buffer.clear(); + } + Assert.assertEquals(totalBytes, expectedContentLength); + } finally { + try { + multipartBody.close(); + } catch (IOException ignore) { + } + } + } +} From a4f00a057f9f71c496c26a87ca45cb2166f2bbdc Mon Sep 17 00:00:00 2001 From: Bongjae Chang Date: Thu, 7 Nov 2013 11:43:09 +0900 Subject: [PATCH 0180/2389] Fixed infinite loop of MultipartBodyTest for master branch. --- .../java/org/asynchttpclient/multipart/MultipartBodyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java index 9cbccb9ac0..1e8ba2860c 100644 --- a/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java @@ -91,7 +91,7 @@ private static void compareContentLength(final List parts) { } catch (IOException ie) { Assert.fail("read failure"); } - if (readBytes >= 0) { + if (readBytes > 0) { totalBytes += readBytes; } else { last = true; From 0f7615655c85f925cb81c377bd4205e9d5ed8bfb Mon Sep 17 00:00:00 2001 From: Bongjae Chang Date: Thu, 7 Nov 2013 12:24:52 +0900 Subject: [PATCH 0181/2389] MultipartBody#read() returns -1 when it meets EOF. Current MultipartBody#read() returns only 0 when it meets both Exception and EOF(endWritten). Then caller can't know whether the value is EOF or Error. --- .../main/java/org/asynchttpclient/multipart/MultipartBody.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java index af9df966e2..f72aaf62c1 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java @@ -81,7 +81,7 @@ public long read(ByteBuffer buffer) throws IOException { int maxLength = buffer.remaining(); if (startPart == parts.size() && endWritten) { - return overallLength; + return -1; } boolean full = false; From 3df777f7e3230711570b30348c1cd09dcd15ad01 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 8 Nov 2013 09:33:18 +0100 Subject: [PATCH 0182/2389] Upgrade Netty 4.0.12 and javassist 3.18.1 --- providers/netty/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 471355e0a0..9b884d134d 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -39,12 +39,12 @@ io.netty netty-all - 4.0.11.Final + 4.0.12.Final org.javassist javassist - 3.18.0-GA + 3.18.1-GA From 3286d44d4a3682ad9230c8e9b21fb821eb51488c Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Mon, 11 Nov 2013 08:58:24 -0800 Subject: [PATCH 0183/2389] Port changes for #411 from 1.7 to master. --- .../grizzly/bodyhandler/PartsBodyHandler.java | 86 +++++++++++++++---- 1 file changed, 68 insertions(+), 18 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java index ba656d0d68..f4491f391f 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java @@ -13,17 +13,22 @@ package org.asynchttpclient.providers.grizzly.bodyhandler; +import org.asynchttpclient.Body; +import org.asynchttpclient.Part; import org.asynchttpclient.Request; +import org.asynchttpclient.multipart.MultipartBody; import org.asynchttpclient.multipart.MultipartRequestEntity; +import org.asynchttpclient.providers.grizzly.FeedableBodyGenerator; +import org.asynchttpclient.providers.grizzly.GrizzlyAsyncHttpProvider; import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; -import org.glassfish.grizzly.utils.BufferOutputStream; import java.io.IOException; +import java.util.List; import static org.asynchttpclient.util.MiscUtil.isNonEmpty; @@ -42,25 +47,70 @@ public boolean doHandle(final FilterChainContext ctx, final HttpRequestPacket requestPacket) throws IOException { - MultipartRequestEntity mre = + final List parts = request.getParts(); + final MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity( - request.getParts(), - request.getHeaders()); - requestPacket.setContentLengthLong(mre.getContentLength()); - requestPacket.setContentType(mre.getContentType()); - final MemoryManager mm = ctx.getMemoryManager(); - Buffer b = mm.allocate(512); - BufferOutputStream o = new BufferOutputStream(mm, b, true); - mre.writeRequest(o); - b = o.getBuffer(); - b.trim(); - if (b.hasRemaining()) { - final HttpContent content = requestPacket.httpContentBuilder().content(b).build(); - content.setLast(true); - ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null)); + parts, request.getHeaders()); + final long contentLength = mre.getContentLength(); + final String contentType = mre.getContentType(); + requestPacket.setContentLengthLong(contentLength); + requestPacket.setContentType(contentType); + if (GrizzlyAsyncHttpProvider.LOGGER.isDebugEnabled()) { + GrizzlyAsyncHttpProvider.LOGGER.debug( + "REQUEST(modified): contentLength={}, contentType={}", + new Object[]{ + requestPacket.getContentLength(), + requestPacket.getContentType() + }); } - return true; + final FeedableBodyGenerator generator = new FeedableBodyGenerator() { + @Override + public Body createBody() throws IOException { + return new MultipartBody(parts, contentType, + String.valueOf(contentLength)); + } + }; + generator.setFeeder(new FeedableBodyGenerator.BaseFeeder(generator) { + @Override + public void flush() throws IOException { + final Body bodyLocal = feedableBodyGenerator.createBody(); + try { + final MemoryManager mm = ctx.getMemoryManager(); + boolean last = false; + while (!last) { + Buffer buffer = mm.allocate(BodyHandler.MAX_CHUNK_SIZE); + buffer.allowBufferDispose(true); + final long readBytes = + bodyLocal.read(buffer.toByteBuffer()); + if (readBytes > 0) { + buffer.position((int) readBytes); + buffer.trim(); + } else { + buffer.dispose(); + if (readBytes < 0) { + last = true; + buffer = Buffers.EMPTY_BUFFER; + } else { + throw new IllegalStateException( + "MultipartBody unexpectedly returned 0 bytes available"); + } + } + feed(buffer, last); + } + } finally { + if (bodyLocal != null) { + try { + bodyLocal.close(); + } catch (IOException ignore) { + } + } + } + } + }); + generator.initializeAsynchronousTransfer(ctx, requestPacket); + return false; + } } // END PartsBodyHandler From 6530497ddb512477d72b91b2ae87b8bd369d0b56 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 12 Nov 2013 11:34:08 +0100 Subject: [PATCH 0184/2389] Introduce a constant exception for Remotely Closed --- .../main/java/org/asynchttpclient/AsyncHttpClient.java | 2 ++ .../org/asynchttpclient/util/AsyncHttpProviderUtils.java | 9 ++++++++- .../java/org/asynchttpclient/async/AuthTimeoutTest.java | 3 ++- .../asynchttpclient/providers/grizzly/HttpTxContext.java | 3 ++- .../providers/netty/handler/NettyChannelHandler.java | 3 ++- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java index 18ddaa77fe..85e19adc55 100755 --- a/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHttpClient.java @@ -20,7 +20,9 @@ import org.asynchttpclient.filter.FilterException; import org.asynchttpclient.filter.RequestFilter; import org.asynchttpclient.resumable.ResumableAsyncHandler; + import java.io.Closeable; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java index a0599eecf6..bca98acabb 100644 --- a/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java +++ b/api/src/main/java/org/asynchttpclient/util/AsyncHttpProviderUtils.java @@ -14,6 +14,7 @@ import java.io.ByteArrayInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.io.SequenceInputStream; import java.io.UnsupportedEncodingException; @@ -52,7 +53,13 @@ * The cookies's handling code is from the Netty framework. */ public class AsyncHttpProviderUtils { - + + public static final IOException REMOTELY_CLOSED_EXCEPTION = new IOException("Remotely Closed"); + + static { + REMOTELY_CLOSED_EXCEPTION.setStackTrace(new StackTraceElement[] {}); + } + private final static byte[] NO_BYTES = new byte[0]; public final static String DEFAULT_CHARSET = "ISO-8859-1"; diff --git a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java index 962e996cd2..9cb3d6026b 100644 --- a/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java +++ b/api/src/test/java/org/asynchttpclient/async/AuthTimeoutTest.java @@ -28,6 +28,7 @@ import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Realm; import org.asynchttpclient.Response; +import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; @@ -195,7 +196,7 @@ public void digestFuturePreemptiveAuthTimeoutTest() throws Exception { protected void inspectException(Throwable t) { assertNotNull(t.getCause()); assertEquals(t.getCause().getClass(), IOException.class); - if (!t.getCause().getMessage().startsWith("Remotely Closed")) { + if (t.getCause() != AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION) { fail(); } } diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java index 3ea419bf67..ce4368dd97 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/HttpTxContext.java @@ -17,6 +17,7 @@ import org.asynchttpclient.Request; import org.asynchttpclient.providers.grizzly.bodyhandler.BodyHandler; import org.asynchttpclient.providers.grizzly.statushandler.StatusHandler; +import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.asynchttpclient.websocket.WebSocket; import org.glassfish.grizzly.CloseListener; import org.glassfish.grizzly.CloseType; @@ -67,7 +68,7 @@ public final class HttpTxContext { public void onClosed(Closeable closeable, CloseType type) throws IOException { if (CloseType.REMOTELY.equals(type)) { - abort(new IOException("Remotely Closed")); + abort(AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION); } } }; diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java index 03f68ae246..e2cacfeae7 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/NettyChannelHandler.java @@ -35,6 +35,7 @@ import org.asynchttpclient.providers.netty.future.NettyResponseFuture; import org.asynchttpclient.providers.netty.future.NettyResponseFutures; import org.asynchttpclient.providers.netty.request.NettyRequestSender; +import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -119,7 +120,7 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception { if (future != null && !future.isDone() && !future.isCancelled()) { if (!requestSender.retry(ctx.channel(), future)) { - channels.abort(future, new IOException("Remotely Closed")); + channels.abort(future, AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION); } } else { channels.closeChannel(ctx); From 55989012bc109d03d95d4e74091616bf88fd35b5 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 12 Nov 2013 11:37:23 +0100 Subject: [PATCH 0185/2389] append to previous commit --- .../test/java/org/asynchttpclient/async/RetryRequestTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java index 6c27502c6e..fdbc1af6dc 100644 --- a/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java +++ b/api/src/test/java/org/asynchttpclient/async/RetryRequestTest.java @@ -14,6 +14,7 @@ import org.asynchttpclient.AsyncHttpClient; import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.util.AsyncHttpProviderUtils; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; import org.testng.annotations.Test; @@ -21,6 +22,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.io.OutputStream; @@ -76,7 +78,7 @@ public void testMaxRetry() throws Exception { } catch (Exception t) { assertNotNull(t.getCause()); assertEquals(t.getCause().getClass(), IOException.class); - if (!t.getCause().getMessage().startsWith("Remotely Closed")) { + if (t.getCause() != AsyncHttpProviderUtils.REMOTELY_CLOSED_EXCEPTION) { fail(); } } finally { From d673a45fe5bd4ce890e061417daf6d2a720153b3 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 14 Nov 2013 14:55:42 +0100 Subject: [PATCH 0186/2389] All HTTP methods allow passing a body, close #421 --- .../main/java/org/asynchttpclient/RequestBuilderBase.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java index d737158ade..0a5f6789b1 100644 --- a/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java +++ b/api/src/main/java/org/asynchttpclient/RequestBuilderBase.java @@ -614,7 +614,7 @@ public T setConnectionPoolKeyStrategy(ConnectionPoolKeyStrategy connectionPoolKe } public Request build() { - if ((request.length < 0) && (request.streamData == null) && allowBody(request.getMethod())) { + if (request.length < 0 && request.streamData == null) { // can't concatenate content-length String contentLength = null; if (request.headers != null && request.headers.isEmpty()) { @@ -635,10 +635,6 @@ public Request build() { return request; } - private boolean allowBody(String method) { - return !(method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("OPTIONS") || method.equalsIgnoreCase("TRACE") || method.equalsIgnoreCase("HEAD")); - } - public T addOrReplaceCookie(Cookie cookie) { String cookieKey = cookie.getName(); boolean replace = false; From 40e2536d5336cd781c6dc59c36ccdeef87d70ad1 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 26 Nov 2013 09:43:15 +0100 Subject: [PATCH 0187/2389] Port #424 on master --- .../providers/netty/NettyAsyncHttpProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java index d67821c497..4b820aab87 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProvider.java @@ -55,8 +55,9 @@ public NettyAsyncHttpProvider(AsyncHttpClientConfig config) { @Override public String toString() { + int availablePermits = channels.freeConnections != null ? channels.freeConnections.availablePermits() : 0; return String.format("NettyAsyncHttpProvider4:\n\t- maxConnections: %d\n\t- openChannels: %s\n\t- connectionPools: %s", config.getMaxTotalConnections() - - channels.freeConnections.availablePermits(), channels.openChannels.toString(), channels.connectionsPool.toString()); + - availablePermits, channels.openChannels.toString(), channels.connectionsPool.toString()); } @Override From aa42d85261c632049ed99747cd3705e5d6c842a4 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 28 Nov 2013 22:28:16 +0100 Subject: [PATCH 0188/2389] Upgrade Netty 4.0.13 --- providers/netty/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/pom.xml b/providers/netty/pom.xml index 9b884d134d..818df789ec 100644 --- a/providers/netty/pom.xml +++ b/providers/netty/pom.xml @@ -39,7 +39,7 @@ io.netty netty-all - 4.0.12.Final + 4.0.13.Final org.javassist From 19644726ce7f7fe10d14a1e560d0cdc325cf973f Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 29 Nov 2013 15:35:22 +0100 Subject: [PATCH 0189/2389] Allow Multipart with unknown content length, close #427 --- .../org/asynchttpclient/multipart/MultipartBody.java | 4 ++-- .../providers/netty/request/NettyRequestSender.java | 9 ++++++++- .../providers/netty/request/NettyRequests.java | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java index f72aaf62c1..99525d0a21 100644 --- a/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java +++ b/api/src/main/java/org/asynchttpclient/multipart/MultipartBody.java @@ -49,9 +49,9 @@ public class MultipartBody implements RandomAccessBody { enum FileLocation {NONE, START, MIDDLE, END} - public MultipartBody(List parts, String contentType, String contentLength) { + public MultipartBody(List parts, String contentType, long contentLength) { this.boundary = MultipartEncodingUtil.getAsciiBytes(contentType.substring(contentType.indexOf("boundary=") + "boundary=".length())); - this.contentLength = Long.parseLong(contentLength); + this.contentLength = contentLength; this.parts = parts; files = new ArrayList(); diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java index 5c049d70ba..3a83fcc695 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java @@ -439,7 +439,14 @@ private Body computeBody(HttpRequest nettyRequest, NettyResponseFuture future } } else if (future.getRequest().getParts() != null) { String contentType = headers.get(HttpHeaders.Names.CONTENT_TYPE); - String length = headers.get(HttpHeaders.Names.CONTENT_LENGTH); + String contentLength = nettyRequest.headers().get(HttpHeaders.Names.CONTENT_LENGTH); + + long length = -1; + if (contentLength != null) { + length = Long.parseLong(contentLength); + } else { + nettyRequest.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED); + } body = new MultipartBody(future.getRequest().getParts(), contentType, length); } diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java index d5821471eb..3827789185 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequests.java @@ -260,7 +260,9 @@ else if (uri.getRawQuery() != null) MultipartRequestEntity mre = AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(), request.getHeaders()); headers.put(HttpHeaders.Names.CONTENT_TYPE, mre.getContentType()); - headers.put(HttpHeaders.Names.CONTENT_LENGTH, mre.getContentLength()); + if (mre.getContentLength() >= 0) { + headers.put(HttpHeaders.Names.CONTENT_LENGTH, mre.getContentLength()); + } hasDeferredContent = true; } else if (request.getFile() != null) { From 895adc259fd3b9ef2f1f63b7dd026a92b6e82b15 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Fri, 29 Nov 2013 15:38:33 +0100 Subject: [PATCH 0190/2389] dammit --- .../providers/grizzly/bodyhandler/PartsBodyHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java index f4491f391f..5dcc1bc710 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/PartsBodyHandler.java @@ -67,8 +67,7 @@ public boolean doHandle(final FilterChainContext ctx, final FeedableBodyGenerator generator = new FeedableBodyGenerator() { @Override public Body createBody() throws IOException { - return new MultipartBody(parts, contentType, - String.valueOf(contentLength)); + return new MultipartBody(parts, contentType, contentLength); } }; generator.setFeeder(new FeedableBodyGenerator.BaseFeeder(generator) { From 81d59c1dd45a51359913d0b907542f6fe40a37c0 Mon Sep 17 00:00:00 2001 From: Jeanfrancois Arcand Date: Tue, 3 Dec 2013 16:24:29 -0500 Subject: [PATCH 0191/2389] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82921e4652..1eb2503dad 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Async Http Client library purpose is to allow Java applications to easily execut com.ning async-http-client - 1.7.20 + 1.7.22 ``` From 01aa462959ef98e64f8019856d5009813fcb09d8 Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 3 Dec 2013 19:41:54 -0800 Subject: [PATCH 0192/2389] Fix compilation error. --- .../java/org/asynchttpclient/multipart/MultipartBodyTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java index 1e8ba2860c..ceb62a8dd0 100644 --- a/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java +++ b/api/src/test/java/org/asynchttpclient/multipart/MultipartBodyTest.java @@ -79,7 +79,7 @@ private static void compareContentLength(final List parts) { final long expectedContentLength = mre.getContentLength(); // get real bytes - final Body multipartBody = new MultipartBody(parts, mre.getContentType(), String.valueOf(expectedContentLength)); + final Body multipartBody = new MultipartBody(parts, mre.getContentType(), expectedContentLength); try { final ByteBuffer buffer = ByteBuffer.allocate(8192); boolean last = false; From 22cb35acf9f55526917a93c7bb5d37933d6e44da Mon Sep 17 00:00:00 2001 From: Ryan Lubke Date: Tue, 3 Dec 2013 19:45:17 -0800 Subject: [PATCH 0193/2389] Fix for #429. --- .../providers/grizzly/bodyhandler/ByteArrayBodyHandler.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ByteArrayBodyHandler.java b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ByteArrayBodyHandler.java index 9ed538e5fe..c995adef2c 100644 --- a/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ByteArrayBodyHandler.java +++ b/providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/bodyhandler/ByteArrayBodyHandler.java @@ -46,11 +46,7 @@ public boolean doHandle(final FilterChainContext ctx, final HttpRequestPacket requestPacket) throws IOException { - String charset = request.getBodyEncoding(); - if (charset == null) { - charset = Charsets.ASCII_CHARSET.name(); - } - final byte[] data = new String(request.getByteData(), charset).getBytes(charset); + final byte[] data = request.getByteData(); final MemoryManager mm = ctx.getMemoryManager(); final Buffer gBuffer = Buffers.wrap(mm, data); if (requestPacket.getContentLength() == -1) { From ed9f9b3b2758ab6b545ff8f294f4eabb604bd338 Mon Sep 17 00:00:00 2001 From: Lukasz Kryger Date: Sun, 8 Dec 2013 22:32:07 +0000 Subject: [PATCH 0194/2389] Nitpicking: "it's" -> "its" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1eb2503dad..561933cd2f 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Future f = c.prepareGet("http://www.ning.com/").execute(new AsyncHandler String bodyResponse = f.get(); ``` -Finally, you can also configure the AsyncHttpClient via it's AsyncHttpClientConfig object: +Finally, you can also configure the AsyncHttpClient via its AsyncHttpClientConfig object: ```java AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder() From 8373cc31ac81498c45a6471163df43c6a0db6029 Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 12 Dec 2013 12:14:26 +0100 Subject: [PATCH 0195/2389] Implement onRequestSent for Netty provider, close #434 --- .../AsyncHandlerExtensions.java | 38 +++++++++++++++++++ .../netty/request/NettyRequestSender.java | 4 ++ 2 files changed, 42 insertions(+) create mode 100644 api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java diff --git a/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java b/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java new file mode 100644 index 0000000000..858d14201f --- /dev/null +++ b/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2010-2012 Sonatype, Inc. All rights reserved. + * + * This program is licensed to you under the Apache License Version 2.0, + * and you may not use this file except in compliance with the Apache License Version 2.0. + * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the Apache License Version 2.0 is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. + */ +package org.asynchttpclient; + +/** + * This interface hosts new low level callback methods on {@link AsyncHandler}. + * For now, those methods are in a dedicated interface in order not to break the existing API, + * but could be merged into one of the existing ones in AHC 2. + * + * More additional hooks might come, such as: + *

      + *
    • onRetry()
    • + *
    • onConnected()
    • + *
    • onConnectionClosed()
    • + *
    • onBytesSent(long numberOfBytes)
    • + *
    • onBytesReceived(long numberOfBytes)
    • + *
    + */ +public interface AsyncHandlerExtensions { + + /** + * Notify the callback when a request is being written on the wire. + * If the original request causes multiple requests to be sent, for example, because of authorization or retry, + * it will be notified multiple times. + * Currently only supported by the Netty provider. + */ + void onRequestSent(); +} \ No newline at end of file diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java index 3a83fcc695..364c36567a 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestSender.java @@ -45,6 +45,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.asynchttpclient.AsyncHandler; +import org.asynchttpclient.AsyncHandlerExtensions; import org.asynchttpclient.AsyncHttpClientConfig; import org.asynchttpclient.Body; import org.asynchttpclient.BodyGenerator; @@ -501,6 +502,9 @@ public final void writeRequest(final Channel channel, final AsyncHttpClientC // FIXME That doesn't just leave to true, the set is always done? and what's the point of not having a is/get? if (future.getAndSetWriteHeaders(true)) { try { + if (future.getAsyncHandler() instanceof AsyncHandlerExtensions) { + AsyncHandlerExtensions.class.cast(future.getAsyncHandler()).onRequestSent(); + } channel.writeAndFlush(nettyRequest, channel.newProgressivePromise()).addListener(new ProgressListener(config, true, future.getAsyncHandler(), future)); } catch (Throwable cause) { // FIXME why not notify? From 31b3f44079ff5cfa7be277d6e793e1c129e4189a Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 12 Dec 2013 12:17:07 +0100 Subject: [PATCH 0196/2389] Fix deprecation --- .../org/asynchttpclient/providers/netty/channel/Channels.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java index bc1f091d02..b5bbbb51dc 100644 --- a/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java +++ b/providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/Channels.java @@ -77,7 +77,7 @@ public class Channels { public static final String WS_DECODER_HANDLER = "ws-decoder"; public static final String WS_ENCODER_HANDLER = "ws-encoder"; - private static final AttributeKey DEFAULT_ATTRIBUTE = new AttributeKey("default"); + private static final AttributeKey DEFAULT_ATTRIBUTE = AttributeKey.valueOf("default"); private final AsyncHttpClientConfig config; private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig; From 18b73b7433977f6a58cd17b67599342e99bbb8cb Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Thu, 12 Dec 2013 12:20:41 +0100 Subject: [PATCH 0197/2389] Add new onRetry callback method for #435 --- .../java/org/asynchttpclient/AsyncHandlerExtensions.java | 8 ++++++-- .../providers/netty/request/NettyRequestSender.java | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java b/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java index 858d14201f..1991d0aba1 100644 --- a/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java +++ b/api/src/main/java/org/asynchttpclient/AsyncHandlerExtensions.java @@ -19,7 +19,6 @@ * * More additional hooks might come, such as: *