org.jboss.netty.handler.codec.http.HttpResponseEncoder Java Examples

The following examples show how to use org.jboss.netty.handler.codec.http.HttpResponseEncoder. 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: FileServerPipelineFactory.java    From netty-file-parent with Apache License 2.0 6 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
	ChannelPipeline pipeline = Channels.pipeline();
	//它负责把字节解码成Http请求。
	pipeline.addLast("decoder", new HttpRequestDecoder());
	//当Server处理完消息后,需要向Client发送响应。那么需要把响应编码成字节,再发送出去。故添加HttpResponseEncoder处理器。
	pipeline.addLast("encoder", new HttpResponseEncoder());
	//它负责把多个HttpMessage组装成一个完整的Http请求或者响应。到底是组装成请求还是响应,则取决于它所处理的内容是请求的内容,还是响应的内容。
	//这其实可以通过Inbound和Outbound来判断,对于Server端而言,在Inbound 端接收请求,在Outbound端返回响应。
	//如果Server向Client返回的数据指定的传输编码是 chunked。则,Server不需要知道发送给Client的数据总长度是多少,它是通过分块发送的,参考分块传输编码
	//pipeline.addLast("http-aggregator", new HttpObjectAggregator(65536));
	pipeline.addLast("deflater", new HttpContentCompressor());
	//该通道处理器主要是为了处理大文件传输的情形。大文件传输时,需要复杂的状态管理,而ChunkedWriteHandler实现这个功能。
	pipeline.addLast("http-chunked", new ChunkedWriteHandler());
	//自定义的通道处理器,其目的是实现文件服务器的业务逻辑。
	pipeline.addLast("handler", new FileServerHandler());
	return pipeline;
}
 
Example #2
Source File: ShuffleHandler.java    From tez with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  if (sslFactory != null) {
    pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
  }
  pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", SHUFFLE);
  pipeline.addLast("idle", idleStateHandler);
  pipeline.addLast(TIMEOUT_HANDLER, new TimeoutHandler());
  return pipeline;
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
Example #3
Source File: WebSocketServerPipelineFactory.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    if ( ssl ) {
        SSLEngine sslEngine = WebSocketSslContextFactory.getServerContext().createSSLEngine();
        sslEngine.setUseClientMode( false );
        pipeline.addLast( "ssl", new SslHandler( sslEngine ) );
    }
    pipeline.addLast( "decoder", new HttpRequestDecoder() );
    pipeline.addLast( "aggregator", new HttpChunkAggregator( 65536 ) );
    pipeline.addLast( "encoder", new HttpResponseEncoder() );
    pipeline.addLast( "execution", executionHandler );
    pipeline.addLast( "handler", new WebSocketChannelHandler( emf, smf, management, securityManager, ssl ) );
    return pipeline;
}
 
Example #4
Source File: HttpServerPipelineFactory.java    From restcommander with Apache License 2.0 6 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {

        Integer max = Integer.valueOf(Play.configuration.getProperty("play.netty.maxContentLength", "-1"));
           
        ChannelPipeline pipeline = pipeline();
        PlayHandler playHandler = new PlayHandler();
        
        pipeline.addLast("flashPolicy", new FlashPolicyHandler()); 
        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("aggregator", new StreamChunkAggregator(max));
        pipeline.addLast("encoder", new HttpResponseEncoder());
        pipeline.addLast("chunkedWriter", playHandler.chunkedWriteHandler);
        pipeline.addLast("handler", playHandler);

        return pipeline;
    }
 
Example #5
Source File: HttpDataServerPipelineFactory.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
  // Create a default pipeline implementation.
  ChannelPipeline pipeline = 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));
  return pipeline;
}
 
Example #6
Source File: HttpDataServerPipelineFactory.java    From incubator-tajo with Apache License 2.0 6 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
  // Create a default pipeline implementation.
  ChannelPipeline pipeline = 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(ret));
  return pipeline;
}
 
Example #7
Source File: TestDelegationTokenRemoteFetcher.java    From big-c with Apache License 2.0 6 votes vote down vote up
private ServerBootstrap startHttpServer(int port,
    final Token<DelegationTokenIdentifier> token, final URI url) {
  ServerBootstrap bootstrap = new ServerBootstrap(
      new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
          Executors.newCachedThreadPool()));

  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(new HttpRequestDecoder(),
          new HttpChunkAggregator(65536), new HttpResponseEncoder(),
          new CredentialsLogicHandler(token, url.toString()));
    }
  });
  bootstrap.bind(new InetSocketAddress("localhost", port));
  return bootstrap;
}
 
Example #8
Source File: ShuffleHandler.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  if (sslFactory != null) {
    pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
  }
  pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", SHUFFLE);
  return pipeline;
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
Example #9
Source File: TestDelegationTokenRemoteFetcher.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private ServerBootstrap startHttpServer(int port,
    final Token<DelegationTokenIdentifier> token, final URI url) {
  ServerBootstrap bootstrap = new ServerBootstrap(
      new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
          Executors.newCachedThreadPool()));

  bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    @Override
    public ChannelPipeline getPipeline() throws Exception {
      return Channels.pipeline(new HttpRequestDecoder(),
          new HttpChunkAggregator(65536), new HttpResponseEncoder(),
          new CredentialsLogicHandler(token, url.toString()));
    }
  });
  bootstrap.bind(new InetSocketAddress("localhost", port));
  return bootstrap;
}
 
Example #10
Source File: ShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  if (sslFactory != null) {
    pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
  }
  pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", SHUFFLE);
  return pipeline;
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
Example #11
Source File: HttpServer.java    From feeyo-hlsserver with Apache License 2.0 6 votes vote down vote up
public void startup(int port) {		
	
	final int maxContentLength = 1024 * 1024 * 1024;
	
	bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(bossExecutor,  workerExecutor));

	bootstrap.setOption("connectTimeoutMillis", 10000);
	bootstrap.setOption("reuseAddress", true); 	// kernel optimization
	bootstrap.setOption("keepAlive", true); 	// for mobiles & our
	bootstrap.setOption("tcpNoDelay", true); 	// better latency over
	
	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		@Override
		public ChannelPipeline getPipeline() throws Exception {
			ChannelPipeline p = Channels.pipeline();
			p.addLast("http-encoder", new HttpResponseEncoder());
			p.addLast("http-decoder", new HttpRequestDecoder());
			p.addLast("http-aggregator", new HttpChunkAggregator( maxContentLength ));
			p.addLast("server-handler", new HttpServerRequestHandler());
			return p;
		}
	});
	channel = bootstrap.bind(new InetSocketAddress(port));

}
 
Example #12
Source File: HttpServer.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("deflater", new HttpContentCompressor());
    pipeline.addLast("handler", new HttpServerHandler());
    return pipeline;
}
 
Example #13
Source File: SslHttpServerPipelineFactory.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {

        Integer max = Integer.valueOf(Play.configuration.getProperty("play.netty.maxContentLength", "-1"));
        String mode = Play.configuration.getProperty("play.netty.clientAuth", "none");

        ChannelPipeline pipeline = pipeline();

        // Add SSL handler first to encrypt and decrypt everything.
        SSLEngine engine = SslHttpServerContextFactory.getServerContext().createSSLEngine();
        engine.setUseClientMode(false);
        
        if ("want".equalsIgnoreCase(mode)) {
            engine.setWantClientAuth(true);
        } else if ("need".equalsIgnoreCase(mode)) {
            engine.setNeedClientAuth(true);
        }
        
        engine.setEnableSessionCreation(true);

        pipeline.addLast("flashPolicy", new FlashPolicyHandler());
        pipeline.addLast("ssl", new SslHandler(engine));
        pipeline.addLast("decoder", new HttpRequestDecoder());
        pipeline.addLast("aggregator", new StreamChunkAggregator(max));
        pipeline.addLast("encoder", new HttpResponseEncoder());
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());

        pipeline.addLast("handler", new SslPlayHandler());

        return pipeline;
    }
 
Example #14
Source File: TaskTracker.java    From RDFS with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
  return Channels.pipeline(
    new HttpRequestDecoder(),
    new HttpChunkAggregator(1 << 16),
    new HttpResponseEncoder(),
    new ChunkedWriteHandler(),
    shuffleHandler);
}
 
Example #15
Source File: CommonHttpPipeline.java    From zuul-netty with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();

    //offload from worker threads
    pipeline.addLast("app-execution-handler", APP_EXECUTION_HANDLER);

    //httpfu io
    pipeline.addLast("socket-suspension", new SocketSuspensionHandler());
    pipeline.addLast("idle-detection", idleStateHandler);
    pipeline.addLast("http-decoder", new HttpRequestDecoder());
    pipeline.addLast("http-encoder", new HttpResponseEncoder());

    //httpfu
    pipeline.addLast("http-deflater", new HttpContentCompressor());
    pipeline.addLast("edge-timer", SERVER_TIMING_HANDLER);
    pipeline.addLast("http-keep-alive", KEEP_ALIVE_HANDLER);
    pipeline.addLast("idle-watchdog", IDLE_CHANNEL_WATCHDOG_HANDLER);

    //response handlers
    addZuulPostFilters(pipeline, postFilters);

    pipeline.addLast("app-http-response-logger", HTTP_RESPONSE_LOGGER);

    //request handlers
    addZuulPreFilters(pipeline, preFilters);

    //proxy
    pipeline.addLast("proxy", new HttpProxyHandler(outboundConnectionPool, IS_REQUEST_CHUNKED_ENABLED));

    return pipeline;
}
 
Example #16
Source File: ShuffleHandler.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public ChannelPipeline getPipeline() throws Exception {
  ChannelPipeline pipeline = Channels.pipeline();
  pipeline.addLast("decoder", new HttpRequestDecoder());
  pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
  pipeline.addLast("encoder", new HttpResponseEncoder());
  pipeline.addLast("chunking", new ChunkedWriteHandler());
  pipeline.addLast("shuffle", SHUFFLE);
  return pipeline;
  // TODO factor security manager into pipeline
  // TODO factor out encode/decode to permit binary shuffle
  // TODO factor out decode of index to permit alt. models
}
 
Example #17
Source File: HttpServerPipelineFactory.java    From netty-servlet with Apache License 2.0 4 votes vote down vote up
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();

    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("excution", executionHandler);

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