io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CleartextHttp2ServerUpgradeHandlerTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private void setUpServerChannel() {
    frameListener = mock(Http2FrameListener.class);

    http2ConnectionHandler = new Http2ConnectionHandlerBuilder()
            .frameListener(frameListener).build();

    UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {
        @Override
        public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
            return new Http2ServerUpgradeCodec(http2ConnectionHandler);
        }
    };

    userEvents = new ArrayList<Object>();

    HttpServerCodec httpServerCodec = new HttpServerCodec();
    HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(httpServerCodec, upgradeCodecFactory);

    CleartextHttp2ServerUpgradeHandler handler = new CleartextHttp2ServerUpgradeHandler(
            httpServerCodec, upgradeHandler, http2ConnectionHandler);
    channel = new EmbeddedChannel(handler, new ChannelInboundHandlerAdapter() {
        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            userEvents.add(evt);
        }
    });
}
 
Example #2
Source File: CleartextHttp2ServerUpgradeHandlerTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void usedHttp2MultiplexCodec() throws Exception {
    final Http2MultiplexCodec http2Codec = new Http2MultiplexCodecBuilder(true, new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(Channel ch) throws Exception {
        }
    }).build();
    UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {
        @Override
        public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
            return new Http2ServerUpgradeCodec(http2Codec);
        }
    };
    http2ConnectionHandler = http2Codec;

    userEvents = new ArrayList<Object>();

    HttpServerCodec httpServerCodec = new HttpServerCodec();
    HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(httpServerCodec, upgradeCodecFactory);

    CleartextHttp2ServerUpgradeHandler handler = new CleartextHttp2ServerUpgradeHandler(
            httpServerCodec, upgradeHandler, http2Codec);
    channel = new EmbeddedChannel(handler, new ChannelInboundHandlerAdapter() {
        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            userEvents.add(evt);
        }
    });

    assertFalse(channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf()));

    ByteBuf settingsFrame = settingsFrameBuf();

    assertTrue(channel.writeInbound(settingsFrame));

    assertEquals(1, userEvents.size());
    assertTrue(userEvents.get(0) instanceof PriorKnowledgeUpgradeEvent);
}