本文整理汇总了Java中io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler类的典型用法代码示例。如果您正苦于以下问题:Java WebSocketServerProtocolHandler类的具体用法?Java WebSocketServerProtocolHandler怎么用?Java WebSocketServerProtocolHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketServerProtocolHandler类属于io.netty.handler.codec.http.websocketx包,在下文中一共展示了WebSocketServerProtocolHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userEventTriggered
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)throws Exception {
if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE)
{//旧版本
log.debug("excute webSocketHandComplete……");
webSocketHandComplete(ctx);
ctx.pipeline().remove(this);
log.debug("excuted webSocketHandComplete:"+ctx.pipeline().toMap().toString());
return;
}
if(evt instanceof HandshakeComplete)
{//新版本
HandshakeComplete hc=(HandshakeComplete)evt;
log.debug("excute webSocketHandComplete……,HandshakeComplete="+hc);
webSocketHandComplete(ctx);
ctx.pipeline().remove(this);
log.debug("excuted webSocketHandComplete:"+ctx.pipeline().toMap().toString());
return;
}
super.userEventTriggered(ctx, evt);
}
示例2: setupWSChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
return new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
ch.pipeline().addLast("httpServer", new HttpServerCodec());
ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
ch.pipeline().addLast("error", new WSExceptionHandler());
}
};
}
示例3: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
//编解码http请求
pipeline.addLast(new HttpServerCodec());
//聚合解码HttpRequest/HttpContent/LastHttpContent到FullHttpRequest
//保证接收的Http请求的完整性
pipeline.addLast(new HttpObjectAggregator(64 *1024));
//写文件内容
pipeline.addLast(new ChunkedWriteHandler());
//处理FullHttpRequest
pipeline.addLast(new HttpRequestHandler("/ws"));
//处理其他的WebSocketFrame
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
//处理TextWebSocketFrame
pipeline.addLast(new TextWebSocketFrameHandler(group));
}
示例4: userEventTriggered
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// 如果WebSocket握手完成
if (evt == WebSocketServerProtocolHandler.ServerHandshakeStateEvent.HANDSHAKE_COMPLETE) {
// 删除ChannelPipeline中的HttpRequestHttpHandler
ctx.pipeline().remove(HttpRequestHandler.class);
String user = ChatUtils.addChannel(ctx.channel());
Users us = new Users(user);
ctx.channel().writeAndFlush(new TextWebSocketFrame(us.getCurrentUser()));
// 写一个消息到ChannelGroup
group.writeAndFlush(new TextWebSocketFrame(user + " 加入聊天室."));
// 将channel添加到ChannelGroup
group.add(ctx.channel());
group.writeAndFlush(new TextWebSocketFrame(us.getAllUsers()));
} else {
super.userEventTriggered(ctx, evt);
}
}
示例5: handleRequest
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
/**
* Processes an HTTP request
* @param ctx The channel handler context
* @param req The HTTP request
*/
public void handleRequest(final ChannelHandlerContext ctx, final FullHttpRequest req) {
log.warn("HTTP Request: {}", req);
if (req.method() != GET) {
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
return;
}
String uri = req.uri();
if(!"/ws".equals(uri)) {
//channelRead(ctx, req);
final WebSocketServerProtocolHandler wsProto = ctx.pipeline().get(WebSocketServerProtocolHandler.class);
if(wsProto != null) {
try {
wsProto.acceptInboundMessage(req);
return;
} catch (Exception ex) {
log.error("Failed to dispatch http request to WebSocketServerProtocolHandler on channel [{}]", ctx.channel(), ex);
}
}
}
log.error("Failed to handle HTTP Request [{}] on channel [{}]", req, ctx.channel());
sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.MISDIRECTED_REQUEST));
}
示例6: decode
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
{
if(!added && msg instanceof HttpRequest)
{
String path = ((HttpRequest)msg).getUri();
WsServerHandler handler = findHandler(path);
if(handler != null)
{
ctx.pipeline().addAfter("switch", "aggregator", new HttpObjectAggregator(65536));
ctx.pipeline().addAfter("aggregator", "wsprotocol", new WebSocketServerProtocolHandler(path, null, true));
ctx.pipeline().addAfter("wsprotocol", "wshandler", new WsFrameHandler(handler));
added = true;
}
}
ReferenceCountUtil.retain(msg);
out.add(msg);
}
示例7: createInitializer
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
protected ChannelInitializer<Channel> createInitializer() {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec() );
p.addLast(new ChunkedWriteHandler());
p.addLast(new HttpObjectAggregator(64 * 1024));
p.addLast(new EchoServerHttpRequestHandler("/ws"));
p.addLast(new WebSocketServerProtocolHandler("/ws"));
p.addLast(new EchoServerWSHandler());
}
};
}
示例8: initWebSocketPipeline
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
private void initWebSocketPipeline(ChannelHandlerContext ctx, String websocketPath) {
ChannelPipeline pipeline = ctx.pipeline();
//websockets specific handlers
pipeline.addLast("WSWebSocketServerProtocolHandler", new WebSocketServerProtocolHandler(websocketPath, true));
pipeline.addLast("WSWebSocket", new WebSocketHandler(stats));
pipeline.addLast("WSMessageDecoder", new MessageDecoder(stats));
pipeline.addLast("WSSocketWrapper", new WebSocketWrapperEncoder());
pipeline.addLast("WSMessageEncoder", new MessageEncoder(stats));
pipeline.addLast("WSWebSocketGenericLoginHandler", genericLoginHandler);
pipeline.remove(this);
pipeline.remove(ChunkedWriteHandler.class);
pipeline.remove(UrlReWriterHandler.class);
pipeline.remove(StaticFileHandler.class);
pipeline.remove(LetsEncryptHandler.class);
}
示例9: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
if (enableGzip) {
p.addLast(new HttpContentCompressor());
}
p.addLast(new HttpServerCodec(36192 * 2, 36192 * 8, 36192 * 16, false));
p.addLast(new HttpServerExpectContinueHandler());
p.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
p.addLast(new ChunkedWriteHandler());
if (enableCors) {
CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
p.addLast(new CorsHandler(corsConfig));
}
if (null != blade.webSocketPath()) {
p.addLast(new WebSocketServerProtocolHandler(blade.webSocketPath(), null, true));
p.addLast(new WebSockerHandler(blade));
}
service.scheduleWithFixedDelay(() -> date = new AsciiString(DateKit.gmtDate(LocalDateTime.now())), 1000, 1000, TimeUnit.MILLISECONDS);
p.addLast(new HttpServerHandler());
}
示例10: run
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
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);
}
示例11: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
//Decode bytes to HTTP requests / encode HTTP requests to bytes.
pipeline.addLast(new HttpServerCodec());
//Allows to write a file content.
pipeline.addLast(new ChunkedWriteHandler());
//Aggregate decoded HttpRequest / HttpContent / LastHttpContent to FullHttpRequest. This way you will always receive only full Http requests
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
//Handle FullHttpRequest which are not send to /ws URI and so serve the index.html page
pipeline.addLast(new HttpRequestHandler("/ws"));
//Handle the WebSocket upgrade and Ping/Pong/Close WebSocket frames to be RFC compliant
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
//Handles Text frames and handshake completion events
pipeline.addLast(new TextWebSocketFrameHandler(group));
}
示例12: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("timeout", new ReadTimeoutHandler(15));
pipeline.addLast("codec-http", new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new HTTPHandler(plugin));
pipeline.addLast("websocket", new WebSocketServerProtocolHandler("/server"));
pipeline.addLast("packet-decoder", new PacketDecoder());
pipeline.addLast("packet-encoder", new PacketEncoder());
pipeline.addLast("packet-handler", new ClientHandler(socketChannel, plugin));
socketChannel.config().setAllocator(PooledByteBufAllocator.DEFAULT);
plugin.getWebHandler().getChannelGroup().add(socketChannel);
}
示例13: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new ReadTimeoutHandler(60, TimeUnit.SECONDS));
if (sslContext != null) {
p.addLast(sslContext.newHandler(ch.alloc()));
}
p.addLast(new HttpContentCompressor(5));
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
p.addLast(new ChunkedWriteHandler());
if (null != corsConfig) {
p.addLast(new CorsHandler(corsConfig));
}
p.addLast(new WebSocketServerCompressionHandler());
p.addLast(new WebSocketServerProtocolHandler(webSocketPath, null, true));
p.addLast(new LaputaServerHandler(null != sslContext, requestProcessor));
}
示例14: initChannel
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
protected void initChannel(NioSocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 编解码 http 请求
pipeline.addLast(new HttpServerCodec());
// 写文件内容
pipeline.addLast(new ChunkedWriteHandler());
// 聚合解码 HttpRequest/HttpContent/LastHttpContent 到 FullHttpRequest
// 保证接收的 Http 请求的完整性
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
// 处理其他的 WebSocketFrame
pipeline.addLast(new WebSocketServerProtocolHandler("/chat"));
// 处理 TextWebSocketFrame
pipeline.addLast(protoCodec);
pipeline.addLast(serverHandler);
}
示例15: switchToHttp
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; //导入依赖的package包/类
private void switchToHttp(ChannelHandlerContext ctx) {
ChannelPipeline p = ctx.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new WebSocketServerCompressionHandler());
p.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, "ws", true));
p.addLast(new NetoJsonStringToMapWebSocketDecoder());
p.addLast(new NetoMessageToWebsocketFrameEncoder());
p.remove(this);
// 핸들러를 다시 등록 했으므로 이벤트를 전파
ctx.fireChannelActive();
}