Search in sources :

Example 76 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase1_1 method testGenerate125ByteTextCase1_1_2.

@Test
public void testGenerate125ByteTextCase1_1_2() {
    int length = 125;
    byte[] buf = new byte[length];
    Arrays.fill(buf, (byte) '*');
    String text = new String(buf, StandardCharsets.UTF_8);
    Frame textFrame = new TextFrame().setPayload(text);
    ByteBuffer actual = UnitGenerator.generate(textFrame);
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x81 });
    // no masking
    byte b = 0x00;
    b |= length & 0x7F;
    expected.put(b);
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
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) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 77 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class TestABCase1_1 method testGenerate65536ByteTextCase1_1_7.

@Test
public void testGenerate65536ByteTextCase1_1_7() {
    int length = 65536;
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < length; ++i) {
        builder.append("*");
    }
    WebSocketFrame textFrame = new TextFrame().setPayload(builder.toString());
    ByteBuffer actual = UnitGenerator.generate(textFrame);
    ByteBuffer expected = ByteBuffer.allocate(length + 11);
    expected.put(new byte[] { (byte) 0x81 });
    // no masking
    byte b = 0x00;
    b |= 0x7F;
    expected.put(b);
    expected.put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 });
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 78 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class WebSocketFrameTest method testRsv2.

@Test
public void testRsv2() {
    TextFrame frame = new TextFrame();
    frame.setPayload("Hi");
    frame.setRsv2(true);
    laxGenerator.setRsv2InUse(true);
    ByteBuffer actual = generateWholeFrame(laxGenerator, frame);
    String expected = "A1024869";
    assertFrameHex("Lax Text Frame with RSV2", expected, actual);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 79 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class WebSocketFrameTest method testRsv1.

@Test
public void testRsv1() {
    TextFrame frame = new TextFrame();
    frame.setPayload("Hi");
    frame.setRsv1(true);
    laxGenerator.setRsv1InUse(true);
    ByteBuffer actual = generateWholeFrame(laxGenerator, frame);
    String expected = "C1024869";
    assertFrameHex("Lax Text Frame with RSV1", expected, actual);
}
Also used : TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 80 with TextFrame

use of org.eclipse.jetty.websocket.common.frames.TextFrame in project jetty.project by eclipse.

the class ParserTest method testParseCase5_19.

/**
     * Similar to the server side 5.19 testcase. text message, send in 5 frames/fragments, with 2 pings in the mix.
     */
@Test
public void testParseCase5_19() {
    List<WebSocketFrame> send = new ArrayList<>();
    send.add(new TextFrame().setPayload("f1").setFin(false));
    send.add(new ContinuationFrame().setPayload(",f2").setFin(false));
    send.add(new PingFrame().setPayload("pong-1"));
    send.add(new ContinuationFrame().setPayload(",f3").setFin(false));
    send.add(new ContinuationFrame().setPayload(",f4").setFin(false));
    send.add(new PingFrame().setPayload("pong-2"));
    send.add(new ContinuationFrame().setPayload(",f5").setFin(true));
    send.add(new CloseInfo(StatusCode.NORMAL).asFrame());
    ByteBuffer completeBuf = UnitGenerator.generate(send);
    UnitParser parser = new UnitParser();
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parseQuietly(completeBuf);
    capture.assertErrorCount(0);
    capture.assertHasFrame(OpCode.TEXT, 1);
    capture.assertHasFrame(OpCode.CONTINUATION, 4);
    capture.assertHasFrame(OpCode.CLOSE, 1);
    capture.assertHasFrame(OpCode.PING, 2);
}
Also used : PingFrame(org.eclipse.jetty.websocket.common.frames.PingFrame) ArrayList(java.util.ArrayList) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) IncomingFramesCapture(org.eclipse.jetty.websocket.common.test.IncomingFramesCapture) ContinuationFrame(org.eclipse.jetty.websocket.common.frames.ContinuationFrame) UnitParser(org.eclipse.jetty.websocket.common.test.UnitParser) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)142 Test (org.junit.Test)130 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)109 ArrayList (java.util.ArrayList)69 CloseInfo (org.eclipse.jetty.websocket.common.CloseInfo)68 Fuzzer (org.eclipse.jetty.websocket.common.test.Fuzzer)59 ByteBuffer (java.nio.ByteBuffer)54 ContinuationFrame (org.eclipse.jetty.websocket.common.frames.ContinuationFrame)38 StacklessLogging (org.eclipse.jetty.util.log.StacklessLogging)35 BlockheadClient (org.eclipse.jetty.websocket.common.test.BlockheadClient)33 PingFrame (org.eclipse.jetty.websocket.common.frames.PingFrame)23 IBlockheadClient (org.eclipse.jetty.websocket.common.test.IBlockheadClient)14 URI (java.net.URI)13 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)12 Matchers.containsString (org.hamcrest.Matchers.containsString)10 PongFrame (org.eclipse.jetty.websocket.common.frames.PongFrame)9 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)8 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)6 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)6 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)5