当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequestDecoder类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.HttpRequestDecoder的典型用法代码示例。如果您正苦于以下问题:Java HttpRequestDecoder类的具体用法?Java HttpRequestDecoder怎么用?Java HttpRequestDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequestDecoder类属于io.netty.handler.codec.http包,在下文中一共展示了HttpRequestDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appendHttpPipeline

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
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;
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:24,代码来源:HttpChannelInitializer.java

示例2: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:HttpServerSharedInitializerFactory.java

示例3: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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());
}
 
开发者ID:aerogear,项目名称:push-network-proxies,代码行数:17,代码来源:MockingFCMServerInitializer.java

示例4: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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));
	}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:19,代码来源:HttpServerInitHandler.java

示例5: init

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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)//自定义处理器
                    );
                }
            });

}
 
开发者ID:beyondfengyu,项目名称:DistributedID,代码行数:24,代码来源:HttpServer.java

示例6: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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());
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:19,代码来源:HttpSnoopServerInitializer.java

示例7: initServer

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
/**
 * 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.");
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:28,代码来源:WebImageViewer.java

示例8: channelRead

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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);
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:27,代码来源:HttpCodecDispatcher.java

示例9: start

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
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();
    }
}
 
开发者ID:janzolau1987,项目名称:study-netty,代码行数:27,代码来源:HttpServer.java

示例10: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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());
}
 
开发者ID:ganskef,项目名称:shortcircuit-proxy,代码行数:17,代码来源:NettyProxyFrontendInitializer.java

示例11: initChannel_adds_HttpRequestDecoder_as_the_first_inbound_handler_after_sslCtx

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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()));
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:23,代码来源:HttpChannelInitializerTest.java

示例12: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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());
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:17,代码来源:HttpUploadServerInitializer.java

示例13: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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));
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:22,代码来源:HttpServerInitializer.java

示例14: start

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
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();
    }
}
 
开发者ID:weibocom,项目名称:yar-java,代码行数:25,代码来源:NettyYarServer.java

示例15: initChannel

import io.netty.handler.codec.http.HttpRequestDecoder; //导入依赖的package包/类
@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);
}
 
开发者ID:linkedin,项目名称:flashback,代码行数:17,代码来源:ProxyInitializer.java


注:本文中的io.netty.handler.codec.http.HttpRequestDecoder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。