io.netty.handler.codec.http.HttpRequestDecoder Java Examples

The following examples show how to use io.netty.handler.codec.http.HttpRequestDecoder. 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: NettyHttpServerInitializer.java    From piranha with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
/**
 * Initialize the channel.
 *
 * @param channel the channel.
 */
@Override
public void initChannel(SocketChannel channel) {
    ChannelPipeline pipeline = channel.pipeline();
    if (ssl) {
        try {
            SSLContext sslContext = SSLContext.getDefault();
            SSLEngine sslEngine = sslContext.createSSLEngine();
            sslEngine.setUseClientMode(false);
            pipeline.addLast(new SslHandler(sslEngine));
        } catch (NoSuchAlgorithmException e) {
            if (LOGGER.isLoggable(SEVERE)) {
                LOGGER.log(WARNING, "Unable to match SSL algorithm", e);
            }
        }
    }
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpObjectAggregator(10*1024*1024));
    pipeline.addLast(new NettyHttpServerHandler(httpServerProcessor));
}
 
Example #2
Source File: HttpUploadServerInitializer.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(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());
}
 
Example #3
Source File: HttpUploadServerInitializer.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(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());
}
 
Example #4
Source File: IrisUpnpServer.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private void handleRequest(@Nullable ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
   EmbeddedChannel http = new EmbeddedChannel(new HttpRequestDecoder());

   try {
      http.writeInbound(Unpooled.unreleasableBuffer(packet.content()));
      http.finish();

      while (true) {
         Object result = http.readInbound();
         if (result == null) {
            break;
         }

         if (result instanceof HttpRequest) {
            HttpRequest req = (HttpRequest)result;
            switch (req.getMethod().name()) {
            case "NOTIFY": handleUpnpNotify(packet, req); break;
            case "M-SEARCH": handleUpnpMsearch(packet, req); break;
            default: log.debug("unknown upnp message: {}", req.getMethod()); break;
            }
         } 
      }
   } finally {
      http.finishAndReleaseAll();
   }
}
 
Example #5
Source File: Ipcd10ChannelInitializer.java    From arcusipcd with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	
	ChannelPipeline pipeline = ch.pipeline();
	
	if (serverTlsContext != null && serverTlsContext.useTls()) {
		SSLEngine engine = serverTlsContext.getContext().createSSLEngine();
		engine.setUseClientMode(false);
		pipeline.addLast("tls", new SslHandler(engine));
	}
	
	pipeline.addLast("encoder", new HttpResponseEncoder());
       pipeline.addLast("decoder", new HttpRequestDecoder());
       pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
       pipeline.addLast("handler", new Ipcd10WebSocketServerHandler(false));
}
 
Example #6
Source File: HttpRequestDecoderBenchmark.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example #7
Source File: WebSocketServerProtocolHandlerTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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 necessary.
        ch.pipeline().remove(HttpRequestDecoder.class);
    }

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

    assertEquals("processed: payload", customTextFrameHandler.getContent());
}
 
Example #8
Source File: HttpRequestDecoderBenchmark.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example #9
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 #10
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 #11
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 #12
Source File: HttpServerInitHandler.java    From util4j with Apache License 2.0 6 votes vote down vote up
@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));
		if(unPoolMsg)
		{
			p.addLast(new DefaultListenerHandler<HttpRequest>(new HttpListenerProxy(listener)));
		}else
		{
			p.addLast(new DefaultListenerHandler<HttpRequest>(listener));
		}
	}
 
Example #13
Source File: ProtocolHandler.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #14
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 #15
Source File: ApiServerInitializer.java    From netty.book.kor with MIT License 6 votes vote down vote up
@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());
}
 
Example #16
Source File: ProxyInitializer.java    From flashback with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);
}
 
Example #17
Source File: HttpServerInitializer.java    From SI with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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));
}
 
Example #18
Source File: TestServer.java    From timely with Apache License 2.0 6 votes vote down vote up
@Override
protected ChannelHandler setupHttpChannel(Configuration config, SslContext sslCtx) {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", new NonSslRedirectHandler(config.getHttp(), sslCtx));
            ch.pipeline().addLast("decompressor", new HttpContentDecompressor());
            ch.pipeline().addLast("decoder", new HttpRequestDecoder());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
            ch.pipeline().addLast("queryDecoder",
                    new timely.netty.http.HttpRequestDecoder(config.getSecurity(), config.getHttp()));
            ch.pipeline().addLast("capture", httpRequests);
        }
    };
}
 
Example #19
Source File: HttpCodecDispatcher.java    From nettythrift with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #20
Source File: HttpServer.java    From DistributedID with Apache License 2.0 6 votes vote down vote up
@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)//自定义处理器
                    );
                }
            });

}
 
Example #21
Source File: HttpUploadServerInitializer.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(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());
}
 
Example #22
Source File: HttpPipelineHandlerTest.java    From styx with Apache License 2.0 5 votes vote down vote up
private static EmbeddedChannel buildEmbeddedChannel(ChannelHandler... lastHandlers) {
    Iterable<ChannelHandler> commonHandlers = asList(
            new HttpRequestDecoder(),
            new HttpObjectAggregator(6000),
            new NettyToStyxRequestDecoder.Builder().build());

    return new EmbeddedChannel(toArray(concat(commonHandlers, asList(lastHandlers)), ChannelHandler.class));
}
 
Example #23
Source File: HttpProtocolHandler.java    From hasor with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelHandler[] channelHandler(Connector connector, AppContext appContext) {
    RsfContext rsfContext = appContext.getInstance(RsfContext.class);
    RsfDuplexHandler inHandler = new RsfDuplexHandler(  //
            new HttpRequestDecoder(),   //
            new HttpResponseEncoder()   //
    );
    return new ChannelHandler[] {       //
            inHandler,                  //
            new HttpCoder(rsfContext, connector, this.httpHandler)//
    };
}
 
Example #24
Source File: PortUnificationServerHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private void switchToHttp(ChannelHandlerContext ctx) {
    ChannelPipeline p = ctx.pipeline();
    p.addLast("decoder", new HttpRequestDecoder());
    p.addLast("encoder", new HttpResponseEncoder());
    p.addLast("deflater", new HttpContentCompressor());
    p.addLast("handler", new HttpSnoopServerHandler());
    p.remove(this);
}
 
Example #25
Source File: HttpCorsServerInitializer.java    From tools-journey with Apache License 2.0 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: ServerInitializer.java    From HAP-Java with MIT License 5 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) throws Exception {
  ChannelPipeline pipeline = ch.pipeline();
  pipeline.addLast(new LoggingHandler());
  pipeline.addLast(HTTP_HANDLER_NAME, new HttpResponseEncoderAggregate());
  pipeline.addLast(new HttpRequestDecoder());
  pipeline.addLast(new HttpObjectAggregator(MAX_POST));
  pipeline.addLast(blockingExecutorGroup, new AccessoryHandler(homekit));
  allChannels.add(ch);
}
 
Example #27
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 #28
Source File: SofaNettyJaxrsServer.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
private void setupHandlers(SocketChannel ch, RequestDispatcher dispatcher,
                           RestEasyHttpRequestDecoder.Protocol protocol) {
    ChannelPipeline channelPipeline = ch.pipeline();
    channelPipeline.addLast(channelHandlers.toArray(new ChannelHandler[channelHandlers.size()]));
    channelPipeline.addLast(new HttpRequestDecoder());
    channelPipeline.addLast(new HttpObjectAggregator(maxRequestSize));
    channelPipeline.addLast(new HttpResponseEncoder());
    channelPipeline.addLast(httpChannelHandlers.toArray(new ChannelHandler[httpChannelHandlers.size()]));
    channelPipeline.addLast(new RestEasyHttpRequestDecoder(dispatcher.getDispatcher(), root, protocol));
    channelPipeline.addLast(new RestEasyHttpResponseEncoder());
    channelPipeline.addLast(eventExecutor, new SofaRestRequestHandler(dispatcher)); // CHANGE: 用sofa的处理类
}
 
Example #29
Source File: HttpPipelineInitializer.java    From netty-learning with MIT License 5 votes vote down vote up
@Override
protected void initChannel(Channel ch) throws Exception {
    ch.pipeline()
            .addLast("decoder", new HttpRequestDecoder())
            .addLast("encoder", new HttpResponseEncoder())
    ;
}
 
Example #30
Source File: HttpSnoopServerInitializer.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
@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 HttpSnoopServerHandler());
}