Search in sources :

Example 36 with BinaryWebSocketFrame

use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.

the class WebSocketExtensionFilterTest method testNeverSkip.

@Test
public void testNeverSkip() {
    WebSocketExtensionFilter neverSkip = WebSocketExtensionFilter.NEVER_SKIP;
    BinaryWebSocketFrame binaryFrame = new BinaryWebSocketFrame();
    assertFalse(neverSkip.mustSkip(binaryFrame));
    assertTrue(binaryFrame.release());
    TextWebSocketFrame textFrame = new TextWebSocketFrame();
    assertFalse(neverSkip.mustSkip(textFrame));
    assertTrue(textFrame.release());
    PingWebSocketFrame pingFrame = new PingWebSocketFrame();
    assertFalse(neverSkip.mustSkip(pingFrame));
    assertTrue(pingFrame.release());
    PongWebSocketFrame pongFrame = new PongWebSocketFrame();
    assertFalse(neverSkip.mustSkip(pongFrame));
    assertTrue(pongFrame.release());
    CloseWebSocketFrame closeFrame = new CloseWebSocketFrame();
    assertFalse(neverSkip.mustSkip(closeFrame));
    assertTrue(closeFrame.release());
    ContinuationWebSocketFrame continuationFrame = new ContinuationWebSocketFrame();
    assertFalse(neverSkip.mustSkip(continuationFrame));
    assertTrue(continuationFrame.release());
}
Also used : CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) ContinuationWebSocketFrame(io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) PingWebSocketFrame(io.netty.handler.codec.http.websocketx.PingWebSocketFrame) Test(org.junit.jupiter.api.Test)

Example 37 with BinaryWebSocketFrame

use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.

the class PerFrameDeflateDecoderTest method testCompressedFrame.

@Test
public void testCompressedFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerFrameDeflateDecoder(false));
    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);
    assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload)));
    ByteBuf compressedPayload = encoderChannel.readOutbound();
    BinaryWebSocketFrame compressedFrame = new BinaryWebSocketFrame(true, RSV1 | RSV3, compressedPayload.slice(0, compressedPayload.readableBytes() - 4));
    // execute
    assertTrue(decoderChannel.writeInbound(compressedFrame));
    BinaryWebSocketFrame uncompressedFrame = decoderChannel.readInbound();
    // test
    assertNotNull(uncompressedFrame);
    assertNotNull(uncompressedFrame.content());
    assertEquals(RSV3, uncompressedFrame.rsv());
    assertEquals(300, uncompressedFrame.content().readableBytes());
    byte[] finalPayload = new byte[300];
    uncompressedFrame.content().readBytes(finalPayload);
    assertArrayEquals(finalPayload, payload);
    uncompressedFrame.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 38 with BinaryWebSocketFrame

use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.

the class PerMessageDeflateDecoderTest method testNormalFrame.

@Test
public void testNormalFrame() {
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false));
    // initialize
    byte[] payload = new byte[300];
    random.nextBytes(payload);
    BinaryWebSocketFrame frame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV3, Unpooled.wrappedBuffer(payload));
    // execute
    assertTrue(decoderChannel.writeInbound(frame));
    BinaryWebSocketFrame newFrame = decoderChannel.readInbound();
    // test
    assertNotNull(newFrame);
    assertNotNull(newFrame.content());
    assertEquals(WebSocketExtension.RSV3, newFrame.rsv());
    assertEquals(300, newFrame.content().readableBytes());
    byte[] finalPayload = new byte[300];
    newFrame.content().readBytes(finalPayload);
    assertArrayEquals(finalPayload, payload);
    newFrame.release();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) Test(org.junit.jupiter.api.Test)

Example 39 with BinaryWebSocketFrame

use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.

the class PerMessageDeflateDecoderTest method testDecompressionSkipForBinaryFrame.

@Test
public void testDecompressionSkipForBinaryFrame() {
    EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false, ALWAYS_SKIP));
    byte[] payload = new byte[300];
    random.nextBytes(payload);
    assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(payload)));
    ByteBuf compressedPayload = encoderChannel.readOutbound();
    BinaryWebSocketFrame compressedBinaryFrame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV1, compressedPayload);
    assertTrue(decoderChannel.writeInbound(compressedBinaryFrame));
    WebSocketFrame inboundFrame = decoderChannel.readInbound();
    assertEquals(WebSocketExtension.RSV1, inboundFrame.rsv());
    assertEquals(compressedPayload, inboundFrame.content());
    assertTrue(inboundFrame.release());
    assertTrue(encoderChannel.finishAndReleaseAll());
    assertFalse(decoderChannel.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) ContinuationWebSocketFrame(io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 40 with BinaryWebSocketFrame

use of io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame in project netty by netty.

the class PerMessageDeflateDecoderTest method testSelectivityDecompressionSkip.

@Test
public void testSelectivityDecompressionSkip() {
    WebSocketExtensionFilter selectivityDecompressionFilter = new WebSocketExtensionFilter() {

        @Override
        public boolean mustSkip(WebSocketFrame frame) {
            return frame instanceof TextWebSocketFrame && frame.content().readableBytes() < 100;
        }
    };
    EmbeddedChannel encoderChannel = new EmbeddedChannel(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.NONE, 9, 15, 8));
    EmbeddedChannel decoderChannel = new EmbeddedChannel(new PerMessageDeflateDecoder(false, selectivityDecompressionFilter));
    String textPayload = "compressed payload";
    byte[] binaryPayload = new byte[300];
    random.nextBytes(binaryPayload);
    assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(textPayload.getBytes(UTF_8))));
    assertTrue(encoderChannel.writeOutbound(Unpooled.wrappedBuffer(binaryPayload)));
    ByteBuf compressedTextPayload = encoderChannel.readOutbound();
    ByteBuf compressedBinaryPayload = encoderChannel.readOutbound();
    TextWebSocketFrame compressedTextFrame = new TextWebSocketFrame(true, WebSocketExtension.RSV1, compressedTextPayload);
    BinaryWebSocketFrame compressedBinaryFrame = new BinaryWebSocketFrame(true, WebSocketExtension.RSV1, compressedBinaryPayload);
    assertTrue(decoderChannel.writeInbound(compressedTextFrame));
    assertTrue(decoderChannel.writeInbound(compressedBinaryFrame));
    TextWebSocketFrame inboundTextFrame = decoderChannel.readInbound();
    BinaryWebSocketFrame inboundBinaryFrame = decoderChannel.readInbound();
    assertEquals(WebSocketExtension.RSV1, inboundTextFrame.rsv());
    assertEquals(compressedTextPayload, inboundTextFrame.content());
    assertTrue(inboundTextFrame.release());
    assertEquals(0, inboundBinaryFrame.rsv());
    assertArrayEquals(binaryPayload, ByteBufUtil.getBytes(inboundBinaryFrame.content()));
    assertTrue(inboundBinaryFrame.release());
    assertTrue(encoderChannel.finishAndReleaseAll());
    assertFalse(decoderChannel.finish());
}
Also used : TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) WebSocketExtensionFilter(io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionFilter) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) ContinuationWebSocketFrame(io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame) BinaryWebSocketFrame(io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Aggregations

BinaryWebSocketFrame (io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame)51 ByteBuf (io.netty.buffer.ByteBuf)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)24 Test (org.junit.jupiter.api.Test)23 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)19 ContinuationWebSocketFrame (io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame)17 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)11 FrameChecker (io.undertow.websockets.utils.FrameChecker)8 WebSocketTestClient (io.undertow.websockets.utils.WebSocketTestClient)8 URI (java.net.URI)8 FutureResult (org.xnio.FutureResult)8 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 PingWebSocketFrame (io.netty.handler.codec.http.websocketx.PingWebSocketFrame)6 PongWebSocketFrame (io.netty.handler.codec.http.websocketx.PongWebSocketFrame)6 ServerWebSocketContainer (io.undertow.websockets.jsr.ServerWebSocketContainer)6 UndertowSession (io.undertow.websockets.jsr.UndertowSession)6 AnnotatedClientEndpoint (io.undertow.websockets.jsr.test.annotated.AnnotatedClientEndpoint)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Endpoint (javax.websocket.Endpoint)6