java类io.netty.handler.codec.http.HttpObjectAggregator的实例源码

EchoServerWS.java 文件源码 项目:examples-javafx-repos1 阅读 31 收藏 0 点赞 0 评论 0
protected ChannelInitializer<Channel> createInitializer() {

    return new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new HttpServerCodec() );
            p.addLast(new ChunkedWriteHandler());
            p.addLast(new HttpObjectAggregator(64 * 1024));
            p.addLast(new EchoServerHttpRequestHandler("/ws"));
            p.addLast(new WebSocketServerProtocolHandler("/ws"));
            p.addLast(new EchoServerWSHandler());
        }
    };
}
HttpStaticFileServerInitializer.java 文件源码 项目:scratch_zookeeper_netty 阅读 28 收藏 0 点赞 0 评论 0
@Override
protected void initChannel(SocketChannel ch)
        throws Exception {
    // Create a default pipeline implementation.
    CorsConfig corsConfig = CorsConfig.withAnyOrigin().build();
    ChannelPipeline pipeline = ch.pipeline();
    // Uncomment the following line if you want HTTPS
    //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    //engine.setUseClientMode(false);
    //pipeline.addLast("ssl", new SslHandler(engine));

    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(8388608)); // 8MB
    //pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("cors", new CorsHandler(corsConfig));
    pipeline.addLast("handler", new HttpStaticFileServerHandler());
}
NetworkManager.java 文件源码 项目:Ogar2-Server 阅读 26 收藏 0 点赞 0 评论 0
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);

    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder());
    ch.pipeline().addLast(new PacketEncoder());
    ch.pipeline().addLast(new ClientHandler(server));
}
GaleServerInitializer.java 文件源码 项目:gale 阅读 28 收藏 0 点赞 0 评论 0
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipeline = ch.pipeline();
  //inbound handler
  pipeline.addLast(new HttpRequestDecoder());
  pipeline.addLast(new HttpContentDecompressor());

  //outbound handler
  pipeline.addLast(new HttpResponseEncoder());
  pipeline.addLast(new HttpContentCompressor());
  //pipeline.addLast(new ChunkedWriteHandler());

  pipeline.addLast(new HttpObjectAggregator(this.sc.getSize()));
  pipeline.addLast(this.galeHttpHandler);

}
WebSocketClient.java 文件源码 项目:blynk-server 阅读 31 收藏 0 点赞 0 评论 0
@Override
protected ChannelInitializer<SocketChannel> getChannelInitializer() {
    return new ChannelInitializer<SocketChannel> () {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (sslCtx != null) {
                p.addLast(sslCtx.newHandler(ch.alloc(), host, port));
            }
            p.addLast(
                    new HttpClientCodec(),
                    new HttpObjectAggregator(8192),
                    handler,
                    new MessageDecoder(new GlobalStats())
            );
        }
    };
}
HttpAPIServer.java 文件源码 项目:blynk-server 阅读 52 收藏 0 点赞 0 评论 0
public HttpAPIServer(Holder holder) {
    super(holder.props.getProperty("listen.address"),
            holder.props.getIntProperty("http.port"), holder.transportTypeHolder);

    String adminRootPath = holder.props.getProperty("admin.rootPath", "/admin");

    final HttpAndWebSocketUnificatorHandler httpAndWebSocketUnificatorHandler =
            new HttpAndWebSocketUnificatorHandler(holder, port, adminRootPath);
    final LetsEncryptHandler letsEncryptHandler = new LetsEncryptHandler(holder.sslContextHolder.contentHolder);

    channelInitializer = new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
            .addLast("HttpServerCodec", new HttpServerCodec())
            .addLast("HttpServerKeepAlive", new HttpServerKeepAliveHandler())
            .addLast("HttpObjectAggregator", new HttpObjectAggregator(holder.limits.webRequestMaxSize, true))
            .addLast(letsEncryptHandler)
            .addLast("HttpChunkedWrite", new ChunkedWriteHandler())
            .addLast("HttpUrlMapper", new UrlReWriterHandler("/favicon.ico", "/static/favicon.ico"))
            .addLast("HttpStaticFile", new StaticFileHandler(holder.props, new StaticFile("/static"),
                    new StaticFileEdsWith(CSVGenerator.CSV_DIR, ".csv.gz")))
            .addLast("HttpWebSocketUnificator", httpAndWebSocketUnificatorHandler);
        }
    };
}
ApiServerInitializer.java 文件源码 项目:netty.book.kor 阅读 33 收藏 0 点赞 0 评论 0
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline p = ch.pipeline();
    if (sslCtx != null) {
        p.addLast(sslCtx.newHandler(ch.alloc()));
    }

    p.addLast(new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    p.addLast(new HttpObjectAggregator(65536));
    p.addLast(new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content
    // compression.
    p.addLast(new HttpContentCompressor());
    p.addLast(new ApiRequestParser());
}
ProtocolHandler.java 文件源码 项目:activemq-artemis 阅读 26 收藏 0 点赞 0 评论 0
private void switchToHttp(ChannelHandlerContext ctx) {
   ChannelPipeline p = ctx.pipeline();
   p.addLast("http-decoder", new HttpRequestDecoder());
   p.addLast("http-aggregator", new HttpObjectAggregator(Integer.MAX_VALUE));
   p.addLast("http-encoder", new HttpResponseEncoder());
   //create it lazily if and when we need it
   if (httpKeepAliveRunnable == null) {
      long httpServerScanPeriod = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_SERVER_SCAN_PERIOD_PROP_NAME, TransportConstants.DEFAULT_HTTP_SERVER_SCAN_PERIOD, nettyAcceptor.getConfiguration());
      httpKeepAliveRunnable = new HttpKeepAliveRunnable();
      Future<?> future = scheduledThreadPool.scheduleAtFixedRate(httpKeepAliveRunnable, httpServerScanPeriod, httpServerScanPeriod, TimeUnit.MILLISECONDS);
      httpKeepAliveRunnable.setFuture(future);
   }
   long httpResponseTime = ConfigurationHelper.getLongProperty(TransportConstants.HTTP_RESPONSE_TIME_PROP_NAME, TransportConstants.DEFAULT_HTTP_RESPONSE_TIME, nettyAcceptor.getConfiguration());
   HttpAcceptorHandler httpHandler = new HttpAcceptorHandler(httpKeepAliveRunnable, httpResponseTime, ctx.channel());
   ctx.pipeline().addLast("http-handler", httpHandler);
   p.addLast(new ProtocolDecoder(false, true));
   p.remove(this);
}
HttpClientInitializer.java 文件源码 项目:SI 阅读 24 收藏 0 点赞 0 评论 0
@Override
    public void initChannel(SocketChannel ch) {
        ChannelPipeline pipeline = ch.pipeline();

        // Enable HTTPS if necessary.
//      if (sslCtx != null) {
//          pipeline.addLast(sslCtx.newHandler(ch.alloc()));
//      }

        pipeline.addLast(new HttpClientCodec());
        // Remove the following line if you don't want automatic content decompression.
        pipeline.addLast(new HttpContentDecompressor());

        // Uncomment the following line if you don't want to handle HttpContents.
        //pipeline.addLast(new HttpObjectAggregator(65536));
        pipeline.addLast(new HttpObjectAggregator(65536 * 3));


//      pipeline.addLast(new HttpClientHandler(null, mHttpClientListener));
    }
HttpServerInitializer.java 文件源码 项目:SI 阅读 31 收藏 0 点赞 0 评论 0
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    //p.addLast(new HttpObjectAggregator(1048576));
    // Remove the following line if you don't want automatic content compression.
    //pipeline.addLast(new HttpContentCompressor());

    // Uncomment the following line if you don't want to handle HttpContents.
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast("readTimeoutHandler", new ReadTimeoutHandler(READ_TIMEOUT));
    pipeline.addLast("myHandler", new MyHandler());

    pipeline.addLast("handler", new HttpServerHandler(listener));
}


问题


面经


文章

微信
公众号

扫码关注公众号