Java 类io.netty.handler.codec.http.HttpRequestDecoder 实例源码

项目:Camel    文件:HttpServerSharedInitializerFactory.java   
@Override
protected void initChannel(Channel ch) throws Exception {
    // create a new pipeline
    ChannelPipeline pipeline = ch.pipeline();

    SslHandler sslHandler = configureServerSSLOnDemand();
    if (sslHandler != null) {
        LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
        pipeline.addLast("ssl", sslHandler);
    }

    pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    if (configuration.isChunked()) {
        pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
    }
    if (configuration.isCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }

    pipeline.addLast("handler", channelFactory.getChannelHandler());
}
项目:push-network-proxies    文件:MockingFCMServerInitializer.java   
@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(1048576));
    p.addLast(new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast(new HttpContentCompressor());
    p.addLast(new MockingFCMServerHandler());
}
项目:tasfe-framework    文件:HttpChannelInitializer.java   
public final ChannelPipeline appendHttpPipeline(ChannelPipeline channelPipeline) {
    // 服务端,对响应编码。属于ChannelOutboundHandler,逆序执行
    channelPipeline.addLast("encoder", new HttpResponseEncoder());

    // 服务端,对请求解码。属于ChannelIntboundHandler,按照顺序执行
    channelPipeline.addLast("decoder", new HttpRequestDecoder());
    //即通过它可以把 HttpMessage 和 HttpContent 聚合成一个 FullHttpRequest,并定义可以接受的数据大小,在文件上传时,可以支持params+multipart
    channelPipeline.addLast("aggregator", new HttpObjectAggregator(maxConentLength));
    //块写入写出Handler
    channelPipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    // 对传输数据进行压缩,这里在客户端需要解压缩处理
    // channelPipeline.addLast("deflater", new HttpContentCompressor());

    HttpServletHandler servletHandler = new HttpServletHandler();
    servletHandler.addInterceptor(new ChannelInterceptor());
    //servletHandler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
    // 自定义Handler
    channelPipeline.addLast("handler", servletHandler);
    // 异步
    // channelPipeline.addLast(businessExecutor, new AsyncHttpServletHandler());
    return channelPipeline;
}
项目:util4j    文件:HttpServerInitHandler.java   
@Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline p = ch.pipeline();
        if(sslCtx!=null)
        {
            p.addLast(new SslHandler(sslCtx.newEngine(ch.alloc())));
        }
        p.addLast(new HttpResponseEncoder());//必须放在最前面,如果decoder途中需要回复消息,则decoder前面需要encoder
        p.addLast(new HttpRequestDecoder());
        p.addLast(new HttpObjectAggregator(65536));//限制contentLength
        //大文件传输处理
//      p.addLast(new ChunkedWriteHandler());
//      p.addLast(new HttpContentCompressor());
        //跨域配置
        CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
        p.addLast(new CorsHandler(corsConfig));
        p.addLast(new DefaultListenerHandler<HttpRequest>(listener));
    }
项目:DistributedID    文件:HttpServer.java   
@Override
public void init() {
    super.init();
    b.group(bossGroup, workGroup)
            .channel(NioServerSocketChannel.class)
            .option(ChannelOption.SO_KEEPALIVE, false)
            .option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_BACKLOG, 1024)
            .localAddress(new InetSocketAddress(port))
            .childHandler(new ChannelInitializer<SocketChannel>() {

                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(defLoopGroup,
                            new HttpRequestDecoder(),       //请求解码器
                            new HttpObjectAggregator(65536),//将多个消息转换成单一的消息对象
                            new HttpResponseEncoder(),      // 响应编码器
                            new HttpServerHandler(snowFlake)//自定义处理器
                    );
                }
            });

}
项目:ServiceCOLDCache    文件:HttpSnoopServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline p = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    //engine.setUseClientMode(false);
    //p.addLast("ssl", new SslHandler(engine));

    p.addLast("decoder", new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //p.addLast("aggregator", new HttpObjectAggregator(1048576));
    p.addLast("encoder", new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
}
项目:aliyun-oss-hadoop-fs    文件:WebImageViewer.java   
/**
 * Start WebImageViewer.
 * @param fsimage the fsimage to load.
 * @throws IOException if fail to load the fsimage.
 */
@VisibleForTesting
public void initServer(String fsimage)
        throws IOException, InterruptedException {
  final FSImageLoader loader = FSImageLoader.load(fsimage);

  bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
      ChannelPipeline p = ch.pipeline();
      p.addLast(new HttpRequestDecoder(),
        new StringEncoder(),
        new HttpResponseEncoder(),
        new FSImageHandler(loader, allChannels));
    }
  });

  channel = bootstrap.bind(address).sync().channel();
  allChannels.add(channel);

  address = (InetSocketAddress) channel.localAddress();
  LOG.info("WebImageViewer started. Listening on " + address.toString() + ". Press Ctrl+C to stop the viewer.");
}
项目:nettythrift    文件:HttpCodecDispatcher.java   
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof ByteBuf && ctx.channel().isActive()) {
        boolean isHttpRequest = false;
        ByteBuf buffer = (ByteBuf) msg;
        final int len = 11;
        if (buffer.readableBytes() > len) {
            byte[] dst = new byte[len];
            buffer.getBytes(buffer.readerIndex(), dst, 0, len);
            int n = HttpMethodUtil.method(dst);
            isHttpRequest = n > 2;
        }
        if (isHttpRequest) {
            ChannelPipeline cp = ctx.pipeline();
            String currentName = ctx.name();
            cp.addAfter(currentName, "HttpRequestDecoder", new HttpRequestDecoder());
            cp.addAfter("HttpRequestDecoder", "HttpResponseEncoder", new HttpResponseEncoder());
            cp.addAfter("HttpResponseEncoder", "HttpObjectAggregator", new HttpObjectAggregator(512 * 1024));
            ChannelHandler handler = serverDef.httpHandlerFactory.create(serverDef);
            cp.addAfter("HttpObjectAggregator", "HttpThriftBufDecoder", handler);

            cp.remove(currentName);
        }
    }
    ctx.fireChannelRead(msg);
}
项目:study-netty    文件:HttpServer.java   
public void start(int port) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                            @Override
                            public void initChannel(SocketChannel ch) throws Exception {
                                // server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
                                ch.pipeline().addLast(new HttpResponseEncoder());
                                // server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
                                ch.pipeline().addLast(new HttpRequestDecoder());
                                ch.pipeline().addLast(new HttpServerInboundHandler());
                            }
                        }).option(ChannelOption.SO_BACKLOG, 128) 
                .childOption(ChannelOption.SO_KEEPALIVE, true);

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

        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
项目:big-c    文件:WebImageViewer.java   
/**
 * Start WebImageViewer.
 * @param fsimage the fsimage to load.
 * @throws IOException if fail to load the fsimage.
 */
@VisibleForTesting
public void initServer(String fsimage)
        throws IOException, InterruptedException {
  final FSImageLoader loader = FSImageLoader.load(fsimage);

  bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
      ChannelPipeline p = ch.pipeline();
      p.addLast(new HttpRequestDecoder(),
        new StringEncoder(),
        new HttpResponseEncoder(),
        new FSImageHandler(loader, allChannels));
    }
  });

  channel = bootstrap.bind(address).sync().channel();
  allChannels.add(channel);

  address = (InetSocketAddress) channel.localAddress();
  LOG.info("WebImageViewer started. Listening on " + address.toString() + ". Press Ctrl+C to stop the viewer.");
}
项目:shortcircuit-proxy    文件:NettyProxyFrontendInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    /* Netty default: {@code maxInitialLineLength (4096)} */
    int maxInitialLineLength = 4096 * 2;
    /* Netty default: {@code maxHeaderSize (8192)} */
    int maxHeaderSize = 8192 * 2;
    /* Netty default: {@code maxChunkSize (8192)} */
    int maxChunkSize = 8192 * 2;
    int readerIdleTimeSeconds = 0;
    int writerIdleTimeSeconds = 0;
    int allIdleTimeSeconds = 10;
    ch.pipeline().addLast(new LoggingHandler(NettyProxyFrontendHandler.class), //
            new HttpRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize), //
            new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds), //
            new NettyProxyFrontendHandler());
}
项目:riposte    文件:HttpChannelInitializerTest.java   
@Test
public void initChannel_adds_HttpRequestDecoder_as_the_first_inbound_handler_after_sslCtx() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializerNoUtilityHandlers();

    // when
    hci.initChannel(socketChannelMock);

    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, ChannelInboundHandler> firstInboundHandler = findChannelHandler(handlers, ChannelInboundHandler.class);
    Pair<Integer, HttpRequestDecoder> foundHandler = findChannelHandler(handlers, HttpRequestDecoder.class);

    assertThat(firstInboundHandler, notNullValue());
    assertThat(foundHandler, notNullValue());

    // No SSL Context was passed, so HttpRequestDecoder should be the first inbound handler.
    assertThat(foundHandler.getLeft(), is(firstInboundHandler.getLeft()));
    assertThat(foundHandler.getRight(), is(firstInboundHandler.getRight()));
}
项目:JavaAyo    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

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

    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());

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

    pipeline.addLast(new HttpUploadServerHandler());
}
项目:SI    文件:HttpServerInitializer.java   
@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));
}
项目:yar-java    文件:NettyYarServer.java   
public void start(int port) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
                ch.pipeline().addLast("http-aggregator", new HttpObjectAggregator(65536));
                ch.pipeline().addLast("http-encoder", new HttpResponseEncoder());
                ch.pipeline().addLast("http-chunked", new ChunkedWriteHandler());
                ch.pipeline().addLast("serverHandler", new HttpServerHandler());
            }
        }).option(ChannelOption.SO_BACKLOG, 1024).childOption(ChannelOption.SO_KEEPALIVE, true);

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

        f.channel().closeFuture().sync();
    } finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
项目:flashback    文件:ProxyInitializer.java   
@Override
public void initChannel(SocketChannel socketChannel) {
  ChannelPipeline channelPipeline = socketChannel.pipeline();
  channelPipeline.addLast("decoder", new HttpRequestDecoder());
  channelPipeline.addLast("encoder", new HttpResponseEncoder());
  channelPipeline.addLast("idle", new IdleStateHandler(0, 0, _proxyServer.getClientConnectionIdleTimeout()));
  ChannelMediator channelMediator = new ChannelMediator(socketChannel,
      _proxyServer.getProxyModeControllerFactory(),
      _proxyServer.getDownstreamWorkerGroup(),
      _proxyServer.getServerConnectionIdleTimeout(),
      _proxyServer.getAllChannels());
  ClientChannelHandler clientChannelHandler =
      new ClientChannelHandler(channelMediator, _proxyServer.getConnectionFlowRegistry());

  channelPipeline.addLast("handler", clientChannelHandler);
}
项目:intellij-ce-playground    文件:NettyUtil.java   
public static void addHttpServerCodec(@NotNull ChannelPipeline pipeline) {
  pipeline.addLast("httpRequestEncoder", new HttpResponseEncoder());
  // https://jetbrains.zendesk.com/agent/tickets/68315
  pipeline.addLast("httpRequestDecoder", new HttpRequestDecoder(16 * 1024, 16 * 1024, 8192));
  pipeline.addLast("httpObjectAggregator", new HttpObjectAggregator(MAX_CONTENT_LENGTH));
  // could be added earlier if HTTPS
  if (pipeline.get(ChunkedWriteHandler.class) == null) {
    pipeline.addLast("chunkedWriteHandler", new ChunkedWriteHandler());
  }
  pipeline.addLast("corsHandler", new CorsHandlerDoNotUseOwnLogger(CorsConfig
                                                                     .withAnyOrigin()
                                                                     .allowCredentials()
                                                                     .allowNullOrigin()
                                                                     .allowedRequestMethods(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.PATCH)
                                                                     .allowedRequestHeaders("origin", "accept", "authorization", "content-type")
                                                                     .build()));
}
项目:netty-cookbook    文件:PublicHttpServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline p = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    //engine.setUseClientMode(false);
    //p.addLast("ssl", new SslHandler(engine));
    //TODO support SSL HTTP

    p.addLast("decoder", new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //p.addLast("aggregator", new HttpObjectAggregator(1048576));
    p.addLast("encoder", new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpEventProcessingHandler());         
}
项目:netty-cookbook    文件:NettyHttpServerWithCORS.java   
public static void main(String[] args) {
    String ip = "127.0.0.1";
    int port = 8080;
    ChannelInitializer<SocketChannel> channelInit = new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();

            CorsConfig corsConfig = CorsConfig.withAnyOrigin()
                    .allowedRequestHeaders("content-type","accept","MyCustomHeader")
                    .allowedRequestMethods(PUT,POST,GET,DELETE)
                    .build();

            p.addLast(new HttpResponseEncoder());
            p.addLast(new HttpRequestDecoder());
            p.addLast(new HttpObjectAggregator(65536));
            p.addLast(new ChunkedWriteHandler());
            p.addLast(new CorsHandler(corsConfig));
            p.addLast(new SimpleCORSHandler());
        }
    };
    NettyServerUtil.newHttpServerBootstrap(ip, port, channelInit);
}
项目:netty-http-server    文件:ServerConfig.java   
@Bean(name = "channelInitializer")
public ChannelInitializer<SocketChannel> initializerFactory(final ApplicationContext contxt) {
    return new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            SimpleChannelInboundHandler<?> channelInboundHandler = contxt.getBean(NettyHttpChannelHandler.class);
            ChannelPipeline pipeline = ch.pipeline();
            // HTTP
            pipeline.addLast(new HttpRequestDecoder());
            pipeline.addLast(new HttpResponseEncoder());
            pipeline.addLast(new HttpContentCompressor());
            pipeline.addLast(new ChunkedWriteHandler());
            // 设置处理的Handler
            pipeline.addLast(channelInboundHandler);
        }
    };
}
项目:netty4.0.27Learn    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();

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

    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());

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

    pipeline.addLast(new HttpUploadServerHandler());
}
项目:netty4.0.27Learn    文件:HttpRequestDecoderBenchmark.java   
private static void testDecodeWholeRequestInMultipleSteps(byte[] content, int fragmentSize) {
    final EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());

    final int headerLength = content.length - CONTENT_LENGTH;

    // split up the header
    for (int a = 0; a < headerLength;) {
        int amount = fragmentSize;
        if (a + amount > headerLength) {
            amount = headerLength -  a;
        }

        // if header is done it should produce a HttpRequest
        channel.writeInbound(Unpooled.wrappedBuffer(content, a, amount));
        a += amount;
    }

    for (int i = CONTENT_LENGTH; i > 0; i --) {
        // Should produce HttpContent
        channel.writeInbound(Unpooled.wrappedBuffer(content, content.length - i, 1));
    }
}
项目:netty4.0.27Learn    文件:WebSocketServerProtocolHandlerTest.java   
@Test
public void testHandleTextFrame() {
    CustomTextFrameHandler customTextFrameHandler = new CustomTextFrameHandler();
    EmbeddedChannel ch = createChannel(customTextFrameHandler);
    writeUpgradeRequest(ch);

    if (ch.pipeline().context(HttpRequestDecoder.class) != null) {
        // Removing the HttpRequestDecoder because we are writing a TextWebSocketFrame and thus
        // decoding is not neccessary.
        ch.pipeline().remove(HttpRequestDecoder.class);
    }

    ch.writeInbound(new TextWebSocketFrame("payload"));

    assertEquals("processed: payload", customTextFrameHandler.getContent());
}
项目:scratch_zookeeper_netty    文件:HttpStaticFileServerInitializer.java   
@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());
}
项目:gale    文件:GaleServerInitializer.java   
@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);

}
项目:netty.book.kor    文件:ApiServerInitializer.java   
@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());
}
项目:activemq-artemis    文件:ProtocolHandler.java   
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);
}
项目:SI    文件:HttpServerInitializer.java   
@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));
}
项目:jaxrs-engine    文件:MicroServicesServerSC.java   
public void initChannel(SocketChannel channel) {
    ChannelPipeline pipeline = channel.pipeline();
    //        pipeline.addLast("tracker", connectionTracker);
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(Integer.MAX_VALUE));  //TODO: fix
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("compressor", new HttpContentCompressor());

    HttpResourceHandler resourceHandler = new HttpResourceHandler(dataHolder.getHttpServices(),
            new ArrayList<HandlerHook>(), null, null);
    pipeline.addLast(new DefaultEventExecutorGroup(200),
            "router", new RequestRouter(resourceHandler, 0)); //TODO: remove limit

    //TODO: see what can be done
    /*if (pipelineModifier != null) {
        pipelineModifier.apply(pipeline);
    }*/
}
项目:camunda-bpm-workbench    文件:WebsocketServer.java   
public ChannelFuture run() {

    final ServerBootstrap httpServerBootstrap = new ServerBootstrap();
    httpServerBootstrap.group(bossGroup, workerGroup)
      .channel(NioServerSocketChannel.class)
      .localAddress(new InetSocketAddress(port))
      .childHandler(new ChannelInitializer<SocketChannel>() {

        public void initChannel(final SocketChannel ch) throws Exception {
          ch.pipeline().addLast(
            new HttpResponseEncoder(),
            new HttpRequestDecoder(),
            new HttpObjectAggregator(65536),
            new WebSocketServerProtocolHandler("/debug-session"),
            new DebugProtocolHandler(debugWebsocketConfiguration));
        }

    });

    LOGG.log(Level.INFO, "starting camunda BPM debug HTTP websocket interface on port "+port+".");

    return httpServerBootstrap.bind(port);


  }
项目:tajo    文件:HttpDataServerChannelInitializer.java   
@Override
 protected void initChannel(Channel 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("deflater", new HttpContentCompressor());
   pipeline.addLast("handler", new HttpDataServerHandler(userName, appId));
 }
项目:tajo    文件:HttpFileServerChannelInitializer.java   
@Override
protected void initChannel(Channel channel) throws Exception {
  ChannelPipeline pipeline = channel.pipeline();

  // Uncomment the following lines 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(65536));
  pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

  pipeline.addLast("handler", new HttpFileServerHandler());
}
项目:netty4study    文件:HttpUploadServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = ch.pipeline();

    if (HttpUploadServer.isSSL) {
        SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);
        pipeline.addLast("ssl", new SslHandler(engine));
    }

    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());

    // Remove the following line if you don't want automatic content
    // compression.
    pipeline.addLast("deflater", new HttpContentCompressor());

    pipeline.addLast("handler", new HttpUploadServerHandler());
}
项目:netty4study    文件:HttpSnoopServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline p = ch.pipeline();

    // Uncomment the following line if you want HTTPS
    //SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
    //engine.setUseClientMode(false);
    //p.addLast("ssl", new SslHandler(engine));

    p.addLast("decoder", new HttpRequestDecoder());
    // Uncomment the following line if you don't want to handle HttpChunks.
    //p.addLast("aggregator", new HttpObjectAggregator(1048576));
    p.addLast("encoder", new HttpResponseEncoder());
    // Remove the following line if you don't want automatic content compression.
    //p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
}
项目:netty4study    文件:HttpStaticFileServerInitializer.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
    // Create a default pipeline implementation.
    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("decoder", new HttpRequestDecoder());
    pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

    pipeline.addLast("handler", new HttpStaticFileServerHandler(true)); // Specify false if SSL.
}
项目:netty4study    文件:WebSocketServerProtocolHandlerTest.java   
@Test
public void testHandleTextFrame() {
    CustomTextFrameHandler customTextFrameHandler = new CustomTextFrameHandler();
    EmbeddedChannel ch = createChannel(customTextFrameHandler);
    writeUpgradeRequest(ch);

    if (ch.pipeline().context(HttpRequestDecoder.class) != null) {
        // Removing the HttpRequestDecoder because we are writing a TextWebSocketFrame and thus
        // decoding is not neccessary.
        ch.pipeline().remove(HttpRequestDecoder.class);
    }

    ch.writeInbound(new TextWebSocketFrame("payload"));

    assertEquals("processed: payload", customTextFrameHandler.getContent());
}
项目:baiji4j    文件:HttpServer.java   
public void startWithoutWaitingForShutdown() throws Exception {
    _bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
                    .addLast("logger", new LoggingHandler())
                    .addLast("decoder", new HttpRequestDecoder())
                    .addLast("aggregator", new HttpObjectAggregator(_maxContentLength))
                    .addLast("encoder", new HttpResponseEncoder());
            addRouterToPipeline(ch);
        }
    });
    Channel channel = _bootstrap.bind().sync().channel();
    _logger.info("Started netty http module at port: " + channel.localAddress());
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                stop();
            } catch (InterruptedException e) {
                _logger.error("Error while shutting down.", e);
            }
        }
    }));
    _serverShutdownFuture = channel.closeFuture();
}
项目:detective    文件:HttpServerTask.java   
@Override
public void initChannel(SocketChannel ch) throws Exception {
  // Create a default pipeline implementation.
  ChannelPipeline p = ch.pipeline();

  // Uncomment the following line if you want HTTPS
  // SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
  // engine.setUseClientMode(false);
  // p.addLast("ssl", new SslHandler(engine));

  p.addLast("decoder", new HttpRequestDecoder());
  // Uncomment the following line if you don't want to handle HttpChunks.
  // p.addLast("aggregator", new HttpObjectAggregator(1048576));
  p.addLast("encoder", new HttpResponseEncoder());
  // Remove the following line if you don't want automatic content compression.
  // p.addLast("deflater", new HttpContentCompressor());
  p.addLast("handler", new HttpSnoopServerHandler());
}
项目:MTBT    文件:MysqlInitializer.java   
public void initChannel(SocketChannel ch)
{
  String thrName = Thread.currentThread().getName() + ": ";
  _LOG.debug(thrName + "Initializing SocketChannel...");

  ChannelPipeline p = ch.pipeline();

  //HttpMessage encoder/decoder
  p.addLast("httpDecoder", new HttpRequestDecoder());
  p.addLast("httpAggr", new HttpObjectAggregator(_httpBufferSize));
  p.addLast("httpEncoder", new HttpResponseEncoder());

  //MysqlQuery encoder/decoder
  p.addLast("mysqlDecoder", new MysqlQueryDecoder());
  p.addLast("mysqlEncoder", new MysqlQueryEncoder());

  //MysqlQuery handler
  p.addLast("mysqlHandler", new MysqlQueryHandler(_connPool));
}
项目:MTBT    文件:RocksdbInitializer.java   
public void initChannel(SocketChannel ch)
{
  String thrName = Thread.currentThread().getName() + ": ";
  m_log.debug(thrName + "Initializing SocketChannel...");

  ChannelPipeline p = ch.pipeline();

  //HttpMessage encoder/decoder
  p.addLast("httpDecoder", new HttpRequestDecoder());
  p.addLast("httpAggr", new HttpObjectAggregator(_httpBufferSize));
  p.addLast("httpEncoder", new HttpResponseEncoder());

  //Rocksdb encoder/decoder
  p.addLast("rocksdbDecoder", new RocksdbQueryDecoder());
  p.addLast("rocksdbEncoder", new RocksdbQueryEncoder());

  //Rocksdb query handler
  p.addLast("rocksdbHandler", new RocksdbQueryHandler(m_connPool));
}