From d7d4e415eadb900596308063fcd60d3cc3fe0009 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 24 Jul 2013 14:46:59 -0700 Subject: [PATCH] JSR-356 - making use of ServiceLoader technique for finding Extensions --- .../extensions/WebSocketExtensionFactory.java | 11 ----------- .../compress/FrameCompressionExtension.java | 6 ++++++ ...> MessageDeflateCompressionExtension.java} | 19 ++++++++----------- .../fragment/FragmentExtension.java | 6 ++++++ .../identity/IdentityExtension.java | 6 ++++++ ...e.jetty.websocket.api.extensions.Extension | 4 ++++ .../MessageCompressionExtensionTest.java | 10 +++++----- .../server/browser/BrowserDebugTool.java | 4 ++-- .../websocket/server/helper/EchoServlet.java | 4 ++-- 9 files changed, 39 insertions(+), 31 deletions(-) rename jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/{MessageCompressionExtension.java => MessageDeflateCompressionExtension.java} (90%) create mode 100644 jetty-websocket/websocket-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.api.extensions.Extension diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/WebSocketExtensionFactory.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/WebSocketExtensionFactory.java index 6ed92244486..f56fd1bb51b 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/WebSocketExtensionFactory.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/WebSocketExtensionFactory.java @@ -25,10 +25,6 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy; import org.eclipse.jetty.websocket.api.extensions.Extension; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory; -import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension; -import org.eclipse.jetty.websocket.common.extensions.compress.MessageCompressionExtension; -import org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension; -import org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension; public class WebSocketExtensionFactory extends ExtensionFactory { @@ -40,13 +36,6 @@ public class WebSocketExtensionFactory extends ExtensionFactory super(); this.policy = policy; this.bufferPool = bufferPool; - - register("identity",IdentityExtension.class); - register("fragment",FragmentExtension.class); - /* FIXME: Disabled due to bug report - http://bugs.eclipse.org/395444 - * register("x-webkit-deflate-frame",FrameCompressionExtension.class); - * register("permessage-compress",MessageCompressionExtension.class); - */ } @Override diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtension.java index a548f20782a..bf19f35f2ba 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/FrameCompressionExtension.java @@ -34,6 +34,12 @@ import org.eclipse.jetty.websocket.common.extensions.AbstractExtension; public class FrameCompressionExtension extends AbstractExtension { private CompressionMethod method = new DeflateCompressionMethod(); + + @Override + public String getName() + { + return "x-webkit-deflate-frame"; + } @Override public synchronized void incomingFrame(Frame frame) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageDeflateCompressionExtension.java similarity index 90% rename from jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtension.java rename to jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageDeflateCompressionExtension.java index 75d7817e820..51200c2e858 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageDeflateCompressionExtension.java @@ -18,11 +18,8 @@ package org.eclipse.jetty.websocket.common.extensions.compress; - import java.nio.ByteBuffer; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.api.WriteCallback; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.api.extensions.Frame; @@ -30,15 +27,19 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame; import org.eclipse.jetty.websocket.common.extensions.AbstractExtension; /** - * Per Message Compression extension for WebSocket. + * Per Message Deflate Compression extension for WebSocket. *

* Attempts to follow draft-ietf-hybi-permessage-compression-01 */ -public class MessageCompressionExtension extends AbstractExtension +public class MessageDeflateCompressionExtension extends AbstractExtension { - private static final Logger LOG = Log.getLogger(MessageCompressionExtension.class); - private CompressionMethod method; + + @Override + public String getName() + { + return "permessage-deflate"; + } @Override public void incomingFrame(Frame frame) @@ -133,10 +134,6 @@ public class MessageCompressionExtension extends AbstractExtension public void setConfig(ExtensionConfig config) { super.setConfig(config); - - String methodOptions = config.getParameter("method","deflate"); - LOG.debug("Method requested: {}",methodOptions); - method = new DeflateCompressionMethod(); } diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java index 428d6eb0738..f728c65013e 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/fragment/FragmentExtension.java @@ -34,6 +34,12 @@ import org.eclipse.jetty.websocket.common.extensions.AbstractExtension; public class FragmentExtension extends AbstractExtension { private int maxLength = -1; + + @Override + public String getName() + { + return "fragment"; + } @Override public void incomingError(Throwable e) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/identity/IdentityExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/identity/IdentityExtension.java index 742488e8830..e57f1661621 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/identity/IdentityExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/identity/IdentityExtension.java @@ -34,6 +34,12 @@ public class IdentityExtension extends AbstractExtension { return getConfig().getParameter(key,"?"); } + + @Override + public String getName() + { + return "identity"; + } @Override public void incomingError(Throwable e) diff --git a/jetty-websocket/websocket-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.api.extensions.Extension b/jetty-websocket/websocket-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.api.extensions.Extension new file mode 100644 index 00000000000..5442966f294 --- /dev/null +++ b/jetty-websocket/websocket-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.api.extensions.Extension @@ -0,0 +1,4 @@ +org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension +org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension +org.eclipse.jetty.websocket.common.extensions.compress.MessageDeflateCompressionExtension +org.eclipse.jetty.websocket.common.extensions.fragment.FragmentExtension \ No newline at end of file diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java index 3f8c96d3a6f..6f0a9e80ec1 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/MessageCompressionExtensionTest.java @@ -49,7 +49,7 @@ public class MessageCompressionExtensionTest WebSocketPolicy policy = WebSocketPolicy.newServerPolicy(); // Setup extension - MessageCompressionExtension ext = new MessageCompressionExtension(); + MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension(); ext.setBufferPool(new MappedByteBufferPool()); ext.setPolicy(policy); ExtensionConfig config = ExtensionConfig.parse("permessage-compress"); @@ -162,7 +162,7 @@ public class MessageCompressionExtensionTest */ @Test public void testIncomingPing() { - MessageCompressionExtension ext = new MessageCompressionExtension(); + MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension(); ext.setBufferPool(new MappedByteBufferPool()); ext.setPolicy(WebSocketPolicy.newServerPolicy()); ExtensionConfig config = ExtensionConfig.parse("permessage-compress"); @@ -199,7 +199,7 @@ public class MessageCompressionExtensionTest @Test public void testIncomingUncompressedFrames() { - MessageCompressionExtension ext = new MessageCompressionExtension(); + MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension(); ext.setBufferPool(new MappedByteBufferPool()); ext.setPolicy(WebSocketPolicy.newServerPolicy()); ExtensionConfig config = ExtensionConfig.parse("permessage-compress"); @@ -255,7 +255,7 @@ public class MessageCompressionExtensionTest @Test public void testOutgoingFrames() throws IOException { - MessageCompressionExtension ext = new MessageCompressionExtension(); + MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension(); ext.setBufferPool(new MappedByteBufferPool()); ext.setPolicy(WebSocketPolicy.newServerPolicy()); ExtensionConfig config = ExtensionConfig.parse("permessage-compress"); @@ -325,7 +325,7 @@ public class MessageCompressionExtensionTest @Test public void testOutgoingPing() throws IOException { - MessageCompressionExtension ext = new MessageCompressionExtension(); + MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension(); ext.setBufferPool(new MappedByteBufferPool()); ext.setPolicy(WebSocketPolicy.newServerPolicy()); ExtensionConfig config = ExtensionConfig.parse("permessage-compress"); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java index 18c05a14287..579ad4231c3 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/browser/BrowserDebugTool.java @@ -24,7 +24,7 @@ import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension; -import org.eclipse.jetty.websocket.common.extensions.compress.MessageCompressionExtension; +import org.eclipse.jetty.websocket.common.extensions.compress.MessageDeflateCompressionExtension; import org.eclipse.jetty.websocket.server.WebSocketHandler; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse; @@ -112,7 +112,7 @@ public class BrowserDebugTool implements WebSocketCreator // Setup some extensions we want to test against factory.getExtensionFactory().register("x-webkit-deflate-frame",FrameCompressionExtension.class); - factory.getExtensionFactory().register("permessage-compress",MessageCompressionExtension.class); + factory.getExtensionFactory().register("permessage-compress",MessageDeflateCompressionExtension.class); // Setup the desired Socket to use for all incoming upgrade requests factory.setCreator(BrowserDebugTool.this); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoServlet.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoServlet.java index 7cbbd2e0e77..877d57b6aa6 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoServlet.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoServlet.java @@ -19,7 +19,7 @@ package org.eclipse.jetty.websocket.server.helper; import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension; -import org.eclipse.jetty.websocket.common.extensions.compress.MessageCompressionExtension; +import org.eclipse.jetty.websocket.common.extensions.compress.MessageDeflateCompressionExtension; import org.eclipse.jetty.websocket.servlet.WebSocketServlet; import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; @@ -34,7 +34,7 @@ public class EchoServlet extends WebSocketServlet { // Setup some extensions we want to test against factory.getExtensionFactory().register("x-webkit-deflate-frame",FrameCompressionExtension.class); - factory.getExtensionFactory().register("permessage-compress",MessageCompressionExtension.class); + factory.getExtensionFactory().register("permessage-compress",MessageDeflateCompressionExtension.class); // Setup the desired Socket to use for all incoming upgrade requests factory.register(EchoSocket.class);