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

The following examples show how to use io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodec. 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: Http2ServerInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(
                Http2MultiplexCodecBuilder.forServer(new HelloWorldHttp2Handler()).build());
    } else {
        return null;
    }
}
 
Example #2
Source File: Http2ServerInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(new HelloWorldHttp2HandlerBuilder().build());
    } else {
        return null;
    }
}
 
Example #3
Source File: Http2ServerInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(
                Http2FrameCodecBuilder.forServer().build(), new HelloWorldHttp2Handler());
    } else {
        return null;
    }
}
 
Example #4
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 #5
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);
}
 
Example #6
Source File: Http2ServerInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
    if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
        return new Http2ServerUpgradeCodec(new HelloWorldHttp2HandlerBuilder().build());
    } else {
        return null;
    }
}