Search in sources :

Example 36 with WebSocketPolicy

use of org.eclipse.jetty.websocket.api.WebSocketPolicy in project jetty.project by eclipse.

the class TestABCase1_2 method testParse65535ByteBinaryCase1_2_6.

@Test
public void testParse65535ByteBinaryCase1_2_6() {
    int length = 65535;
    ByteBuffer expected = ByteBuffer.allocate(length + 5);
    expected.put(new byte[] { (byte) 0x82 });
    // no masking
    byte b = 0x00;
    b |= 0x7E;
    expected.put(b);
    expected.put(new byte[] { (byte) 0xff, (byte) 0xff });
    for (int i = 0; i < length; ++i) {
        expected.put("*".getBytes());
    }
    expected.flip();
    WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.CLIENT);
    policy.setMaxBinaryMessageSize(length);
    Parser parser = new UnitParser(policy);
    IncomingFramesCapture capture = new IncomingFramesCapture();
    parser.setIncomingFramesHandler(capture);
    parser.parse(expected);
    capture.assertNoErrors();
    capture.assertHasFrame(OpCode.BINARY, 1);
    Frame pActual = capture.getFrames().poll();
    Assert.assertThat("BinaryFrame.payloadLength", pActual.getPayloadLength(), is(length));
// Assert.assertEquals("BinaryFrame.payload",length,pActual.getPayloadData().length);
}
Also used : WebSocketPolicy(org.eclipse.jetty.websocket.api.WebSocketPolicy) Frame(org.eclipse.jetty.websocket.api.extensions.Frame) BinaryFrame(org.eclipse.jetty.websocket.common.frames.BinaryFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) 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

WebSocketPolicy (org.eclipse.jetty.websocket.api.WebSocketPolicy)36 Test (org.junit.Test)26 ByteBuffer (java.nio.ByteBuffer)24 IncomingFramesCapture (org.eclipse.jetty.websocket.common.test.IncomingFramesCapture)24 UnitParser (org.eclipse.jetty.websocket.common.test.UnitParser)23 Frame (org.eclipse.jetty.websocket.api.extensions.Frame)7 MaskedByteBuffer (org.eclipse.jetty.websocket.common.util.MaskedByteBuffer)7 WebSocketFrame (org.eclipse.jetty.websocket.common.WebSocketFrame)6 TextFrame (org.eclipse.jetty.websocket.common.frames.TextFrame)6 Parser (org.eclipse.jetty.websocket.common.Parser)5 BinaryFrame (org.eclipse.jetty.websocket.common.frames.BinaryFrame)4 ExtensionConfig (org.eclipse.jetty.websocket.api.extensions.ExtensionConfig)3 Generator (org.eclipse.jetty.websocket.common.Generator)3 EventDriver (org.eclipse.jetty.websocket.common.events.EventDriver)3 SimpleContainerScope (org.eclipse.jetty.websocket.common.scopes.SimpleContainerScope)3 Before (org.junit.Before)3 URI (java.net.URI)2 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)2 WebSocketContainerScope (org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope)2 DummyConnection (org.eclipse.jetty.websocket.common.test.DummyConnection)2