io.netty.handler.stream.ChunkedWriteHandler Java Examples

The following examples show how to use io.netty.handler.stream.ChunkedWriteHandler. 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: HttpUploadClientIntializer.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

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

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #2
Source File: HttpUploadClientInitializer.java    From tools-journey with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

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

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #3
Source File: HttpClient.java    From multi-model-server with Apache License 2.0 6 votes vote down vote up
private Bootstrap bootstrap(ClientHandler handler) {
    Bootstrap b = new Bootstrap();
    b.group(new NioEventLoopGroup(1))
            .channel(NioSocketChannel.class)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10 * 1000)
            .handler(
                    new ChannelInitializer<Channel>() {
                        @Override
                        public void initChannel(Channel ch) {
                            ChannelPipeline p = ch.pipeline();
                            p.addLast(new ReadTimeoutHandler(10 * 60 * 1000));
                            p.addLast(new HttpClientCodec());
                            p.addLast(new HttpContentDecompressor());
                            p.addLast(new ChunkedWriteHandler());
                            p.addLast(new HttpObjectAggregator(6553600));
                            p.addLast(handler);
                        }
                    });
    return b;
}
 
Example #4
Source File: WebSocketChannelInitializer.java    From netstrap with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    SslConfig ssl = nettyConfig.getSsl();

    if (ssl.isEnable()) {
        initSSL(pipeline, ssl);
    }

    //超时检测
    IdleStateHandler idleStateHandler = new IdleStateHandler(
            nettyConfig.getRead(),
            nettyConfig.getWrite(),
            nettyConfig.getAll(), TimeUnit.MINUTES);

    pipeline.addLast(idleStateHandler);
    pipeline.addLast("http-codec", new HttpServerCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65535));
    pipeline.addLast("http-chucked", new ChunkedWriteHandler());
    pipeline.addLast("handler", handler);
}
 
Example #5
Source File: TtyServerInitializer.java    From termd with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipeline = ch.pipeline();
  pipeline.addLast(new HttpServerCodec());
  pipeline.addLast(new ChunkedWriteHandler());
  pipeline.addLast(new HttpObjectAggregator(64 * 1024));
  HttpRequestHandler httpRequestHandler = null;
      if (httpResourcePath == null) {
          httpRequestHandler = new HttpRequestHandler("/ws");
      } else {
          httpRequestHandler = new HttpRequestHandler("/ws", httpResourcePath);
      }

  pipeline.addLast(httpRequestHandler);
  pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
  pipeline.addLast(new TtyWebSocketFrameHandler(group, handler, HttpRequestHandler.class));
}
 
Example #6
Source File: HandlerInitializer.java    From netty-rest-server with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    /*
     * ChannelInboundHandler按照注册的先后顺序执行,ChannelOutboundHandler按照注册的先后顺序逆序执行。
     * HttpRequestDecoder、HttpObjectAggregator、HttpHandler为InboundHandler
     * HttpContentCompressor、HttpResponseEncoder为OutboundHandler
     * 在使用Handler的过程中,需要注意:
     * 1、ChannelInboundHandler之间的传递,通过调用 ctx.fireChannelRead(msg) 实现;调用ctx.write(msg) 将传递到ChannelOutboundHandler。
     * 2、ctx.write()方法执行后,需要调用flush()方法才能令它立即执行。
     * 3、ChannelOutboundHandler 在注册的时候需要放在最后一个ChannelInboundHandler之前,否则将无法传递到ChannelOutboundHandler。
     * 4、Handler的消费处理放在最后一个处理。
     */
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(maxContentLength));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    // 启用gzip(由于使用本地存储文件,不能启用gzip)
    //pipeline.addLast(new HttpContentCompressor(1));
    pipeline.addLast(new ChunkedWriteHandler());
    // 将HttpRequestHandler放在业务线程池中执行,避免阻塞worker线程。
    pipeline.addLast(eventExecutorGroup, "httpRequestHandler", new HttpRequestHandler());
}
 
Example #7
Source File: GatewayServer.java    From pampas with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelInitializer<SocketChannel> newChannelInitializer() {

    return new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
                    .addLast(loggingHandler)
                    .addLast(new IdleStateHandler(30, 0, 10))
                    .addLast("decoder", new HttpRequestDecoder())
                    .addLast("http-aggregator", new HttpObjectAggregator(65536))
                    .addLast("encoder", new HttpResponseEncoder())
                    .addLast("chunk", new ChunkedWriteHandler())
                    .addLast(businessExecutors, "business-handler", new HttpServerHandler())
                    .addLast(new HeartbeatHandler())
                    .addLast(exceptionHandler);

        }
    };
}
 
Example #8
Source File: HttpBlobStore.java    From bazel-buildfarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
private void releaseUploadChannel(Channel ch) {
  if (ch.isOpen()) {
    try {
      ch.pipeline().remove(HttpResponseDecoder.class);
      ch.pipeline().remove(HttpObjectAggregator.class);
      ch.pipeline().remove(HttpRequestEncoder.class);
      ch.pipeline().remove(ChunkedWriteHandler.class);
      ch.pipeline().remove(HttpUploadHandler.class);
    } catch (NoSuchElementException e) {
      // If the channel is in the process of closing but not yet closed, some handlers could have
      // been removed and would cause NoSuchElement exceptions to be thrown. Because handlers are
      // removed in reverse-order, if we get a NoSuchElement exception, the following handlers
      // should have been removed.
    }
  }
  channelPool.release(ch);
}
 
Example #9
Source File: HttpUploadClientInitializer.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast("ssl", sslCtx.newHandler(ch.alloc()));
    }

    pipeline.addLast("codec", new HttpClientCodec());

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

    // to be used since huge file transfer
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpUploadClientHandler());
}
 
Example #10
Source File: HttpServerChannelInitializer.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(Channel ch) throws Exception {
   Preconditions.checkNotNull(handler, "Must specify a channel handler");
   
   ChannelPipeline pipeline = ch.pipeline();
   pipeline.addLast(new HttpServerCodec());
   if(maxRequestSizeBytes > 0) {
      pipeline.addLast(new HttpObjectAggregator(maxRequestSizeBytes));
   }
   if(chunkedWrites) {
      pipeline.addLast(new ChunkedWriteHandler());
   }
   if(clientFactory != null) {
      pipeline.addLast(new BindClientContextHandler(cookieConfig, clientFactory, requestAuthorizer));
   }
   pipeline.addLast(handler);
}
 
Example #11
Source File: WebSocketInitializer.java    From jeesupport with MIT License 6 votes vote down vote up
@Override
	protected void initChannel( SocketChannel _channel ) throws Exception {
		ChannelPipeline pipeline = _channel.pipeline();

		// 是否使用客户端模式
		if( CommonConfig.getBoolean( "jees.jsts.websocket.ssl.enable", false ) ){
			SSLEngine engine = sslContext1.createSSLEngine();
//			 是否需要验证客户端
			engine.setUseClientMode(false);
//			engine.setNeedClientAuth(false);
			pipeline.addFirst("ssl", new SslHandler( engine ));
		}

		pipeline.addLast( new IdleStateHandler( 100 , 0 , 0 , TimeUnit.SECONDS ) );
		pipeline.addLast( new HttpServerCodec() );
		pipeline.addLast( new ChunkedWriteHandler() );
		pipeline.addLast( new HttpObjectAggregator( 8192 ) );
		pipeline.addLast( new WebSocketServerProtocolHandler( CommonConfig.getString( ISocketBase.Netty_WebSocket_Url, "/" ) ) );
		pipeline.addLast( CommonContextHolder.getBean( WebSocketHandler.class ) );
	}
 
Example #12
Source File: TestServer.java    From pampas with Apache License 2.0 6 votes vote down vote up
private ServerBootstrap serverBootstrap() {
        boot.group(bossGroup, workGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                                  @Override
                                  protected void initChannel(SocketChannel ch) throws Exception {
                                      ch.pipeline()
                                              .addLast("decoder", new HttpRequestDecoder())
                                              .addLast("http-aggregator", new HttpObjectAggregator(65536))
//                                              .addLast("encoder", new HttpResponseDecoder())
                                              .addLast("base-encoder", new HttpResponseEncoder())
                                              .addLast("chunk", new ChunkedWriteHandler())
                                              .addLast("handler", new TestHttpServerHandler());

                                  }
                              }
                );


        return boot;
    }
 
Example #13
Source File: HttpRequestInitializer.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
   PREVIEW_STARTED.inc();

   ChannelPipeline pipeline = ch.pipeline();
   pipeline.addLast(inboundIpTracking);

   if (serverTlsContext != null && serverTlsContext.useTls()) {
      SSLEngine engine = serverTlsContext.getContext().newEngine(ch.alloc());
      engine.setNeedClientAuth(serverConfig.isTlsNeedClientAuth());
      engine.setUseClientMode(false);
      pipeline.addLast(FILTER_SSL, new SslHandler(engine));
   }

   pipeline.addLast(FILTER_CODEC, new HttpServerCodec());
   pipeline.addLast(FILTER_HTTP_AGGREGATOR, new HttpObjectAggregator(65536));
   pipeline.addLast("ChunkedWriteHandler", new ChunkedWriteHandler());
   pipeline.addLast("bind-client-context", bindClient);
   pipeline.addLast(FILTER_HANDLER, handlerProvider.get());
   pipeline.addLast(outboundIpTracking);

   ch.pipeline().addAfter(FILTER_HTTP_AGGREGATOR, "corshandler", new CorsHandler(corsConfig.build()));
}
 
Example #14
Source File: FrontFilter.java    From api-gateway-core with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    config.getChannelInboundHandlerList().forEach(pipeline::addLast);
    config.getChannelOutboundHandlerList().forEach(pipeline::addLast);
    pipeline.addLast(new HttpResponseEncoder());
    config.getHttpResponseHandlerList().forEach(pipeline::addLast);
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpObjectAggregator(10 * 1024 * 1024));
    pipeline.addLast(new FrontHandler());
    pipeline.addLast(new ExceptionHandler());


    ch.closeFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            logger.debug("channel close");
        }
    });
}
 
Example #15
Source File: BackPoolHandler.java    From api-gateway-core with Apache License 2.0 6 votes vote down vote up
@Override
    public void channelCreated(Channel ch) throws Exception {
        logger.debug("channelCreated. Channel ID: {}", ch.id());
        NioSocketChannel channel = (NioSocketChannel) ch;
        channel.config().setKeepAlive(true);
        channel.config().setTcpNoDelay(true);
        ChannelPipeline pipeline = channel.pipeline();
        if (sslCtx != null) {
            pipeline.addLast(sslCtx.newHandler(ch.alloc()));
        }
        pipeline.addLast(new HttpClientCodec());
        pipeline.addLast(new HttpContentDecompressor());
        pipeline.addLast(new HttpObjectAggregator(1024 * 1024 * 64));
        pipeline.addLast(new ChunkedWriteHandler());
//        pipeline.addLast(new ReadTimeoutHandler(requestHolder.route.getTimeoutInMilliseconds(), TimeUnit.MILLISECONDS));
        pipeline.addLast(new BackHandler());
    }
 
Example #16
Source File: EchoServerWS.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
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());
		}
	};
}
 
Example #17
Source File: DispatcherServletChannelInitializer.java    From nettyholdspringmvc with Apache License 2.0 6 votes vote down vote up
@Override
public void initChannel(SocketChannel channel) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = channel.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("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpChunkAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("handler", new ServletNettyHandler(this.dispatcherServlet));
}
 
Example #18
Source File: ReactorNetty.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
static void addChunkedWriter(Connection c){
	if (c.channel()
	     .pipeline()
	     .get(ChunkedWriteHandler.class) == null) {
		c.addHandlerLast(NettyPipeline.ChunkedWriter, new ChunkedWriteHandler());
	}
}
 
Example #19
Source File: Server.java    From fileserver with Apache License 2.0 5 votes vote down vote up
public void bind(int port) throws InterruptedException {
	EventLoopGroup bossGroup = new NioEventLoopGroup();
	EventLoopGroup workerGroup = new NioEventLoopGroup();

	try {
		marshallingEncoderCache = MarshallingCodeCFactory.buildMarshallingEncoder();

		ServerBootstrap b = new ServerBootstrap();
		b.group(bossGroup, workerGroup)
		.channel(NioServerSocketChannel.class)
		.option(ChannelOption.SO_BACKLOG, 100)
		.handler(new LoggingHandler(LogLevel.ERROR))
		.childHandler(new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(SocketChannel ch)
					throws Exception {

				ch.pipeline().addLast("marencoder",marshallingEncoderCache);
				ch.pipeline().addLast(
						MarshallingCodeCFactory
						.buildMarshallingDecoder());
				ch.pipeline().addLast("chunkedWriteHandler",new ChunkedWriteHandler());
				ch.pipeline().addLast("ServerHandler",new ServerHandler());

			}
		});

		ChannelFuture f = b.bind(port).sync();

		f.channel().closeFuture().sync();

	} finally {
		bossGroup.shutdownGracefully();
		workerGroup.shutdownGracefully();
	}
}
 
Example #20
Source File: HttpMatcher.java    From cute-proxy with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void handlePipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpServerExpectContinueHandler());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpContentCompressor());
    pipeline.addLast(new HttpRequestHandler(sslContextManager));
}
 
Example #21
Source File: FastdfsPool.java    From fastdfs-client with Apache License 2.0 5 votes vote down vote up
public void channelCreated(Channel channel) throws Exception {
    if (LOG.isInfoEnabled()) {
        LOG.info("channel created : {}", channel.toString());
    }

    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast(new IdleStateHandler(readTimeout, 0, idleTimeout, TimeUnit.MILLISECONDS));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new FastdfsHandler());
}
 
Example #22
Source File: Balancer.java    From timely with Apache License 2.0 5 votes vote down vote up
protected ChannelHandler setupHttpChannel(BalancerConfiguration balancerConfig, SslContext sslCtx,
        MetricResolver metricResolver, HttpClientPool httpClientPool) {

    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {

            ch.pipeline().addLast("ssl", new NonSslRedirectHandler(balancerConfig.getHttp(), sslCtx));
            ch.pipeline().addLast("encoder", new HttpResponseEncoder());
            ch.pipeline().addLast("decoder", new HttpRequestDecoder());
            ch.pipeline().addLast("compressor", new HttpContentCompressor());
            ch.pipeline().addLast("decompressor", new HttpContentDecompressor());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(65536));
            ch.pipeline().addLast("chunker", new ChunkedWriteHandler());
            ch.pipeline().addLast("queryDecoder", new timely.netty.http.HttpRequestDecoder(
                    balancerConfig.getSecurity(), balancerConfig.getHttp()));
            ch.pipeline().addLast("fileServer", new HttpStaticFileServerHandler().setIgnoreSslHandshakeErrors(
                    balancerConfig.getSecurity().getServerSsl().isUseGeneratedKeypair()));
            ch.pipeline().addLast("login",
                    new X509LoginRequestHandler(balancerConfig.getSecurity(), balancerConfig.getHttp()));
            ch.pipeline().addLast("httpRelay", new HttpRelayHandler(metricResolver, httpClientPool));
            ch.pipeline().addLast("error", new TimelyExceptionHandler().setIgnoreSslHandshakeErrors(
                    balancerConfig.getSecurity().getServerSsl().isUseGeneratedKeypair()));
        }
    };
}
 
Example #23
Source File: AbstractBootstrapServer.java    From InChat with Apache License 2.0 5 votes vote down vote up
private  void intProtocolHandler(ChannelPipeline channelPipeline,InitNetty serverBean){
        channelPipeline.addLast(BootstrapConstant.HTTP_CODE,new HttpServerCodec());
//        channelPipeline.addLast("http-decoder",new HttpRequestDecoder());
        channelPipeline.addLast(BootstrapConstant.AGGREGATOR, new HttpObjectAggregator(serverBean.getMaxContext()));
//        channelPipeline.addLast("http-encoder",new HttpResponseEncoder());
        channelPipeline.addLast(BootstrapConstant.CHUNKED_WRITE,new ChunkedWriteHandler());
        channelPipeline.addLast(BootstrapConstant.WEB_SOCKET_HANDLER,new WebSocketServerProtocolHandler(serverBean.getWebSocketPath()));
    }
 
Example #24
Source File: ModelServerTest.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
private Channel connect(boolean management) {
    Logger logger = LoggerFactory.getLogger(ModelServerTest.class);

    final Connector connector = configManager.getListener(management);
    try {
        Bootstrap b = new Bootstrap();
        final SslContext sslCtx =
                SslContextBuilder.forClient()
                        .trustManager(InsecureTrustManagerFactory.INSTANCE)
                        .build();
        b.group(Connector.newEventLoopGroup(1))
                .channel(connector.getClientChannel())
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                .handler(
                        new ChannelInitializer<Channel>() {
                            @Override
                            public void initChannel(Channel ch) {
                                ChannelPipeline p = ch.pipeline();
                                if (connector.isSsl()) {
                                    p.addLast(sslCtx.newHandler(ch.alloc()));
                                }
                                p.addLast(new ReadTimeoutHandler(30));
                                p.addLast(new HttpClientCodec());
                                p.addLast(new HttpContentDecompressor());
                                p.addLast(new ChunkedWriteHandler());
                                p.addLast(new HttpObjectAggregator(6553600));
                                p.addLast(new TestHandler());
                            }
                        });

        return b.connect(connector.getSocketAddress()).sync().channel();
    } catch (Throwable t) {
        logger.warn("Connect error.", t);
    }
    return null;
}
 
Example #25
Source File: HttpCorsServerInitializer.java    From HttpProxy with MIT License 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new CorsHandler(corsConfig));
    pipeline.addLast(new OkResponseHandler());
}
 
Example #26
Source File: FileMsgSendInitializer.java    From codes-scratch-zookeeper-netty with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch)
        throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("encod", new FileMsgEncoder());//编码
    pipeline.addLast("idle", new IdleStateHandler(3, 0, 0));//心跳
    pipeline.addLast("handle", new FileMsgSendHandler());//send file msg
}
 
Example #27
Source File: NettyHttpServerInitializer.java    From redant with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

    // HttpServerCodec is a combination of HttpRequestDecoder and HttpResponseEncoder
    // 使用HttpServerCodec将ByteBuf编解码为httpRequest/httpResponse
    pipeline.addLast(new HttpServerCodec());
    addAdvanced(pipeline);
    pipeline.addLast(new ChunkedWriteHandler());
    // 路由分发器
    pipeline.addLast(new ControllerDispatcher());
}
 
Example #28
Source File: ProtocolDetectHandler.java    From arthas with Apache License 2.0 5 votes vote down vote up
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    ByteBuf in = (ByteBuf) msg;
    if (in.readableBytes() < 3) {
        return;
    }

    if (detectTelnetFuture != null && detectTelnetFuture.isCancellable()) {
        detectTelnetFuture.cancel(false);
    }

    byte[] bytes = new byte[3];
    in.getBytes(0, bytes);
    String httpHeader = new String(bytes);

    ChannelPipeline pipeline = ctx.pipeline();
    if (!"GET".equalsIgnoreCase(httpHeader)) { // telnet
        channelGroup.add(ctx.channel());
        TelnetChannelHandler handler = new TelnetChannelHandler(handlerFactory);
        pipeline.addLast(handler);
        ctx.fireChannelActive(); // trigger TelnetChannelHandler init
    } else {
        pipeline.addLast(new HttpServerCodec());
        pipeline.addLast(new ChunkedWriteHandler());
        pipeline.addLast(new HttpObjectAggregator(64 * 1024));
        pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File("arthas-output")));
        pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
        pipeline.addLast(new TtyWebSocketFrameHandler(channelGroup, ttyConnectionFactory));
        ctx.fireChannelActive();
    }
    pipeline.remove(this);
    ctx.fireChannelRead(in);
}
 
Example #29
Source File: TtyServerInitializer.java    From arthas with Apache License 2.0 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {

  ChannelPipeline pipeline = ch.pipeline();
  pipeline.addLast(new HttpServerCodec());
  pipeline.addLast(new ChunkedWriteHandler());
  pipeline.addLast(new HttpObjectAggregator(64 * 1024));
  pipeline.addLast(workerGroup, "HttpRequestHandler", new HttpRequestHandler("/ws", new File("arthas-output")));
  pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
  pipeline.addLast(new TtyWebSocketFrameHandler(group, handler));
}
 
Example #30
Source File: NettyEmbeddedServletInitializer.java    From Jinx with Apache License 2.0 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslContext != null) {
        SSLEngine sslEngine = sslContext.newEngine(ch.alloc());
        sslEngine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(sslEngine));
    }
    pipeline.addLast("codec", new HttpServerCodec());
    pipeline.addLast("aggregator", new HttpObjectAggregator(1024 * 1024 * 64));
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("handler", new ServletContentHandler(servletContext));
    pipeline.addLast(servletExecutor, "filterChain", requestDispatcherHandler);
    ChannelThreadLocal.set(ch);
}