@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()); }
@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()); }
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; }
@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)); }
@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)//自定义处理器 ); } }); }
@Override protected ChannelHandler newNonSslHandler(ChannelHandlerContext context) { return new ChannelInboundHandlerAdapter() { private HttpResponseEncoder encoder = new HttpResponseEncoder(); @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { LOG.trace("Received non-SSL request, returning redirect"); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.MOVED_PERMANENTLY, Unpooled.EMPTY_BUFFER); response.headers().set(Names.LOCATION, redirectAddress); LOG.trace(Constants.LOG_RETURNING_RESPONSE, response); encoder.write(ctx, response, ctx.voidPromise()); ctx.flush(); } }; }
@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()); }
/** * 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."); }
@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); }
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(); } }
@Test public void initChannel_adds_HttpResponseEncoder_as_the_last_outbound_handler_before_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, HttpResponseEncoder> foundHandler = findChannelHandler(handlers, HttpResponseEncoder.class); assertThat(foundHandler, notNullValue()); // No SSL Context was passed, so HttpResponseEncoder should be the handler at index 0 in the list (corresponding to the "last" outbound handler since they go in reverse order). assertThat(foundHandler.getLeft(), is(0)); }
@Test public void initChannel_adds_HttpContentCompressor_before_HttpResponseEncoder_for_outbound_handler() { // 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, HttpContentCompressor> httpContentCompressor = findChannelHandler(handlers, HttpContentCompressor.class); Pair<Integer, HttpResponseEncoder> httpResponseEncoder = findChannelHandler(handlers, HttpResponseEncoder.class); assertThat(httpContentCompressor, notNullValue()); assertThat(httpResponseEncoder, notNullValue()); // HttpContentCompressor's index should be later than HttpResponseEncoder's index to verify that it comes BEFORE HttpResponseEncoder on the OUTBOUND handlers // (since the outbound handlers are processed in reverse order). assertThat(httpContentCompressor.getLeft(), is(greaterThan(httpResponseEncoder.getLeft()))); }
@Test public void prematureCancel() throws Exception { DirectProcessor<Void> signal = DirectProcessor.create(); NettyContext x = TcpServer.create("localhost", 0) .newHandler((in, out) -> { signal.onComplete(); return out.context(c -> c.addHandlerFirst( new HttpResponseEncoder())) .sendObject(Mono.delay(Duration .ofSeconds(2)) .map(t -> new DefaultFullHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus .PROCESSING))) .neverComplete(); }) .block(Duration.ofSeconds(30)); StepVerifier.create(createHttpClientForContext(x) .get("/") .timeout(signal) ) .verifyError(TimeoutException.class); // Thread.sleep(1000000); }
@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()); }
@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)); }
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(); } }
@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); }
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())); }
@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()); }
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); }
@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); } }; }
@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()); }
@Override public void initChannel(SocketChannel ch) throws Exception { if (log.isDebugEnabled()) { log.debug("Initializing source channel pipeline"); } ChannelPipeline pipeline = ch.pipeline(); if (sslConfig != null) { pipeline.addLast(Constants.SSL_HANDLER, new SslHandler(new SSLHandlerFactory(sslConfig).build())); } pipeline.addLast("encoder", new HttpResponseEncoder()); configureHTTPPipeline(pipeline); if (socketIdleTimeout > 0) { pipeline.addBefore( Constants.HTTP_SOURCE_HANDLER, Constants.IDLE_STATE_HANDLER, new IdleStateHandler(socketIdleTimeout, socketIdleTimeout, socketIdleTimeout, TimeUnit.MILLISECONDS)); } }
@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); }
@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()); }
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); }
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); }*/ }
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); }
@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)); }
@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()); }
@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()); }
@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. }
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(); }
@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()); }
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)); }