JSR-356 - making use of ServiceLoader technique for finding Extensions
This commit is contained in:
parent
d967dafe45
commit
d7d4e415ea
|
@ -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.Extension;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
|
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
|
public class WebSocketExtensionFactory extends ExtensionFactory
|
||||||
{
|
{
|
||||||
|
@ -40,13 +36,6 @@ public class WebSocketExtensionFactory extends ExtensionFactory
|
||||||
super();
|
super();
|
||||||
this.policy = policy;
|
this.policy = policy;
|
||||||
this.bufferPool = bufferPool;
|
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
|
@Override
|
||||||
|
|
|
@ -35,6 +35,12 @@ public class FrameCompressionExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private CompressionMethod method = new DeflateCompressionMethod();
|
private CompressionMethod method = new DeflateCompressionMethod();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "x-webkit-deflate-frame";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void incomingFrame(Frame frame)
|
public synchronized void incomingFrame(Frame frame)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,11 +18,8 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.websocket.common.extensions.compress;
|
package org.eclipse.jetty.websocket.common.extensions.compress;
|
||||||
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
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.WriteCallback;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
import org.eclipse.jetty.websocket.api.extensions.Frame;
|
||||||
|
@ -30,16 +27,20 @@ import org.eclipse.jetty.websocket.common.WebSocketFrame;
|
||||||
import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
|
import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Per Message Compression extension for WebSocket.
|
* Per Message Deflate Compression extension for WebSocket.
|
||||||
* <p>
|
* <p>
|
||||||
* Attempts to follow <a href="https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-01">draft-ietf-hybi-permessage-compression-01</a>
|
* Attempts to follow <a href="https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-01">draft-ietf-hybi-permessage-compression-01</a>
|
||||||
*/
|
*/
|
||||||
public class MessageCompressionExtension extends AbstractExtension
|
public class MessageDeflateCompressionExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(MessageCompressionExtension.class);
|
|
||||||
|
|
||||||
private CompressionMethod method;
|
private CompressionMethod method;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "permessage-deflate";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incomingFrame(Frame frame)
|
public void incomingFrame(Frame frame)
|
||||||
{
|
{
|
||||||
|
@ -133,10 +134,6 @@ public class MessageCompressionExtension extends AbstractExtension
|
||||||
public void setConfig(ExtensionConfig config)
|
public void setConfig(ExtensionConfig config)
|
||||||
{
|
{
|
||||||
super.setConfig(config);
|
super.setConfig(config);
|
||||||
|
|
||||||
String methodOptions = config.getParameter("method","deflate");
|
|
||||||
LOG.debug("Method requested: {}",methodOptions);
|
|
||||||
|
|
||||||
method = new DeflateCompressionMethod();
|
method = new DeflateCompressionMethod();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,12 @@ public class FragmentExtension extends AbstractExtension
|
||||||
{
|
{
|
||||||
private int maxLength = -1;
|
private int maxLength = -1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "fragment";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incomingError(Throwable e)
|
public void incomingError(Throwable e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,12 @@ public class IdentityExtension extends AbstractExtension
|
||||||
return getConfig().getParameter(key,"?");
|
return getConfig().getParameter(key,"?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return "identity";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incomingError(Throwable e)
|
public void incomingError(Throwable e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
|
@ -49,7 +49,7 @@ public class MessageCompressionExtensionTest
|
||||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||||
|
|
||||||
// Setup extension
|
// Setup extension
|
||||||
MessageCompressionExtension ext = new MessageCompressionExtension();
|
MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension();
|
||||||
ext.setBufferPool(new MappedByteBufferPool());
|
ext.setBufferPool(new MappedByteBufferPool());
|
||||||
ext.setPolicy(policy);
|
ext.setPolicy(policy);
|
||||||
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
||||||
|
@ -162,7 +162,7 @@ public class MessageCompressionExtensionTest
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIncomingPing() {
|
public void testIncomingPing() {
|
||||||
MessageCompressionExtension ext = new MessageCompressionExtension();
|
MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension();
|
||||||
ext.setBufferPool(new MappedByteBufferPool());
|
ext.setBufferPool(new MappedByteBufferPool());
|
||||||
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
||||||
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
||||||
|
@ -199,7 +199,7 @@ public class MessageCompressionExtensionTest
|
||||||
@Test
|
@Test
|
||||||
public void testIncomingUncompressedFrames()
|
public void testIncomingUncompressedFrames()
|
||||||
{
|
{
|
||||||
MessageCompressionExtension ext = new MessageCompressionExtension();
|
MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension();
|
||||||
ext.setBufferPool(new MappedByteBufferPool());
|
ext.setBufferPool(new MappedByteBufferPool());
|
||||||
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
||||||
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
||||||
|
@ -255,7 +255,7 @@ public class MessageCompressionExtensionTest
|
||||||
@Test
|
@Test
|
||||||
public void testOutgoingFrames() throws IOException
|
public void testOutgoingFrames() throws IOException
|
||||||
{
|
{
|
||||||
MessageCompressionExtension ext = new MessageCompressionExtension();
|
MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension();
|
||||||
ext.setBufferPool(new MappedByteBufferPool());
|
ext.setBufferPool(new MappedByteBufferPool());
|
||||||
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
||||||
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
||||||
|
@ -325,7 +325,7 @@ public class MessageCompressionExtensionTest
|
||||||
@Test
|
@Test
|
||||||
public void testOutgoingPing() throws IOException
|
public void testOutgoingPing() throws IOException
|
||||||
{
|
{
|
||||||
MessageCompressionExtension ext = new MessageCompressionExtension();
|
MessageDeflateCompressionExtension ext = new MessageDeflateCompressionExtension();
|
||||||
ext.setBufferPool(new MappedByteBufferPool());
|
ext.setBufferPool(new MappedByteBufferPool());
|
||||||
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
ext.setPolicy(WebSocketPolicy.newServerPolicy());
|
||||||
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
ExtensionConfig config = ExtensionConfig.parse("permessage-compress");
|
||||||
|
|
|
@ -24,7 +24,7 @@ import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension;
|
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.server.WebSocketHandler;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||||
|
@ -112,7 +112,7 @@ public class BrowserDebugTool implements WebSocketCreator
|
||||||
|
|
||||||
// Setup some extensions we want to test against
|
// Setup some extensions we want to test against
|
||||||
factory.getExtensionFactory().register("x-webkit-deflate-frame",FrameCompressionExtension.class);
|
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
|
// Setup the desired Socket to use for all incoming upgrade requests
|
||||||
factory.setCreator(BrowserDebugTool.this);
|
factory.setCreator(BrowserDebugTool.this);
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
package org.eclipse.jetty.websocket.server.helper;
|
package org.eclipse.jetty.websocket.server.helper;
|
||||||
|
|
||||||
import org.eclipse.jetty.websocket.common.extensions.compress.FrameCompressionExtension;
|
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.WebSocketServlet;
|
||||||
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ public class EchoServlet extends WebSocketServlet
|
||||||
{
|
{
|
||||||
// Setup some extensions we want to test against
|
// Setup some extensions we want to test against
|
||||||
factory.getExtensionFactory().register("x-webkit-deflate-frame",FrameCompressionExtension.class);
|
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
|
// Setup the desired Socket to use for all incoming upgrade requests
|
||||||
factory.register(EchoSocket.class);
|
factory.register(EchoSocket.class);
|
||||||
|
|
Loading…
Reference in New Issue