diff --git a/jetty-websocket/jetty-websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/jetty-websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index 4c4a96c5c2f..999d98bd1b6 100644 --- a/jetty-websocket/jetty-websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/jetty-websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -118,18 +118,19 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli * @param websocket the websocket object * @param toUri the websocket uri to connect to * @param request the upgrade request information - * @param listener the upgrade listener + * @param upgradeListener the upgrade listener * @return the future for the session, available on success of connect * @throws IOException if unable to connect */ - public CompletableFuture connect(Object websocket, URI toUri, UpgradeRequest request, UpgradeListener listener) throws IOException + public CompletableFuture connect(Object websocket, URI toUri, UpgradeRequest request, UpgradeListener upgradeListener) throws IOException { for (Connection.Listener listener : getBeans(Connection.Listener.class)) coreClient.addBean(listener); JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket); - if (listener != null) - upgradeRequest.addListener(listener); + if (upgradeListener != null) + upgradeRequest.addListener(upgradeListener); + coreClient.connect(upgradeRequest); return upgradeRequest.getFutureSession(); } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java index a48c791cf2d..73b06129d0f 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientCloseTest.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.server.Server; @@ -39,12 +38,12 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.websocket.api.CloseException; import org.eclipse.jetty.websocket.api.MessageTooLargeException; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; import org.eclipse.jetty.websocket.api.WebSocketFrameListener; import org.eclipse.jetty.websocket.api.WebSocketListener; +import org.eclipse.jetty.websocket.api.WebSocketTimeoutException; import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.core.CloseStatus; @@ -250,8 +249,8 @@ public class ClientCloseTest // client reads -1 (EOF) // client triggers close event on client ws-endpoint clientSocket.assertReceivedCloseEvent(clientTimeout * 2, - is(StatusCode.SHUTDOWN), - containsString("timeout")); + is(StatusCode.ABNORMAL), + containsString("Channel Closed")); } clientSessionTracker.assertClosedProperly(client); @@ -283,12 +282,11 @@ public class ClientCloseTest // client close should occur clientSocket.assertReceivedCloseEvent(clientTimeout * 2, is(StatusCode.SHUTDOWN), - containsString("timeout")); + containsString("Timeout")); // client idle timeout triggers close event on client ws-endpoint assertThat("OnError Latch", clientSocket.errorLatch.await(2, SECONDS), is(true)); - assertThat("OnError", clientSocket.error.get(), instanceOf(CloseException.class)); - assertThat("OnError.cause", clientSocket.error.get().getCause(), instanceOf(TimeoutException.class)); + assertThat("OnError", clientSocket.error.get(), instanceOf(WebSocketTimeoutException.class)); } clientSessionTracker.assertClosedProperly(client); @@ -328,7 +326,7 @@ public class ClientCloseTest // clients disconnect for (int i = 0; i < sessionCount; i++) { - clientSockets.get(i).assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("Disconnected")); + clientSockets.get(i).assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("Channel Closed")); } // ensure all Sessions are gone. connections are gone. etc. (client and server) @@ -368,7 +366,7 @@ public class ClientCloseTest // client triggers close event on client ws-endpoint // assert - close code==1006 (abnormal) - clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("Eof")); + clientSocket.assertReceivedCloseEvent(timeout, is(StatusCode.ABNORMAL), containsString("Channel Closed")); clientSessionTracker.assertClosedProperly(client); } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java index 1d5af427003..1b74d38df11 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/client/ClientSessionsTest.java @@ -145,6 +145,8 @@ public class ClientSessionsTest String received = cliSock.messageQueue.poll(5, TimeUnit.SECONDS); assertThat("Message", received, containsString("Hello World!")); + + sess.close(StatusCode.NORMAL, null); } cliSock.assertReceivedCloseEvent(30000, is(StatusCode.NORMAL)); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java index 0b1c6b32482..722c67c6a08 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ServerCloseTest.java @@ -36,6 +36,7 @@ import org.eclipse.jetty.websocket.api.util.WSURI; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.common.WebSocketSessionImpl; +import org.eclipse.jetty.websocket.core.internal.WebSocketChannel; import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; @@ -148,7 +149,7 @@ public class ServerCloseTest // Verify that server socket got close event AbstractCloseEndpoint serverEndpoint = serverEndpointCreator.pollLastCreated(); assertThat("Fast Close Latch", serverEndpoint.closeLatch.await(5, SECONDS), is(true)); - assertThat("Fast Close.statusCode", serverEndpoint.closeStatusCode, is(StatusCode.ABNORMAL)); + assertThat("Fast Close.statusCode", serverEndpoint.closeStatusCode, is(StatusCode.NORMAL)); } finally { @@ -172,7 +173,7 @@ public class ServerCloseTest Future futSession = client.connect(clientEndpoint, wsUri, request); Session session = null; - try(StacklessLogging ignore = new StacklessLogging(FastFailEndpoint.class, WebSocketSessionImpl.class)) + try(StacklessLogging ignore = new StacklessLogging(WebSocketChannel.class)) { session = futSession.get(5, SECONDS); @@ -219,12 +220,13 @@ public class ServerCloseTest clientEndpoint.getEndPoint().close(); // Verify that client got close - clientEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.ABNORMAL), containsString("Disconnected")); + clientEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.ABNORMAL), containsString("Channel Closed")); // Verify that server socket got close event AbstractCloseEndpoint serverEndpoint = serverEndpointCreator.pollLastCreated(); - serverEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.ABNORMAL), containsString("Disconnected")); - } finally + serverEndpoint.assertReceivedCloseEvent(5000, is(StatusCode.ABNORMAL), containsString("Channel Closed")); + } + finally { close(session); } diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java index 821f5c289fc..76f7bea4400 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannelState.java @@ -134,7 +134,7 @@ public class WebSocketChannelState default: if (_closeStatus == null || CloseStatus.isOrdinary(_closeStatus)) - _closeStatus = CloseStatus.NO_CLOSE_STATUS; + _closeStatus = new CloseStatus(CloseStatus.NO_CLOSE, "Channel Closed"); _channelState = State.CLOSED; return true; }