From 3b0f577aed8b41a97b756047875b6f7f0f319e74 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 7 Mar 2016 16:40:34 +0100 Subject: [PATCH 1/2] Removed DEBUG logging during tests. --- .../src/test/resources/jetty-logging.properties | 3 --- 1 file changed, 3 deletions(-) diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/resources/jetty-logging.properties b/jetty-websocket/javax-websocket-server-impl/src/test/resources/jetty-logging.properties index 9681d9168b4..c5a50f62391 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/resources/jetty-logging.properties +++ b/jetty-websocket/javax-websocket-server-impl/src/test/resources/jetty-logging.properties @@ -6,9 +6,6 @@ org.eclipse.jetty.LEVEL=WARN # org.eclipse.jetty.websocket.LEVEL=WARN # org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG -org.eclipse.jetty.websocket.common.WebSocketSession.LEVEL=DEBUG -org.eclipse.jetty.websocket.jsr356.LEVEL=DEBUG - ### Show state changes on BrowserDebugTool # -- LEAVE THIS AT DEBUG LEVEL -- org.eclipse.jetty.websocket.jsr356.server.browser.LEVEL=DEBUG From 8af356bc0d4b8fec572311e4cd319270a3ed68da Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 7 Mar 2016 17:00:52 +0100 Subject: [PATCH 2/2] Issue #305 (NPE when notifying the session listener if the channel is closed before a session has been opened) Added guard against NPE. It was needed since the connection may not be present if the connect operation failed. --- .../http/HttpClientTransportOverHTTP2.java | 4 ++- .../jetty/http/client/AbstractTest.java | 2 +- .../jetty/http/client/HttpClientTest.java | 31 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2.java index a68eabf3795..844be1a5e37 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpClientTransportOverHTTP2.java @@ -199,7 +199,9 @@ public class HttpClientTransportOverHTTP2 extends ContainerLifeCycle implements @Override public void onFailure(Session session, Throwable failure) { - connection.close(failure); + HttpConnectionOverHTTP2 c = connection; + if (c != null) + c.close(failure); } } } diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AbstractTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AbstractTest.java index a47a8618d0c..974762bdcd2 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AbstractTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AbstractTest.java @@ -154,7 +154,7 @@ public abstract class AbstractTest return result.toArray(new ConnectionFactory[result.size()]); } - private HttpClientTransport provideClientTransport(Transport transport) + protected HttpClientTransport provideClientTransport(Transport transport) { switch (transport) { diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java index 415bbe3700d..b0f3d177351 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/HttpClientTest.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.http.client; import java.io.IOException; import java.io.InterruptedIOException; +import java.util.EnumSet; import java.util.Random; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -39,7 +40,10 @@ import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.http2.FlowControlStrategy; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.junit.Assert; +import org.junit.Assume; import org.junit.Test; public class HttpClientTest extends AbstractTest @@ -285,6 +289,33 @@ public class HttpClientTest extends AbstractTest Assert.assertEquals(response.getStatus(), 200); } + @Test(expected = ExecutionException.class) + public void testClientCannotValidateServerCertificate() throws Exception + { + // Only run this test for transports over TLS. + Assume.assumeTrue(EnumSet.of(Transport.HTTPS, Transport.H2).contains(transport)); + + startServer(new AbstractHandler() + { + @Override + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + { + baseRequest.setHandled(true); + } + }); + + // Use a default SslContextFactory, requests should fail because the server certificate is unknown. + client = newHttpClient(provideClientTransport(transport), new SslContextFactory()); + QueuedThreadPool clientThreads = new QueuedThreadPool(); + clientThreads.setName("client"); + client.setExecutor(clientThreads); + client.start(); + + client.newRequest(newURI()) + .timeout(5, TimeUnit.SECONDS) + .send(); + } + private void sleep(long time) throws IOException { try