Search in sources :

Example 16 with Parser

use of org.eclipse.jetty.websocket.common.Parser in project jetty.project by eclipse.

the class TestABCase2 method testParseEmptyPingCase2_1.

@Test
public void testParseEmptyPingCase2_1() {
    ByteBuffer expected = ByteBuffer.allocate(5);
    expected.put(new byte[] { (byte) 0x89, (byte) 0x00 });
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.PING, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("PingFrame.payloadLength", pActual.getPayloadLength(), is(0));
    Assert.assertEquals("PingFrame.payload", 0, pActual.getPayloadLength());
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 17 with Parser

use of org.eclipse.jetty.websocket.common.Parser in project jetty.project by eclipse.

the class TestABCase7_3 method testCase7_3_4ParseCloseWithStatusReason.

@Test
public void testCase7_3_4ParseCloseWithStatusReason() {
    String message = "bad cough";
    byte[] messageBytes = message.getBytes();
    ByteBuffer expected = ByteBuffer.allocate(32);
    expected.put(new byte[] { (byte) 0x88 });
    // no masking
    byte b = 0x00;
    b |= (messageBytes.length + 2) & 0x7F;
    expected.put(b);
    expected.putShort((short) 1000);
    expected.put(messageBytes);
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.CLOSE, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("CloseFrame.payloadLength", pActual.getPayloadLength(), is(messageBytes.length + 2));
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) CloseFrame(org.eclipse.jetty.websocket.common.frames.CloseFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) Matchers.containsString(org.hamcrest.Matchers.containsString) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 18 with Parser

use of org.eclipse.jetty.websocket.common.Parser in project jetty.project by eclipse.

the class TestABCase1_1 method testParse128ByteTextCase1_1_5.

@Test
public void testParse128ByteTextCase1_1_5() {
    int length = 128;
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x81 });
    // no masking
    byte b = 0x00;
    b |= 0x7E;
    expected.put(b);
    expected.putShort((short) length);
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.TEXT, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(length));
// .assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 19 with Parser

use of org.eclipse.jetty.websocket.common.Parser in project jetty.project by eclipse.

the class TestABCase1_1 method testParseEmptyTextCase1_1_1.

@Test
public void testParseEmptyTextCase1_1_1() {
    ByteBuffer expected = ByteBuffer.allocate(5);
    expected.put(new byte[] { (byte) 0x81, (byte) 0x00 });
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.TEXT, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(0));
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Example 20 with Parser

use of org.eclipse.jetty.websocket.common.Parser in project jetty.project by eclipse.

the class TestABCase1_1 method testParse126ByteTextCase1_1_3.

@Test
public void testParse126ByteTextCase1_1_3() {
    int length = 126;
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x81 });
    // no masking
    byte b = 0x00;
    b |= length & 0x7E;
    expected.put(b);
    expected.putShort((short) length);
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.TEXT, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("TextFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("TextFrame.payload",length,pActual.getPayloadData().length);
}
Also used : Frame(org.eclipse.jetty.websocket.api.extensions.Frame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Parser(org.eclipse.jetty.websocket.common.Parser) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) Test(org.junit.Test)

Aggregations

ByteBuffer (java.nio.ByteBuffer)27 Parser (org.eclipse.jetty.websocket.common.Parser)27 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)27 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)27 Test (org.junit.Test)26 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)22 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)19 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)7 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)7 WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)5 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)4 ProtocolException (org.eclipse.jetty.websocket.api.ProtocolException)4 WebSocketException (org.eclipse.jetty.websocket.api.WebSocketException)4 CloseFrame (org.eclipse.jetty.websocket.common.frames.CloseFrame)4 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)4 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1