From fb2ca29364c2e3fdc822727a397d0092e2f76cf5 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 14 Sep 2012 00:31:52 +0200 Subject: [PATCH] jetty-9 - HTTP client: updated to work also with SSL. --- .../org/eclipse/jetty/client/HttpClient.java | 246 ++++++++++-------- .../eclipse/jetty/client/HttpConnection.java | 7 +- .../org/eclipse/jetty/client/HttpSender.java | 1 - .../client/AbstractHttpClientServerTest.java | 36 ++- .../client/HttpClientAuthenticationTest.java | 12 +- .../jetty/client/HttpClientRedirectTest.java | 16 +- .../jetty/client/HttpClientStreamTest.java | 7 + .../eclipse/jetty/client/HttpClientTest.java | 56 +++- .../client/HttpConnectionLifecycleTest.java | 19 +- .../eclipse/jetty/client/HttpCookieTest.java | 8 +- .../jetty/client/HttpDestinationTest.java | 6 + .../jetty/client/HttpRequestAbortTest.java | 10 + .../jetty/client/HttpResponseAbortTest.java | 11 +- .../test/resources/jetty-logging.properties | 1 + jetty-client/src/test/resources/keystore.jks | Bin 0 -> 2206 bytes .../src/test/resources/truststore.jks | Bin 0 -> 916 bytes 16 files changed, 289 insertions(+), 147 deletions(-) create mode 100644 jetty-client/src/test/resources/keystore.jks create mode 100644 jetty-client/src/test/resources/truststore.jks diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index dba21c5dc61..6e1bd429105 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -102,12 +102,11 @@ public class HttpClient extends AggregateLifeCycle private final List requestListeners = new CopyOnWriteArrayList<>(); private final CookieStore cookieStore = new HttpCookieStore(); private final AuthenticationStore authenticationStore = new HttpAuthenticationStore(); + private final SslContextFactory sslContextFactory; private volatile Executor executor; private volatile ByteBufferPool byteBufferPool; private volatile Scheduler scheduler; private volatile SelectorManager selectorManager; - private volatile SslContextFactory sslContextFactory; - private volatile String agent = "Jetty/" + Jetty.VERSION; private volatile boolean followRedirects = true; private volatile int maxConnectionsPerAddress = 8; @@ -123,14 +122,10 @@ public class HttpClient extends AggregateLifeCycle this(null); } - public HttpClient(Executor executor) + public HttpClient(SslContextFactory sslContextFactory) { - this.executor = executor; - } - - public ByteBufferPool getByteBufferPool() - { - return byteBufferPool; + this.sslContextFactory = sslContextFactory; + addBean(sslContextFactory); } public SslContextFactory getSslContextFactory() @@ -201,34 +196,6 @@ public class HttpClient extends AggregateLifeCycle return authenticationStore; } - public long getIdleTimeout() - { - return idleTimeout; - } - - public void setIdleTimeout(long idleTimeout) - { - this.idleTimeout = idleTimeout; - } - - /** - * @return the address to bind socket channels to - * @see #setBindAddress(SocketAddress) - */ - public SocketAddress getBindAddress() - { - return bindAddress; - } - - /** - * @param bindAddress the address to bind socket channels to - * @see #getBindAddress() - */ - public void setBindAddress(SocketAddress bindAddress) - { - this.bindAddress = bindAddress; - } - public Future GET(String uri) { return GET(URI.create(uri)); @@ -296,26 +263,6 @@ public class HttpClient extends AggregateLifeCycle return new ArrayList(destinations.values()); } - public String getUserAgent() - { - return agent; - } - - public void setUserAgent(String agent) - { - this.agent = agent; - } - - public boolean isFollowRedirects() - { - return followRedirects; - } - - public void setFollowRedirects(boolean follow) - { - this.followRedirects = follow; - } - public void send(Request request, Response.Listener listener) { String scheme = request.scheme().toLowerCase(); @@ -330,61 +277,6 @@ public class HttpClient extends AggregateLifeCycle provideDestination(scheme, host, port).send(request, listener); } - public Executor getExecutor() - { - return executor; - } - - public int getMaxConnectionsPerAddress() - { - return maxConnectionsPerAddress; - } - - public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress) - { - this.maxConnectionsPerAddress = maxConnectionsPerAddress; - } - - public int getMaxQueueSizePerAddress() - { - return maxQueueSizePerAddress; - } - - public void setMaxQueueSizePerAddress(int maxQueueSizePerAddress) - { - this.maxQueueSizePerAddress = maxQueueSizePerAddress; - } - - public int getRequestBufferSize() - { - return requestBufferSize; - } - - public void setRequestBufferSize(int requestBufferSize) - { - this.requestBufferSize = requestBufferSize; - } - - public int getResponseBufferSize() - { - return responseBufferSize; - } - - public void setResponseBufferSize(int responseBufferSize) - { - this.responseBufferSize = responseBufferSize; - } - - public int getMaxRedirects() - { - return maxRedirects; - } - - public void setMaxRedirects(int maxRedirects) - { - this.maxRedirects = maxRedirects; - } - protected void newConnection(HttpDestination destination, Callback callback) { SocketChannel channel = null; @@ -454,6 +346,134 @@ public class HttpClient extends AggregateLifeCycle return null; } + public ByteBufferPool getByteBufferPool() + { + return byteBufferPool; + } + + public void setByteBufferPool(ByteBufferPool byteBufferPool) + { + this.byteBufferPool = byteBufferPool; + } + + public long getIdleTimeout() + { + return idleTimeout; + } + + public void setIdleTimeout(long idleTimeout) + { + this.idleTimeout = idleTimeout; + } + + /** + * @return the address to bind socket channels to + * @see #setBindAddress(SocketAddress) + */ + public SocketAddress getBindAddress() + { + return bindAddress; + } + + /** + * @param bindAddress the address to bind socket channels to + * @see #getBindAddress() + */ + public void setBindAddress(SocketAddress bindAddress) + { + this.bindAddress = bindAddress; + } + + public String getUserAgent() + { + return agent; + } + + public void setUserAgent(String agent) + { + this.agent = agent; + } + + public boolean isFollowRedirects() + { + return followRedirects; + } + + public void setFollowRedirects(boolean follow) + { + this.followRedirects = follow; + } + + public Executor getExecutor() + { + return executor; + } + + public void setExecutor(Executor executor) + { + this.executor = executor; + } + + public Scheduler getScheduler() + { + return scheduler; + } + + public void setScheduler(Scheduler scheduler) + { + this.scheduler = scheduler; + } + + public int getMaxConnectionsPerAddress() + { + return maxConnectionsPerAddress; + } + + public void setMaxConnectionsPerAddress(int maxConnectionsPerAddress) + { + this.maxConnectionsPerAddress = maxConnectionsPerAddress; + } + + public int getMaxQueueSizePerAddress() + { + return maxQueueSizePerAddress; + } + + public void setMaxQueueSizePerAddress(int maxQueueSizePerAddress) + { + this.maxQueueSizePerAddress = maxQueueSizePerAddress; + } + + public int getRequestBufferSize() + { + return requestBufferSize; + } + + public void setRequestBufferSize(int requestBufferSize) + { + this.requestBufferSize = requestBufferSize; + } + + public int getResponseBufferSize() + { + return responseBufferSize; + } + + public void setResponseBufferSize(int responseBufferSize) + { + this.responseBufferSize = responseBufferSize; + } + + public int getMaxRedirects() + { + return maxRedirects; + } + + public void setMaxRedirects(int maxRedirects) + { + this.maxRedirects = maxRedirects; + } + protected class ClientSelectorManager extends SelectorManager { public ClientSelectorManager() @@ -490,7 +510,7 @@ public class HttpClient extends AggregateLifeCycle else { SSLEngine engine = sslContextFactory.newSSLEngine(endPoint.getRemoteAddress()); - engine.setUseClientMode(false); + engine.setUseClientMode(true); SslConnection sslConnection = new SslConnection(getByteBufferPool(), getExecutor(), endPoint, engine); diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java index c7a03c02dbe..d917cd84c8e 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpConnection.java @@ -200,8 +200,7 @@ public class HttpConnection extends AbstractConnection implements Connection HttpExchange exchange = getExchange(); if (exchange != null) exchange.receive(); - else - throw new IllegalStateException(); + // If there is no exchange, we just ignore because the selector may be woken up by a remote close } protected void receive() @@ -258,7 +257,9 @@ public class HttpConnection extends AbstractConnection implements Connection @Override public void close() { - super.close(); + getEndPoint().shutdownOutput(); + LOG.debug("{} oshut", this); + getEndPoint().close(); LOG.debug("{} closed", this); } diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java index e75854fc1bf..c3c261e96e0 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpSender.java @@ -242,7 +242,6 @@ public class HttpSender BufferUtil.clear(header); BufferUtil.clear(chunk); releaseBuffers(); - connection.getEndPoint().shutdownOutput(); generator.abort(); failed = true; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpClientServerTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpClientServerTest.java index 48ce8e3efa7..4c207fa9965 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpClientServerTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/AbstractHttpClientServerTest.java @@ -18,18 +18,31 @@ package org.eclipse.jetty.client; +import java.util.Arrays; +import java.util.Collection; + import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.SelectChannelConnector; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.After; import org.junit.Rule; import org.junit.rules.TestWatchman; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import org.junit.runners.model.FrameworkMethod; -public class AbstractHttpClientServerTest +@RunWith(Parameterized.class) +public abstract class AbstractHttpClientServerTest { + @Parameterized.Parameters + public static Collection parameters() + { + return Arrays.asList(new SslContextFactory[]{null}, new SslContextFactory[]{new SslContextFactory()}); + } + @Rule public final TestWatchman testName = new TestWatchman() { @@ -43,22 +56,39 @@ public class AbstractHttpClientServerTest } }; + protected SslContextFactory sslContextFactory; + protected String scheme; protected Server server; protected HttpClient client; protected NetworkConnector connector; + public AbstractHttpClientServerTest(SslContextFactory sslContextFactory) + { + this.sslContextFactory = sslContextFactory; + this.scheme = sslContextFactory == null ? "http" : "https"; + } + public void start(Handler handler) throws Exception { + if (sslContextFactory != null) + { + sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks"); + sslContextFactory.setKeyStorePassword("storepwd"); + sslContextFactory.setTrustStorePath("src/test/resources/truststore.jks"); + sslContextFactory.setTrustStorePassword("storepwd"); + } + if (server == null) server = new Server(); - connector = new SelectChannelConnector(server); + connector = new SelectChannelConnector(server, sslContextFactory); server.addConnector(connector); server.setHandler(handler); server.start(); QueuedThreadPool executor = new QueuedThreadPool(); executor.setName(executor.getName() + "-client"); - client = new HttpClient(executor); + client = new HttpClient(sslContextFactory); + client.setExecutor(executor); client.start(); } diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java index 7a06dca80c5..19e3b33d2c7 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java @@ -40,6 +40,7 @@ import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.security.Constraint; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; @@ -47,6 +48,11 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest { private String realm = "TestRealm"; + public HttpClientAuthenticationTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + public void startBasic(Handler handler) throws Exception { start(new BasicAuthenticator(), handler); @@ -86,14 +92,14 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest public void test_BasicAuthentication() throws Exception { startBasic(new EmptyServerHandler()); - test_Authentication(new BasicAuthentication("http://localhost:" + connector.getLocalPort(), realm, "basic", "basic")); + test_Authentication(new BasicAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "basic", "basic")); } @Test public void test_DigestAuthentication() throws Exception { startDigest(new EmptyServerHandler()); - test_Authentication(new DigestAuthentication("http://localhost:" + connector.getLocalPort(), realm, "digest", "digest")); + test_Authentication(new DigestAuthentication(scheme + "://localhost:" + connector.getLocalPort(), realm, "digest", "digest")); } private void test_Authentication(Authentication authentication) throws Exception @@ -112,7 +118,7 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest client.getRequestListeners().add(requestListener); // Request without Authentication causes a 401 - Request request = client.newRequest("localhost", connector.getLocalPort()).path("/test"); + Request request = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).path("/test"); ContentResponse response = request.send().get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals(401, response.status()); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientRedirectTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientRedirectTest.java index 36b2f3e5bcf..540ef62ee76 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientRedirectTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientRedirectTest.java @@ -34,6 +34,7 @@ import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.IO; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,8 +43,13 @@ import static org.junit.Assert.fail; public class HttpClientRedirectTest extends AbstractHttpClientServerTest { + public HttpClientRedirectTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Before - public void init() throws Exception + public void prepare() throws Exception { start(new RedirectHandler()); } @@ -52,6 +58,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest public void test_303() throws Exception { Response response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .path("/303/localhost/done") .send().get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); @@ -63,6 +70,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest public void test_303_302() throws Exception { Response response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .path("/303/localhost/302/localhost/done") .send().get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); @@ -74,6 +82,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest public void test_303_302_OnDifferentDestinations() throws Exception { Response response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .path("/303/127.0.0.1/302/localhost/done") .send().get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); @@ -85,6 +94,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest public void test_301() throws Exception { Response response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .method(HttpMethod.HEAD) .path("/301/localhost/done") .send().get(5, TimeUnit.SECONDS); @@ -99,6 +109,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest try { client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .method(HttpMethod.POST) .path("/301/localhost/done") .send().get(5, TimeUnit.SECONDS); @@ -119,6 +130,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest { byte[] data = new byte[]{0, 1, 2, 3, 4, 5, 6, 7}; ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .method(HttpMethod.POST) .path("/307/localhost/done") .content(new ByteBufferContentProvider(ByteBuffer.wrap(data))) @@ -137,6 +149,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest try { client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .path("/303/localhost/302/localhost/done") .send().get(5, TimeUnit.SECONDS); fail(); @@ -155,6 +168,7 @@ public class HttpClientRedirectTest extends AbstractHttpClientServerTest public void test_303_WithConnectionClose_WithBigRequest() throws Exception { Response response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .path("/303/localhost/done?close=true") .send().get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java index 6bc17b34895..ca28699e8a2 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientStreamTest.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; @@ -35,6 +36,11 @@ import static java.nio.file.StandardOpenOption.CREATE; public class HttpClientStreamTest extends AbstractHttpClientServerTest { + public HttpClientStreamTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void testFileUpload() throws Exception { @@ -53,6 +59,7 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest final AtomicLong requestTime = new AtomicLong(); ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .file(upload) .listener(new Request.Listener.Empty() { diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index e9380ef0eb1..4ae11a4c2ce 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -25,9 +25,9 @@ import java.nio.ByteBuffer; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.NoSuchElementException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -47,6 +47,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.annotation.Slow; import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; @@ -54,12 +55,16 @@ import static java.nio.file.StandardOpenOption.CREATE; public class HttpClientTest extends AbstractHttpClientServerTest { + public HttpClientTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void testStoppingClosesConnections() throws Exception { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); String path = "/"; @@ -93,7 +98,6 @@ public class HttpClientTest extends AbstractHttpClientServerTest { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); client.GET(scheme + "://" + host + ":" + port).get(5, TimeUnit.SECONDS); @@ -113,7 +117,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest { start(new EmptyServerHandler()); - Response response = client.GET("http://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS); + Response response = client.GET(scheme + "://localhost:" + connector.getLocalPort()).get(555, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals(200, response.status()); @@ -133,7 +137,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest } }); - ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS); + ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort()).get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals(200, response.status()); @@ -165,7 +169,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest String value1 = "\u20AC"; String paramValue1 = URLEncoder.encode(value1, "UTF-8"); String query = paramName1 + "=" + paramValue1 + "&" + paramName2; - ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS); + ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals(200, response.status()); @@ -201,7 +205,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest String paramValue12 = URLEncoder.encode(value12, "UTF-8"); String paramValue2 = URLEncoder.encode(value2, "UTF-8"); String query = paramName1 + "=" + paramValue11 + "&" + paramName1 + "=" + paramValue12 + "&" + paramName2 + "=" + paramValue2; - ContentResponse response = client.GET("http://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS); + ContentResponse response = client.GET(scheme + "://localhost:" + connector.getLocalPort() + "/?" + query).get(5, TimeUnit.SECONDS); Assert.assertNotNull(response); Assert.assertEquals(200, response.status()); @@ -218,7 +222,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(2); - client.newRequest("http://localhost:" + connector.getLocalPort()) + client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new org.eclipse.jetty.client.api.Request.Listener.Empty() { @Override @@ -244,7 +249,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest } }); - client.newRequest("http://localhost:" + connector.getLocalPort()) + client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new org.eclipse.jetty.client.api.Request.Listener.Empty() { @Override @@ -277,7 +283,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest client.setIdleTimeout(idleTimeout); final CountDownLatch latch = new CountDownLatch(3); - client.newRequest("http://localhost:" + connector.getLocalPort()) + client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new org.eclipse.jetty.client.api.Request.Listener.Empty() { @Override @@ -308,7 +315,8 @@ public class HttpClientTest extends AbstractHttpClientServerTest } }); - client.newRequest("http://localhost:" + connector.getLocalPort()) + client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .send(new Response.Listener.Empty() { @Override @@ -344,6 +352,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest final AtomicLong requestTime = new AtomicLong(); final AtomicLong responseTime = new AtomicLong(); client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .file(file) .listener(new org.eclipse.jetty.client.api.Request.Listener.Empty() { @@ -399,6 +408,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) // The second ByteBuffer set to null will throw an exception .content(new ContentProvider() { @@ -411,7 +421,26 @@ public class HttpClientTest extends AbstractHttpClientServerTest @Override public Iterator iterator() { - return Arrays.asList(ByteBuffer.allocate(chunkSize), null).iterator(); + return new Iterator() + { + @Override + public boolean hasNext() + { + return true; + } + + @Override + public ByteBuffer next() + { + throw new NoSuchElementException("explicitly_thrown_by_test"); + } + + @Override + public void remove() + { + throw new UnsupportedOperationException(); + } + }; } }) .send(new Response.Listener.Empty() @@ -435,12 +464,13 @@ public class HttpClientTest extends AbstractHttpClientServerTest final String host = "localhost"; final int port = connector.getLocalPort(); client.newRequest(host, port) + .scheme(scheme) .listener(new org.eclipse.jetty.client.api.Request.Listener.Empty() { @Override public void onBegin(org.eclipse.jetty.client.api.Request request) { - HttpDestination destination = (HttpDestination)client.getDestination("http", host, port); + HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); destination.getActiveConnections().peek().close(); } }) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java index 5746d4a6d16..50649952439 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpConnectionLifecycleTest.java @@ -34,17 +34,22 @@ import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.client.util.ByteBufferContentProvider; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest { + public HttpConnectionLifecycleTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void test_SuccessfulRequest_ReturnsConnection() throws Exception { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -58,6 +63,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch headersLatch = new CountDownLatch(1); final CountDownLatch successLatch = new CountDownLatch(3); client.newRequest(host, port) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -102,7 +108,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -115,7 +120,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch headersLatch = new CountDownLatch(1); final CountDownLatch failureLatch = new CountDownLatch(2); - client.newRequest(host, port).listener(new Request.Listener.Empty() + client.newRequest(host, port).scheme(scheme).listener(new Request.Listener.Empty() { @Override public void onBegin(Request request) @@ -153,7 +158,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -166,6 +170,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch successLatch = new CountDownLatch(3); client.newRequest(host, port) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -211,7 +216,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest { start(new EmptyServerHandler()); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -226,6 +230,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch failureLatch = new CountDownLatch(2); client.newRequest(host, port) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -263,7 +268,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest } }); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -276,6 +280,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest(host, port) + .scheme(scheme) .send(new Response.Listener.Empty() { @Override @@ -307,7 +312,6 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest } }); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); HttpDestination destination = (HttpDestination)client.getDestination(scheme, host, port); @@ -320,6 +324,7 @@ public class HttpConnectionLifecycleTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest(host, port) + .scheme(scheme) .content(new ByteBufferContentProvider(ByteBuffer.allocate(16 * 1024 * 1024))) .send(new Response.Listener.Empty() { diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpCookieTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpCookieTest.java index b1cbf7c6e1f..68b434b7990 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpCookieTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpCookieTest.java @@ -31,11 +31,17 @@ import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.http.HttpCookie; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; public class HttpCookieTest extends AbstractHttpClientServerTest { + public HttpCookieTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void test_CookieIsStored() throws Exception { @@ -51,7 +57,6 @@ public class HttpCookieTest extends AbstractHttpClientServerTest } }); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); String path = "/path"; @@ -86,7 +91,6 @@ public class HttpCookieTest extends AbstractHttpClientServerTest } }); - String scheme = "http"; String host = "localhost"; int port = connector.getLocalPort(); String path = "/path"; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpDestinationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpDestinationTest.java index 9cebbf403bc..47a86e20490 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpDestinationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpDestinationTest.java @@ -23,12 +23,18 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.toolchain.test.annotation.Slow; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class HttpDestinationTest extends AbstractHttpClientServerTest { + public HttpDestinationTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Before public void init() throws Exception { diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java index a6c15f85246..ca346f767ab 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpRequestAbortTest.java @@ -33,6 +33,7 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.client.util.ByteBufferContentProvider; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.util.IO; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; @@ -41,6 +42,11 @@ import static org.junit.Assert.fail; public class HttpRequestAbortTest extends AbstractHttpClientServerTest { + public HttpRequestAbortTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void testAbortOnQueued() throws Exception { @@ -50,6 +56,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest try { client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -85,6 +92,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest try { client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -117,6 +125,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest start(new EmptyServerHandler()); ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override @@ -158,6 +167,7 @@ public class HttpRequestAbortTest extends AbstractHttpClientServerTest try { ContentResponse response = client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .listener(new Request.Listener.Empty() { @Override diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpResponseAbortTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpResponseAbortTest.java index 30a5dbb5cca..f546340f353 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpResponseAbortTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpResponseAbortTest.java @@ -36,11 +36,17 @@ import org.eclipse.jetty.client.api.Response; import org.eclipse.jetty.client.api.Result; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.junit.Assert; import org.junit.Test; public class HttpResponseAbortTest extends AbstractHttpClientServerTest { + public HttpResponseAbortTest(SslContextFactory sslContextFactory) + { + super(sslContextFactory); + } + @Test public void testAbortOnBegin() throws Exception { @@ -48,6 +54,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .send(new Response.Listener.Empty() { @Override @@ -73,6 +80,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .send(new Response.Listener.Empty() { @Override @@ -117,6 +125,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest final CountDownLatch latch = new CountDownLatch(1); client.newRequest("localhost", connector.getLocalPort()) + .scheme(scheme) .send(new Response.Listener.Empty() { @Override @@ -160,7 +169,7 @@ public class HttpResponseAbortTest extends AbstractHttpClientServerTest } }); - Future future = client.newRequest("localhost", connector.getLocalPort()).send(); + Future future = client.newRequest("localhost", connector.getLocalPort()).scheme(scheme).send(); ref.set(future); latch.countDown(); diff --git a/jetty-client/src/test/resources/jetty-logging.properties b/jetty-client/src/test/resources/jetty-logging.properties index 01824b988bf..b53f7809211 100644 --- a/jetty-client/src/test/resources/jetty-logging.properties +++ b/jetty-client/src/test/resources/jetty-logging.properties @@ -1,2 +1,3 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog +#org.eclipse.jetty.LEVEL=DEBUG org.eclipse.jetty.client.LEVEL=DEBUG diff --git a/jetty-client/src/test/resources/keystore.jks b/jetty-client/src/test/resources/keystore.jks new file mode 100644 index 0000000000000000000000000000000000000000..428ba54776ede2fdcdeedd879edb927c2abd9953 GIT binary patch literal 2206 zcmcgt`9Bkm8{cNkoMUp6gmShKn!AQX*(l6Nj(i=TnQPOKYtv{*Wg>ItE=Q!pRYH8a z$Sp#S#2lYw#aw;$y9u4T}83H*%lp zAKZay0sy=q1Qoo85aAQh;$ zD(c2EIN#D7WwYDLKUg!CotQPD@dp;5FR#bgaace(^x$6g5frD~(_b(MI^J&*A2DRp zf5Q2onfE(zvUb9|9C`66)YFRNM6~xrz4;iVbU=P|*YT2eWHFJJtr+M@zt2qPm)K~rRcqcs=LM12)PX0TT%QO zlf*xkqD3}7l)1J`5W(>=9nR0e6j-<79<11v3ZuXXcQpoCsqY~n`$FN+S}hcVm5Y>G zXnD{@DYs1@{S0z(lW+?86LWKtku$$-(khsh>0qRUXn=84`GRn?77M^_JY`durnN;KE zW#OJ`h<6xcB{I))ekGpc*Ylt}0cx4|OMBDPQvx4`r`}4Ze5_ipdObGMTi3bZHd5PC zcY0;?uBWu$PSvjJeb87nY7ghNv?%M@SoDl6IWt`bQCosfSh$#D6$ea~QhKM^ud2Ut z+9PYJuVpoELmN-A`F$BicO{BSYg@#tS%avVfb}DxL)|NanJ)#zB!2~?#Ot%H7--9N zU$bs0fS5G!m5M4&WK3#a|H|Tgw*?X-;H+Lu@kwA>qSR~7UC7b)7MJXTn6PG>n@8jP zW+}F^X$$c;U~4ryqRF; z>`j!tbLMK4ZGyY643|~?%Mu#fm!l%wAKjBDmd+VYmp3S#$scD$~bxbf|z#)hShN0*AhRaPDcmqrftGlHq4^54MM$Xfy(2> zH8QYVMzmn_oHbvJCB`IN~E&{1*h&0gEM{e zKvWvzp(!BqMX8`t#)~0nq}Wa zr6>FRPyp;AAB&)1$5@;r$23J{K&~>TWjZf7V$wFzmGM95CXhFG1cJNVAXks}C+&2- zbf9Qn*D8N}Afd2kpwDxns3%1uaFhAqDV8ksWiWY|quuLGZ0)SqrJ!Y8yX}@}IyC$C zQ3rCUsn}#>F#D8%D?q~ySy4j&he%Bs{{7V%rl!ui`@KQP?NTi+_iN{cwom&9RaMRR zB~z!hz|0HAgB9_Ijvpe-zr#jLbckJsc>vmo{+im?t8lA;N#fD4?{lb&J0V8Gocq%; f1ihv=QIDh{M_<9V+45Z2{KE4_qW}V3B0uV%GgrOJ literal 0 HcmV?d00001 diff --git a/jetty-client/src/test/resources/truststore.jks b/jetty-client/src/test/resources/truststore.jks new file mode 100644 index 0000000000000000000000000000000000000000..839cb8c35151c2b7c64afca24b6b72caad070a05 GIT binary patch literal 916 zcmezO_TO6u1_mY|W(3o$xs} zE~X|%Muz1J{3AIFGbaABoD&*5saD@gH|APIn|qhRGl}gsUzm=o9G*UXZaLfkb^*)o zjA*-gTf)`m_MQJYE&gJ}p^PHkrj!4^W|XX5a=N7A{;n#yaON&k_bHloe-^*hm?Z91 zlB>xeD=<(C>yn{9D54u}krkl}HQ(Uscha(++qf!T9y+xaEfnXd1O zi0)T?voO%;QH9LK;*_O3mBblqm)!31vU@hm;^%>mh5U@y3R%l0gzi`2yxH!+?kPOi zt!Tnsz1x9B3U2~8STZp)GB6^C5HPs_Lx_=~O<3xi>MmQ;D_g$D<_pdct`+TyzWTQ= zW5Finm(sGEe;ty^>vg$!cV)t>;H#Mev23$*WWBpyJ}Ir;RW+Htrt6{Pk&qz&-XG2@ z8@{&Lu%DX7m47Uny+-3w`=4V611q#Ub(U`xZCtSK^2LO^3(s|HW&N14dV4@A&(kX% z*S_eUPs-bSWRp>avt;CP@7K+G&3=b&1eO-s3f`;Cf91p#$)FW&xME3L8sEBQQDVCvfG>mdwqnk+GXd2ihXqpv z;usF(WoYYmu8DZZa4%1z=+hI+*gpkUykAy5tj#grb*gH!M6TqIcifYBGVe^&T#-2O K*=+x>r_BKeJV|!| literal 0 HcmV?d00001