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.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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
* <p>
|
||||
* 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;
|
||||
|
||||
@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();
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
// 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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue