use of io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler in project java-in-action by xinghalo.
the class ChatServerInitializer method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpObjectAggregator(60 * 1024));
pipeline.addLast(new HttpRequestHandler("/ws"));
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
pipeline.addLast(new TextWebSocketFrameHandler(group));
}
use of io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler in project transporter by wang4ever.
the class WSChildHandlerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
WSConfig conf = this.config.getWsConfig();
if (logger.isDebugEnabled())
logger.debug("Initital channel handler...\twebsocketPath={}", conf.getWebsocketPath());
ChannelPipeline p = ch.pipeline();
// Configure SSL.
if (conf.getSslEnable()) {
/*
* SelfSignedCertificate ssc = new SelfSignedCertificate();
* SslContext sslCtx =
* SslContextBuilder.forServer(ssc.certificate(),
* ssc.privateKey()).build();
*/
File keyCertChainFile = new File(Resources.getResource(conf.getKeyCertChainFile()).getFile());
File keyFile = new File(Resources.getResource(conf.getKeyFile()).getFile());
SslContext sslCtx = SslContextBuilder.forServer(keyCertChainFile, keyFile).build();
p.addLast(sslCtx.newHandler(ch.alloc()));
if (logger.isDebugEnabled())
logger.debug("The ssl(wss) handler has been enabled. sslCtx={}", sslCtx.toString());
}
// pipeline管理channel中的Handler,在channel队列中添加一个handler来处理业务
if (conf.getLoggingEnable()) {
p.addLast(new LoggingHandler(LogLevel.valueOf(conf.getLoggingLevel())));
if (logger.isInfoEnabled())
logger.info("Netty internal log has been used. (WS)level={}", conf.getLoggingLevel());
}
IdleStateHandler idleHandler = new IdleStateHandler(conf.getReadIdleSeconds(), conf.getWriteIdleSeconds(), conf.getAllIdleSeconds());
p.addLast(idleHandler);
// 将请求和应答消息解码为HTTP消息
p.addLast("http-codec", new HttpServerCodec());
// 将HTTP消息的多个部分合成一条完整的HTTP消息
p.addLast("aggregator", new HttpObjectAggregator(65536));
// 向客户端发送HTML5文件
p.addLast("http-chunked", new ChunkedWriteHandler());
p.addLast("ws-protocol", new WebSocketServerProtocolHandler(conf.getWebsocketPath(), null, true));
p.addLast("text-handler", SpringContextHolder.getBean("textWSFrameHandler"));
}
use of io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler in project ballerina by ballerina-lang.
the class WebSocketRemoteServerInitializer method initChannel.
@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));
WebSocketRemoteServerFrameHandler frameHandler = new WebSocketRemoteServerFrameHandler();
FRAME_HANDLERS.add(frameHandler);
pipeline.addLast(frameHandler);
}
use of io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler in project neo4j by neo4j.
the class TransportSelectionHandler method switchToWebsocket.
private void switchToWebsocket(ChannelHandlerContext ctx) {
ChannelPipeline p = ctx.pipeline();
memoryTracker.allocateHeap(HTTP_SERVER_CODEC_SHALLOW_SIZE + HTTP_OBJECT_AGGREGATOR_SHALLOW_SIZE + WEB_SOCKET_SERVER_PROTOCOL_HANDLER_SHALLOW_SIZE + WEB_SOCKET_FRAME_AGGREGATOR_SHALLOW_SIZE + WebSocketFrameTranslator.SHALLOW_SIZE + ProtocolHandshaker.SHALLOW_SIZE);
p.addLast(new HttpServerCodec(), new HttpObjectAggregator(MAX_WEBSOCKET_HANDSHAKE_SIZE), new WebSocketServerProtocolHandler("/", null, false, MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameAggregator(MAX_WEBSOCKET_FRAME_SIZE), new WebSocketFrameTranslator(), newHandshaker());
p.remove(this);
}
use of io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler in project summer by foxsugar.
the class WebSocketServerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 处理日志
// pipeline.addLast(new LoggingHandler(LogLevel.INFO));
// 处理心跳
// pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS));
// pipeline.addLast(new ChatHeartbeatHandler());
// // 获取职责链
// pipeline.addLast("http-codec", new HttpServerCodec());
// pipeline.addLast("aggregator", new HttpObjectAggregator(64*1024));
// pipeline.addLast("http-chunked", new ChunkedWriteHandler());
// // pipeline.addLast(new WebSocketServerCompressionHandler());
//
// // pipeline.addLast("encoder", new WsEncoder());
// // pipeline.addLast("decoder", new WsDecoder());
// pipeline.addLast("handshake",new WebSocketServerProtocolHandler("/ws"));
// pipeline.addLast(new WsCodec());
// // pipeline.addLast(new WsGameMsgHandler());
// pipeline.addLast(new WsHandler());
// // pipeline.addLast("codec", new WsEncoder());
// //websocket定义了传递数据的6中frame类型
// // pipeline.addLast(new GameMsgHandler());
//
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
pipeline.addLast(new WebSocketServerProtocolHandler("/websocket", null, true));
pipeline.addLast(new WsCodec());
pipeline.addLast(new GameMsgHandler());
// ChannelPipeline pipeline = ch.pipeline();
// 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 WebSocketServerHandler());
}
Aggregations