Search in sources :

Example 1 with HttpProxyServerHandle

use of com.wing.apirecord.core.handler.HttpProxyServerHandle in project apiRecord by tobecoder2015.

the class NettyHttpProxyServer method start.

public void start(int port) {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    // ChannelInboundHandlerAdapter
    try {
        init();
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<Channel>() {

            @Override
            protected void initChannel(Channel ch) throws Exception {
                ch.pipeline().addLast("httpCodec", new HttpServerCodec());
                ch.pipeline().addLast(new ReadTimeoutHandler(10));
                ch.pipeline().addLast(new WriteTimeoutHandler(10));
                ch.pipeline().addLast("serverHandle", new HttpProxyServerHandle(proxyInterceptFactory.build()));
            }
        });
        ChannelFuture f = b.bind(port).sync();
        f.channel().closeFuture().sync();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
Also used : NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) WriteTimeoutHandler(io.netty.handler.timeout.WriteTimeoutHandler) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) HttpProxyServerHandle(com.wing.apirecord.core.handler.HttpProxyServerHandle) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Aggregations

HttpProxyServerHandle (com.wing.apirecord.core.handler.HttpProxyServerHandle)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 WriteTimeoutHandler (io.netty.handler.timeout.WriteTimeoutHandler)1