io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler Java Examples

The following examples show how to use io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler. 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: WebSocketServerInitializer.java    From litchi 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 HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new IdleStateHandler(0, 0, 60));
    pipeline.addLast(new WebSocketServerProtocolHandler(WEB_SOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketHandler(litchi));

    for (ChannelHandler handler : handlers) {
        pipeline.addLast(handler);
    }
}
 
Example #2
Source File: SeleniumHttpInitializer.java    From selenium with Apache License 2.0 6 votes vote down vote up
@Override
protected void initChannel(SocketChannel ch) {
  if (sslCtx != null) {
    ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
  }
  ch.pipeline().addLast("codec", new HttpServerCodec());
  ch.pipeline().addLast("keep-alive", new HttpServerKeepAliveHandler());
  ch.pipeline().addLast("chunked-write", new ChunkedWriteHandler());

  // Websocket magic
  ch.pipeline().addLast("ws-compression", new WebSocketServerCompressionHandler());
  ch.pipeline().addLast("ws-protocol", new WebSocketUpgradeHandler(KEY, webSocketHandler));
  ch.pipeline().addLast("netty-to-se-messages", new MessageInboundConverter());
  ch.pipeline().addLast("se-to-netty-messages", new MessageOutboundConverter());
  ch.pipeline().addLast("se-websocket-handler", new WebSocketMessageHandler(KEY));

  // Regular HTTP magic
  ch.pipeline().addLast("se-request", new RequestConverter());
  ch.pipeline().addLast("se-response", new ResponseConverter());
  ch.pipeline().addLast("se-handler", new SeleniumHandler(seleniumHandler));
}
 
Example #3
Source File: WebSocketRemoteServerInitializer.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, subProtocols, true));
    pipeline.addLast(new WebSocketRemoteServerFrameHandler());
}
 
Example #4
Source File: WebSocketServerInitializer.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    pipeline.addLast(new WebSocketFrameHandler());
}
 
Example #5
Source File: LauncherNettyServer.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
public LauncherNettyServer(LaunchServer server) {
    LaunchServerConfig.NettyConfig config = server.config.netty;
    NettyObjectFactory.setUsingEpoll(config.performance.usingEpoll);
    if (config.performance.usingEpoll) {
        LogHelper.debug("Netty: Epoll enabled");
    }
    if (config.performance.usingEpoll && !Epoll.isAvailable()) {
        LogHelper.error("Epoll is not available: (netty,perfomance.usingEpoll configured wrongly)", Epoll.unavailabilityCause());
    }
    bossGroup = NettyObjectFactory.newEventLoopGroup(config.performance.bossThread);
    workerGroup = NettyObjectFactory.newEventLoopGroup(config.performance.workerThread);
    serverBootstrap = new ServerBootstrap();
    service = new WebSocketService(new DefaultChannelGroup(GlobalEventExecutor.INSTANCE), server);
    serverBootstrap.group(bossGroup, workerGroup)
            .channelFactory(NettyObjectFactory.getServerSocketChannelFactory())
            .handler(new LoggingHandler(config.logLevel))
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) {
                    ChannelPipeline pipeline = ch.pipeline();
                    NettyConnectContext context = new NettyConnectContext();
                    //p.addLast(new LoggingHandler(LogLevel.INFO));
                    pipeline.addLast("http-codec", new HttpServerCodec());
                    pipeline.addLast("http-codec-compressor", new HttpObjectAggregator(65536));
                    if (server.config.netty.ipForwarding)
                        pipeline.addLast("forward-http", new NettyIpForwardHandler(context));
                    pipeline.addLast("websock-comp", new WebSocketServerCompressionHandler());
                    pipeline.addLast("websock-codec", new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
                    if (server.config.netty.fileServerEnabled)
                        pipeline.addLast("fileserver", new FileServerHandler(server.updatesDir, true, config.showHiddenFiles));
                    pipeline.addLast("launchserver", new WebSocketFrameHandler(context, server, service));
                    pipelineHook.hook(context, ch);
                }
            });
}
 
Example #6
Source File: TunnelSocketServerInitializer.java    From arthas with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true, 65536, false, true, 10000L));

    pipeline.addLast(new TunnelSocketFrameHandler(tunnelServer));
}
 
Example #7
Source File: WebSocketServerInitializer.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
    pipeline.addLast(new WebSocketFrameHandler());
}
 
Example #8
Source File: WebsocketServer.java    From mpush with Apache License 2.0 5 votes vote down vote up
@Override
protected void initPipeline(ChannelPipeline pipeline) {
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(CC.mp.net.ws_path, null, true));
    pipeline.addLast(new WebSocketIndexPageHandler());
    pipeline.addLast(getChannelHandler());
}
 
Example #9
Source File: NettyChannelInitializer.java    From ChatServer with Artistic License 2.0 5 votes vote down vote up
/**
 * 채널 파이프라인 설정.
 * Netty.Server.Configuration.NettyServerConfiguration 에서 등록한 Bean 을 이용해 사용자의 통신을 처리할 Handler 도 등록.
 * Netty.Server.Handler.JsonHandler 에서 실제 사용자 요청 처리.
 *
 * @param channel
 * @throws Exception
 */
@Override
protected void initChannel(Channel channel) throws Exception {

	ChannelPipeline channelPipeline = channel.pipeline();

	switch (transferType) {

		case "websocket":

			channelPipeline
					.addLast(new HttpServerCodec())
					.addLast(new HttpObjectAggregator(65536))
					.addLast(new WebSocketServerCompressionHandler())
					.addLast(new WebSocketServerProtocolHandler(transferWebsocketPath, transferWebsocketSubProtocol, transferWebsocketAllowExtensions))
					.addLast(new LoggingHandler(LogLevel.valueOf(logLevelPipeline)))
					.addLast(websocketHandler);

		case "tcp":
		default:

			channelPipeline
					.addLast(new LineBasedFrameDecoder(Integer.MAX_VALUE))
					.addLast(STRING_DECODER)
					.addLast(STRING_ENCODER)
					.addLast(new LoggingHandler(LogLevel.valueOf(logLevelPipeline)))
					.addLast(jsonHandler);

	}

}
 
Example #10
Source File: WebSocketRemoteServerInitializer.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, subProtocols, true));
    pipeline.addLast(new WebSocketRemoteServerFrameHandler());
}
 
Example #11
Source File: SampleWebSocketPushChannelInitializer.java    From zuul with Apache License 2.0 5 votes vote down vote up
@Override
protected void addPushHandlers(final ChannelPipeline pipeline) {
    pipeline.addLast(PushAuthHandler.NAME, pushAuthHandler);
    pipeline.addLast(new WebSocketServerCompressionHandler());
    pipeline.addLast(new WebSocketServerProtocolHandler(PushProtocol.WEBSOCKET.getPath(), null, true));
    pipeline.addLast(new PushRegistrationHandler(pushConnectionRegistry, PushProtocol.WEBSOCKET));
    pipeline.addLast(new SampleWebSocketPushClientProtocolHandler());
}
 
Example #12
Source File: WebsocketServerOperations.java    From reactor-netty with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("FutureReturnValueIgnored")
WebsocketServerOperations(String wsUrl, WebsocketServerSpec websocketServerSpec, HttpServerOperations replaced) {
	super(replaced);
	this.proxyPing = websocketServerSpec.handlePing();

	Channel channel = replaced.channel();
	onCloseState = MonoProcessor.create();

	// Handshake
	WebSocketServerHandshakerFactory wsFactory =
			new WebSocketServerHandshakerFactory(wsUrl, websocketServerSpec.protocols(), true, websocketServerSpec.maxFramePayloadLength());
	handshaker = wsFactory.newHandshaker(replaced.nettyRequest);
	if (handshaker == null) {
		//"FutureReturnValueIgnored" this is deliberate
		WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(channel);
		handshakerResult = null;
	}
	else {
		removeHandler(NettyPipeline.HttpTrafficHandler);
		removeHandler(NettyPipeline.AccessLogHandler);
		removeHandler(NettyPipeline.HttpMetricsHandler);

		handshakerResult = channel.newPromise();
		HttpRequest request = new DefaultFullHttpRequest(replaced.version(),
				replaced.method(),
				replaced.uri());

		request.headers()
		       .set(replaced.nettyRequest.headers());

		if (websocketServerSpec.compress()) {
			removeHandler(NettyPipeline.CompressionHandler);

			WebSocketServerCompressionHandler wsServerCompressionHandler =
					new WebSocketServerCompressionHandler();
			try {
				wsServerCompressionHandler.channelRead(channel.pipeline()
				                                              .context(NettyPipeline.ReactiveBridge),
						request);

				addHandlerFirst(NettyPipeline.WsCompressionHandler, wsServerCompressionHandler);
			} catch (Throwable e) {
				log.error(format(channel(), ""), e);
			}
		}

		handshaker.handshake(channel,
		                     request,
		                     replaced.responseHeaders
		                             .remove(HttpHeaderNames.TRANSFER_ENCODING),
		                     handshakerResult)
		          .addListener(f -> {
		              if (replaced.rebind(this)) {
		                  markPersistent(false);
		              }
		              else {
		                  log.debug("Cannot bind WebsocketServerOperations after the handshake.");
		              }
		          });
	}
}
 
Example #13
Source File: SocketIOChannelInitializer.java    From socketio with Apache License 2.0 4 votes vote down vote up
@Override
protected void initChannel(Channel ch) throws Exception {
  ChannelPipeline pipeline = ch.pipeline();
  // Flash policy file
  if (isFlashSupported) {
    pipeline.addLast(FLASH_POLICY_HANDLER, flashPolicyHandler);
  }
  // SSL
  if (sslContext != null) {
    pipeline.addLast(SSL_HANDLER, sslContext.newHandler(ch.alloc()));
  }

  // HTTP
  pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder());
  pipeline.addLast(HTTP_CHUNK_AGGREGATOR, new HttpObjectAggregator(MAX_HTTP_CONTENT_LENGTH));
  pipeline.addLast(HTTP_RESPONSE_ENCODER, new HttpResponseEncoder());
  if (isHttpCompressionEnabled) {
    pipeline.addLast(HTTP_COMPRESSION, new HttpContentCompressor());
  }

  // Flash resources
  if (isFlashSupported) {
    pipeline.addLast(FLASH_RESOURCE_HANDLER, flashResourceHandler);
  }

  // Socket.IO
  pipeline.addLast(SOCKETIO_PACKET_ENCODER, packetEncoderHandler);
  pipeline.addLast(SOCKETIO_HANDSHAKE_HANDLER, handshakeHandler);
  pipeline.addLast(SOCKETIO_DISCONNECT_HANDLER, disconnectHandler);
  if (isWebsocketCompressionEnabled) {
    pipeline.addLast(WEBSOCKET_COMPRESSION, new WebSocketServerCompressionHandler());
  }
  pipeline.addLast(SOCKETIO_WEBSOCKET_HANDLER, webSocketHandler);
  if (isFlashSupported) {
    pipeline.addLast(SOCKETIO_FLASHSOCKET_HANDLER, flashSocketHandler);
  }
  pipeline.addLast(SOCKETIO_XHR_POLLING_HANDLER, xhrPollingHandler);
  if (isJsonpSupported) {
    pipeline.addLast(SOCKETIO_JSONP_POLLING_HANDLER, jsonpPollingHandler);
  }
  pipeline.addLast(SOCKETIO_HEARTBEAT_HANDLER, heartbeatHandler);
  pipeline.addLast(eventExecutorGroup, SOCKETIO_PACKET_DISPATCHER, packetDispatcherHandler);

  if (pipelineModifier != null) {
    pipelineModifier.modifyPipeline(pipeline);
  }
}