From f9b9cc131384a162a10b34ffcc4214333143cd39 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 22 Jan 2019 09:11:05 +1100 Subject: [PATCH] Issue #2175 cleanups after review Signed-off-by: Greg Wilkins --- .../websocket/javax/tests/LocalServer.java | 9 ++++++- .../quotes/QuotesDecoderTextStreamTest.java | 4 +++- .../javax/tests/server/MemoryUsageTest.java | 7 +++++- .../WebSocketServerContainerExecutorTest.java | 8 ++++++- .../core/internal/ExtensionStack.java | 5 +--- .../core/internal/WebSocketChannel.java | 8 +++---- .../core/internal/WebSocketChannelState.java | 24 +++++++++---------- .../core/extensions/ExtensionStackTest.java | 10 ++++---- .../websocket/servlet/WebSocketMapping.java | 7 +++++- 9 files changed, 52 insertions(+), 30 deletions(-) diff --git a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java index f07ee22c3bd..c1099963f54 100644 --- a/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java +++ b/jetty-websocket/javax-websocket-tests/src/main/java/org/eclipse/jetty/websocket/javax/tests/LocalServer.java @@ -32,7 +32,14 @@ import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; -import org.eclipse.jetty.server.*; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.LocalConnector; +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.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/quotes/QuotesDecoderTextStreamTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/quotes/QuotesDecoderTextStreamTest.java index a0a90cdfcad..8c2112de515 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/quotes/QuotesDecoderTextStreamTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/quotes/QuotesDecoderTextStreamTest.java @@ -38,7 +38,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.allOf; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; /** * Tests a {@link javax.websocket.Decoder.TextStream} automatic decoding to a Socket onMessage parameter diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java index e5d6ab10216..b47cb19030b 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/MemoryUsageTest.java @@ -25,7 +25,12 @@ import java.net.URI; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import javax.websocket.*; +import javax.websocket.ContainerProvider; +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.MessageHandler; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; import javax.websocket.server.ServerContainer; import javax.websocket.server.ServerEndpointConfig; diff --git a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java index 0f47ed9be2e..edaaa030aef 100644 --- a/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java +++ b/jetty-websocket/javax-websocket-tests/src/test/java/org/eclipse/jetty/websocket/javax/tests/server/WebSocketServerContainerExecutorTest.java @@ -31,7 +31,13 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.websocket.*; +import javax.websocket.ContainerProvider; +import javax.websocket.Endpoint; +import javax.websocket.EndpointConfig; +import javax.websocket.OnError; +import javax.websocket.OnMessage; +import javax.websocket.Session; +import javax.websocket.WebSocketContainer; import javax.websocket.server.ServerEndpoint; import org.eclipse.jetty.client.HttpClient; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java index 52ec3df0af1..fa903261f14 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java @@ -19,18 +19,15 @@ package org.eclipse.jetty.websocket.core.internal; import java.io.IOException; -import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.ListIterator; -import java.util.Queue; import java.util.stream.Collectors; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.DecoratedObjectFactory; -import org.eclipse.jetty.util.IteratingCallback; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.Dumpable; @@ -201,7 +198,7 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable outgoing.sendFrame(frame, callback, batch); } - public void connect(IncomingFrames incoming, OutgoingFrames outgoing, WebSocketChannel webSocketChannel) + public void initialize(IncomingFrames incoming, OutgoingFrames outgoing, WebSocketChannel webSocketChannel) { if (extensions == null) throw new IllegalStateException(); diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java index c93d8222f04..a42246f8182 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/core/internal/WebSocketChannel.java @@ -79,7 +79,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio this.behavior = behavior; this.negotiated = negotiated; this.demanding = handler.isDemanding(); - negotiated.getExtensions().connect(new IncomingAdaptor(), new OutgoingAdaptor(), this); + negotiated.getExtensions().initialize(new IncomingAdaptor(), new OutgoingAdaptor(), this); } /** @@ -153,7 +153,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio if (frame.getOpCode() == OpCode.CLOSE) { if (!(frame instanceof ParsedFrame)) // already check in parser - CloseStatus.getCloseStatus(frame); + CloseStatus.getCloseStatus(frame); // return ignored as get used to validate there is a closeStatus } } else @@ -237,7 +237,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio @Override public boolean isOpen() { - return channelState.isOutOpen(); + return channelState.isOutputOpen(); } public void setWebSocketConnection(WebSocketConnection connection) @@ -640,7 +640,7 @@ public class WebSocketChannel implements IncomingFrames, FrameHandler.CoreSessio @Override public void completed() { - if (channelState.isOutOpen()) + if (channelState.isOutputOpen()) { CloseStatus closeStatus = CloseStatus.getCloseStatus(frame); 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 b467dd2a89f..6d3938b8db6 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 @@ -33,8 +33,8 @@ public class WebSocketChannelState CONNECTING, CONNECTED, OPEN, - ICLOSED, - OCLOSED, + ISHUT, + OSHUT, CLOSED } @@ -85,16 +85,16 @@ public class WebSocketChannelState return getState()==State.CLOSED; } - public boolean isInOpen() + public boolean isInputOpen() { State state = getState(); - return (state==State.OPEN || state==State.OCLOSED); + return (state==State.OPEN || state==State.OSHUT); } - public boolean isOutOpen() + public boolean isOutputOpen() { State state = getState(); - return (state==State.OPEN || state==State.ICLOSED); + return (state==State.OPEN || state==State.ISHUT); } public CloseStatus getCloseStatus() @@ -125,7 +125,7 @@ public class WebSocketChannelState synchronized (this) { - if (!isOutOpen()) + if (!isOutputOpen()) throw new IllegalStateException(_channelState.toString()); if (opcode == OpCode.CLOSE) @@ -135,9 +135,9 @@ public class WebSocketChannelState switch (_channelState) { case OPEN: - _channelState = State.OCLOSED; + _channelState = State.OSHUT; return false; - case ICLOSED: + case ISHUT: _channelState = State.CLOSED; return true; default: @@ -160,7 +160,7 @@ public class WebSocketChannelState synchronized (this) { - if (!isInOpen()) + if (!isInputOpen()) throw new IllegalStateException(_channelState.toString()); if (opcode == OpCode.CLOSE) @@ -170,9 +170,9 @@ public class WebSocketChannelState switch (_channelState) { case OPEN: - _channelState = State.ICLOSED; + _channelState = State.ISHUT; return false; - case OCLOSED: + case OSHUT: _channelState = State.CLOSED; return true; default: diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java index a35121e05f2..d5276089157 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/core/extensions/ExtensionStackTest.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.websocket.core.extensions; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.DecoratedObjectFactory; @@ -35,9 +38,6 @@ import org.eclipse.jetty.websocket.core.internal.IdentityExtension; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import java.util.ArrayList; -import java.util.List; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -80,7 +80,7 @@ public class ExtensionStackTest // Setup Listeners IncomingFrames session = new IncomingFramesCapture(); OutgoingFrames connection = new OutgoingFramesCapture(); - stack.connect(session, connection, null); + stack.initialize(session, connection, null); // Dump LOG.debug("{}", stack.dump()); @@ -104,7 +104,7 @@ public class ExtensionStackTest // Setup Listeners IncomingFrames session = new IncomingFramesCapture(); OutgoingFrames connection = new OutgoingFramesCapture(); - stack.connect(session, connection, null); + stack.initialize(session, connection, null); // Dump LOG.debug("{}", stack.dump()); diff --git a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java index 8a484622c98..b16505505cb 100644 --- a/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java +++ b/jetty-websocket/websocket-servlet/src/main/java/org/eclipse/jetty/websocket/servlet/WebSocketMapping.java @@ -27,7 +27,12 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.eclipse.jetty.http.pathmap.*; +import org.eclipse.jetty.http.pathmap.MappedResource; +import org.eclipse.jetty.http.pathmap.PathMappings; +import org.eclipse.jetty.http.pathmap.PathSpec; +import org.eclipse.jetty.http.pathmap.RegexPathSpec; +import org.eclipse.jetty.http.pathmap.ServletPathSpec; +import org.eclipse.jetty.http.pathmap.UriTemplatePathSpec; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.RuntimeIOException;