Integrating new policy changes
This commit is contained in:
parent
2e6c307adc
commit
085127c8f8
|
@ -24,7 +24,36 @@ public class WebSocketPolicy
|
|||
/**
|
||||
* Behavior of the websockets
|
||||
*/
|
||||
private WebSocketBehavior behavior = WebSocketBehavior.SERVER; // TODO: Review default
|
||||
private final WebSocketBehavior behavior;
|
||||
|
||||
public WebSocketPolicy(WebSocketBehavior behavior)
|
||||
{
|
||||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
public void assertValidBinaryMessageSize(int requestedSize)
|
||||
{
|
||||
if (maxBinaryMessageSize > 0)
|
||||
{
|
||||
// validate it
|
||||
if (requestedSize > maxBinaryMessageSize)
|
||||
{
|
||||
throw new PolicyViolationException("Requested binary message size [" + requestedSize + "] exceeds maximum size [" + maxBinaryMessageSize + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void assertValidTextMessageSize(int requestedSize)
|
||||
{
|
||||
if (maxTextMessageSize > 0)
|
||||
{
|
||||
// validate it
|
||||
if (requestedSize > maxTextMessageSize)
|
||||
{
|
||||
throw new PolicyViolationException("Requested text message size [" + requestedSize + "] exceeds maximum size [" + maxTextMessageSize + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public WebSocketBehavior getBehavior()
|
||||
{
|
||||
|
@ -46,11 +75,6 @@ public class WebSocketPolicy
|
|||
return maxTextMessageSize;
|
||||
}
|
||||
|
||||
public void setBehavior(WebSocketBehavior behavior)
|
||||
{
|
||||
this.behavior = behavior;
|
||||
}
|
||||
|
||||
public void setMasker(Masker masker)
|
||||
{
|
||||
this.masker = masker;
|
||||
|
@ -65,5 +89,4 @@ public class WebSocketPolicy
|
|||
{
|
||||
this.maxTextMessageSize = maxTextMessageSize;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,25 +3,26 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
|
||||
public class CloseFrameGenerator extends FrameGenerator<CloseFrame>
|
||||
{
|
||||
public CloseFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
public CloseFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy policy)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
super(bufferPool, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer payload(CloseFrame close)
|
||||
{
|
||||
ByteBuffer b = ByteBuffer.allocate(close.getReason().length() + 2);
|
||||
|
||||
|
||||
b.putShort(close.getStatusCode());
|
||||
b.put(close.getReason().getBytes()); // TODO force UTF-8 and work out ex handling
|
||||
|
||||
byte utf[] = close.getReason().getBytes(StringUtil.__UTF8_CHARSET);
|
||||
b.put(utf,0,utf.length);
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,19 @@ package org.eclipse.jetty.websocket.generator;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.PolicyViolationException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
|
||||
public abstract class FrameGenerator<T extends BaseFrame>
|
||||
{
|
||||
private final ByteBufferPool bufferPool;
|
||||
private final WebSocketPolicy settings;
|
||||
private final WebSocketPolicy policy;
|
||||
|
||||
protected FrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
protected FrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy policy)
|
||||
{
|
||||
this.bufferPool = bufferPool;
|
||||
this.settings = settings;
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public ByteBuffer generate(T frame)
|
||||
|
@ -25,10 +26,28 @@ public abstract class FrameGenerator<T extends BaseFrame>
|
|||
|
||||
// Setup fin thru opcode
|
||||
b = 0x00;
|
||||
b |= (frame.isFin()?0x80:0x00); // 1000_0000
|
||||
b |= (frame.isRsv1()?0x40:0x00); // 0100_0000
|
||||
b |= (frame.isRsv2()?0x20:0x00); // 0010_0000 TODO: validate?
|
||||
b |= (frame.isRsv3()?0x10:0x00); // 0001_0000 TODO: validate?
|
||||
if (frame.isFin())
|
||||
{
|
||||
b |= 0x80; // 1000_0000
|
||||
}
|
||||
if (frame.isRsv1())
|
||||
{
|
||||
b |= 0x40; // 0100_0000
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV1 not allowed to be set");
|
||||
}
|
||||
if (frame.isRsv2())
|
||||
{
|
||||
b |= 0x20; // 0010_0000
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV2 not allowed to be set");
|
||||
}
|
||||
if (frame.isRsv3())
|
||||
{
|
||||
b |= 0x10;
|
||||
// TODO: extensions can negotiate this (somehow)
|
||||
throw new PolicyViolationException("RSV3 not allowed to be set");
|
||||
}
|
||||
b |= (frame.getOpCode().getCode() & 0x0F);
|
||||
framing.put(b);
|
||||
|
||||
|
@ -77,13 +96,13 @@ public abstract class FrameGenerator<T extends BaseFrame>
|
|||
|
||||
// TODO see if we can avoid the extra buffer here, make convention of payload
|
||||
// call back into masking check/method on this class?
|
||||
|
||||
// generate payload
|
||||
|
||||
// generate payload
|
||||
ByteBuffer payloadBuffer = payload(frame);
|
||||
|
||||
|
||||
// insert framing
|
||||
buffer.put(framing);
|
||||
|
||||
|
||||
// mask it if needed
|
||||
if ( frame.isMasked() )
|
||||
{
|
||||
|
@ -99,14 +118,19 @@ public abstract class FrameGenerator<T extends BaseFrame>
|
|||
{
|
||||
buffer.put(payloadBuffer);
|
||||
}
|
||||
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public abstract ByteBuffer payload(T frame);
|
||||
|
||||
protected ByteBufferPool getByteBufferPool()
|
||||
{
|
||||
return bufferPool;
|
||||
}
|
||||
|
||||
public WebSocketPolicy getPolicy()
|
||||
{
|
||||
return policy;
|
||||
}
|
||||
|
||||
public abstract ByteBuffer payload(T frame);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.eclipse.jetty.io.ByteBufferPool;
|
|||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
import org.eclipse.jetty.websocket.masks.Masker;
|
||||
|
||||
/**
|
||||
* Generating a frame in WebSocket land.
|
||||
|
@ -36,18 +35,16 @@ import org.eclipse.jetty.websocket.masks.Masker;
|
|||
public class Generator {
|
||||
|
||||
private final EnumMap<OpCode, FrameGenerator<?>> generators = new EnumMap<>(OpCode.class);
|
||||
private Masker maskgen = null;
|
||||
|
||||
public Generator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
public Generator(ByteBufferPool bufferPool, WebSocketPolicy policy)
|
||||
{
|
||||
generators.put(OpCode.PING,new PingFrameGenerator(bufferPool, settings));
|
||||
generators.put(OpCode.PONG,new PongFrameGenerator(bufferPool, settings));
|
||||
generators.put(OpCode.CLOSE,new CloseFrameGenerator(bufferPool, settings));
|
||||
generators.put(OpCode.PING,new PingFrameGenerator(bufferPool,policy));
|
||||
generators.put(OpCode.PONG,new PongFrameGenerator(bufferPool,policy));
|
||||
generators.put(OpCode.CLOSE,new CloseFrameGenerator(bufferPool,policy));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings(
|
||||
{ "unchecked", "rawtypes" })
|
||||
{ "unchecked", "rawtypes" })
|
||||
public ByteBuffer generate(BaseFrame frame)
|
||||
{
|
||||
FrameGenerator generator = generators.get(frame.getOpCode());
|
||||
|
|
|
@ -8,9 +8,9 @@ import org.eclipse.jetty.websocket.frames.PingFrame;
|
|||
|
||||
public class PingFrameGenerator extends FrameGenerator<PingFrame>
|
||||
{
|
||||
public PingFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
public PingFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy policy)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
super(bufferPool, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,14 +4,13 @@ import java.nio.ByteBuffer;
|
|||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
|
||||
public class PongFrameGenerator extends FrameGenerator<PongFrame>
|
||||
{
|
||||
public PongFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy settings)
|
||||
public PongFrameGenerator(ByteBufferPool bufferPool, WebSocketPolicy policy)
|
||||
{
|
||||
super(bufferPool, settings);
|
||||
super(bufferPool, policy);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,9 +14,9 @@ public class BinaryPayloadParser extends FrameParser<BinaryFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public BinaryPayloadParser(WebSocketPolicy settings)
|
||||
public BinaryPayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new BinaryFrame();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class BinaryPayloadParser extends FrameParser<BinaryFrame>
|
|||
{
|
||||
if (payload == null)
|
||||
{
|
||||
// TODO: buffer size limits
|
||||
getPolicy().assertValidBinaryMessageSize(payloadLength);
|
||||
payload = ByteBuffer.allocate(payloadLength);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ public class ClosePayloadParser extends FrameParser<CloseFrame>
|
|||
{
|
||||
private CloseFrame frame;
|
||||
|
||||
public ClosePayloadParser(WebSocketPolicy settings)
|
||||
public ClosePayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new CloseFrame();
|
||||
}
|
||||
|
||||
|
|
|
@ -44,14 +44,14 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
}
|
||||
|
||||
private static final Logger LOG = Log.getLogger(FrameParser.class);
|
||||
private WebSocketPolicy settings;
|
||||
private WebSocketPolicy policy;
|
||||
private State state = State.PAYLOAD_LEN;
|
||||
private int length = 0;
|
||||
private int cursor = 0;
|
||||
|
||||
public FrameParser(WebSocketPolicy settings)
|
||||
public FrameParser(WebSocketPolicy policy)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,9 +94,9 @@ public abstract class FrameParser<T extends BaseFrame>
|
|||
*/
|
||||
public abstract T getFrame();
|
||||
|
||||
protected WebSocketPolicy getSettings()
|
||||
protected WebSocketPolicy getPolicy()
|
||||
{
|
||||
return settings;
|
||||
return policy;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,30 +36,25 @@ public class Parser
|
|||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
private final EnumMap<OpCode, FrameParser<?>> parsers = new EnumMap<>(OpCode.class);
|
||||
private FrameParser<?> parser;
|
||||
private WebSocketPolicy settings;
|
||||
private WebSocketPolicy policy;
|
||||
private State state = State.FINOP;
|
||||
private int currentContinuationIndex = 0;
|
||||
|
||||
public Parser()
|
||||
{
|
||||
this(new WebSocketPolicy());
|
||||
}
|
||||
|
||||
public Parser(WebSocketPolicy settings)
|
||||
public Parser(WebSocketPolicy wspolicy)
|
||||
{
|
||||
/*
|
||||
* TODO: Investigate addition of decompression factory similar to SPDY work in situation of negotiated deflate extension?
|
||||
*/
|
||||
|
||||
this.settings = settings;
|
||||
this.policy = wspolicy;
|
||||
|
||||
reset();
|
||||
|
||||
parsers.put(OpCode.TEXT,new TextPayloadParser(settings));
|
||||
parsers.put(OpCode.BINARY,new BinaryPayloadParser(settings));
|
||||
parsers.put(OpCode.CLOSE,new ClosePayloadParser(settings));
|
||||
parsers.put(OpCode.PING,new PingPayloadParser(settings));
|
||||
parsers.put(OpCode.PONG,new PongPayloadParser(settings));
|
||||
parsers.put(OpCode.TEXT,new TextPayloadParser(policy));
|
||||
parsers.put(OpCode.BINARY,new BinaryPayloadParser(policy));
|
||||
parsers.put(OpCode.CLOSE,new ClosePayloadParser(policy));
|
||||
parsers.put(OpCode.PING,new PingPayloadParser(policy));
|
||||
parsers.put(OpCode.PONG,new PongPayloadParser(policy));
|
||||
}
|
||||
|
||||
public void addListener(Listener listener)
|
||||
|
@ -67,9 +62,9 @@ public class Parser
|
|||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public WebSocketPolicy getSettings()
|
||||
public WebSocketPolicy getPolicy()
|
||||
{
|
||||
return settings;
|
||||
return policy;
|
||||
}
|
||||
|
||||
protected void notifyFrame(final BaseFrame f)
|
||||
|
|
|
@ -14,9 +14,9 @@ public class PingPayloadParser extends FrameParser<PingFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public PingPayloadParser(WebSocketPolicy settings)
|
||||
public PingPayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new PingFrame();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ public class PongPayloadParser extends FrameParser<PongFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public PongPayloadParser(WebSocketPolicy settings)
|
||||
public PongPayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new PongFrame();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ public class TextPayloadParser extends FrameParser<TextFrame>
|
|||
private ByteBuffer payload;
|
||||
private int payloadLength;
|
||||
|
||||
public TextPayloadParser(WebSocketPolicy settings)
|
||||
public TextPayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new TextFrame();
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ public class TextPayloadParser extends FrameParser<TextFrame>
|
|||
{
|
||||
if (payload == null)
|
||||
{
|
||||
getPolicy().assertValidTextMessageSize(payloadLength);
|
||||
payload = ByteBuffer.allocate(payloadLength);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ public class UnknownPayloadParser extends FrameParser<BaseFrame>
|
|||
{
|
||||
private BaseFrame frame;
|
||||
|
||||
public UnknownPayloadParser(WebSocketPolicy settings)
|
||||
public UnknownPayloadParser(WebSocketPolicy policy)
|
||||
{
|
||||
super(settings);
|
||||
super(policy);
|
||||
frame = new BaseFrame();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,46 +6,17 @@ import java.nio.ByteBuffer;
|
|||
import org.eclipse.jetty.io.StandardByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
import org.eclipse.jetty.websocket.masks.FixedMasker;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RFC6455ExamplesGeneratorTest
|
||||
{
|
||||
StandardByteBufferPool bufferPool = new StandardByteBufferPool();
|
||||
|
||||
@Test
|
||||
public void testSingleUnmaskedPingRequest() throws Exception
|
||||
{
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(7);
|
||||
buf.put(new byte[] {
|
||||
(byte)0x89, (byte)0x05, (byte)0x48, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x6f
|
||||
});
|
||||
|
||||
//buffer.flip();
|
||||
|
||||
PingFrame ping = new PingFrame();
|
||||
ByteBuffer payload = ByteBuffer.allocate(5);
|
||||
|
||||
payload.put("Hello".getBytes(), 0, 5);
|
||||
ping.setPayload(payload);
|
||||
|
||||
PingFrameGenerator generator = new PingFrameGenerator(bufferPool, new WebSocketPolicy());
|
||||
|
||||
ByteBuffer generatedPing = generator.generate(ping);
|
||||
|
||||
Debug.dumpState(buf);
|
||||
Debug.dumpState(generatedPing);
|
||||
|
||||
ByteBufferAssert.assertEquals("ping buffers are not equal",buf,generatedPing);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSingleMaskedPongRequest()
|
||||
{
|
||||
|
@ -61,19 +32,49 @@ public class RFC6455ExamplesGeneratorTest
|
|||
payload.put("Hello".getBytes(), 0, 5);
|
||||
pong.setPayload(payload);
|
||||
|
||||
WebSocketPolicy settings = new WebSocketPolicy();
|
||||
settings.setMasker(new FixedMasker());
|
||||
|
||||
PongFrameGenerator generator = new PongFrameGenerator(bufferPool, settings);
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
policy.setMasker(new FixedMasker());
|
||||
|
||||
PongFrameGenerator generator = new PongFrameGenerator(bufferPool,policy);
|
||||
|
||||
ByteBuffer generatedPong = generator.generate(pong);
|
||||
Debug.dumpState(buf);
|
||||
Debug.dumpState(generatedPong);
|
||||
|
||||
|
||||
ByteBufferAssert.assertEquals("pong buffers are not equal", buf, generatedPong);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testSingleUnmaskedPingRequest() throws Exception
|
||||
{
|
||||
|
||||
ByteBuffer buf = ByteBuffer.allocate(7);
|
||||
buf.put(new byte[] {
|
||||
(byte)0x89, (byte)0x05, (byte)0x48, (byte)0x65, (byte)0x6c, (byte)0x6c, (byte)0x6f
|
||||
});
|
||||
|
||||
//buffer.flip();
|
||||
|
||||
PingFrame ping = new PingFrame();
|
||||
ByteBuffer payload = ByteBuffer.allocate(5);
|
||||
|
||||
payload.put("Hello".getBytes(), 0, 5);
|
||||
ping.setPayload(payload);
|
||||
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
PingFrameGenerator generator = new PingFrameGenerator(bufferPool, policy);
|
||||
|
||||
ByteBuffer generatedPing = generator.generate(ping);
|
||||
|
||||
Debug.dumpState(buf);
|
||||
Debug.dumpState(generatedPing);
|
||||
|
||||
ByteBufferAssert.assertEquals("ping buffers are not equal",buf,generatedPing);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.eclipse.jetty.websocket.parser;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -16,7 +18,8 @@ public class ParserTest
|
|||
// Put nothing in the buffer.
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.eclipse.jetty.websocket.parser;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -16,7 +18,8 @@ public class PingPayloadParserTest
|
|||
{ (byte)0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
|
|
@ -5,6 +5,8 @@ import static org.hamcrest.Matchers.*;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.BinaryFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
|
@ -20,7 +22,8 @@ public class RFC6455ExamplesParserTest
|
|||
@Test
|
||||
public void testFragmentedUnmaskedTextMessage()
|
||||
{
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
|
||||
|
@ -63,7 +66,8 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x8a, (byte)0x85, 0x37, (byte)0xfa, 0x21, 0x3d, 0x7f, (byte)0x9f, 0x4d, 0x51, 0x58 });
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -85,7 +89,8 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x81, (byte)0x85, 0x37, (byte)0xfa, 0x21, 0x3d, 0x7f, (byte)0x9f, 0x4d, 0x51, 0x58 });
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -114,7 +119,8 @@ public class RFC6455ExamplesParserTest
|
|||
}
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -152,7 +158,8 @@ public class RFC6455ExamplesParserTest
|
|||
}
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -183,7 +190,8 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x89, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -205,7 +213,8 @@ public class RFC6455ExamplesParserTest
|
|||
{ (byte)0x81, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f });
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -216,5 +225,4 @@ public class RFC6455ExamplesParserTest
|
|||
TextFrame txt = (TextFrame)capture.getFrames().get(0);
|
||||
Assert.assertThat("TextFrame.data", txt.getData().toString(), is("Hello"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import static org.hamcrest.Matchers.*;
|
|||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.websocket.Debug;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.TextFrame;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -18,9 +19,6 @@ public class TextPayloadParserTest
|
|||
@Test
|
||||
public void testLongMaskedText() throws Exception
|
||||
{
|
||||
Debug.enableDebugLogging(Parser.class);
|
||||
Debug.enableDebugLogging(TextPayloadParser.class);
|
||||
|
||||
StringBuffer sb = new StringBuffer(); ;
|
||||
for (int i = 0; i < 3500; i++)
|
||||
{
|
||||
|
@ -41,7 +39,8 @@ public class TextPayloadParserTest
|
|||
writeMaskedPayload(buf,utf);
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -55,9 +54,6 @@ public class TextPayloadParserTest
|
|||
@Test
|
||||
public void testMediumMaskedText() throws Exception
|
||||
{
|
||||
Debug.enableDebugLogging(Parser.class);
|
||||
Debug.enableDebugLogging(TextPayloadParser.class);
|
||||
|
||||
StringBuffer sb = new StringBuffer(); ;
|
||||
for (int i = 0; i < 14; i++)
|
||||
{
|
||||
|
@ -78,7 +74,8 @@ public class TextPayloadParserTest
|
|||
writeMaskedPayload(buf,utf);
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -92,9 +89,6 @@ public class TextPayloadParserTest
|
|||
@Test
|
||||
public void testShortMaskedFragmentedText() throws Exception
|
||||
{
|
||||
Debug.enableDebugLogging(Parser.class);
|
||||
Debug.enableDebugLogging(TextPayloadParser.class);
|
||||
|
||||
String part1 = "Hello ";
|
||||
String part2 = "World";
|
||||
|
||||
|
@ -117,7 +111,8 @@ public class TextPayloadParserTest
|
|||
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -142,7 +137,8 @@ public class TextPayloadParserTest
|
|||
writeMaskedPayload(buf,expectedText.getBytes(StringUtil.__UTF8));
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
@ -167,7 +163,8 @@ public class TextPayloadParserTest
|
|||
writeMaskedPayload(buf,utf);
|
||||
buf.flip();
|
||||
|
||||
Parser parser = new Parser();
|
||||
WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER);
|
||||
Parser parser = new Parser(policy);
|
||||
FrameParseCapture capture = new FrameParseCapture();
|
||||
parser.addListener(capture);
|
||||
parser.parse(buf);
|
||||
|
|
Loading…
Reference in New Issue