Search in sources :

Example 1 with HOST

use of io.netty.handler.codec.http.HttpHeaders.Names.HOST in project modules-extra by CubeEngine.

the class WebSocketRequestHandler method doHandshake.

public void doHandshake(ChannelHandlerContext ctx, FullHttpRequest message) {
    WebSocketServerHandshakerFactory handshakerFactory = new WebSocketServerHandshakerFactory("ws://" + message.headers().get(HOST) + "/" + WEBSOCKET_ROUTE, null, false);
    this.handshaker = handshakerFactory.newHandshaker(message);
    if (handshaker == null) {
        this.log.info("client is incompatible!");
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        return;
    }
    this.log.debug("handshaking now...");
    this.handshaker.handshake(ctx.channel(), message).addListener((ChannelFutureListener) future -> {
        if (future.isSuccess()) {
            log.debug("Success!");
        } else {
            log.debug("Failed!");
        }
    });
}
Also used : WebSocketServerHandshakerFactory(io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory) WebSocketFrame(io.netty.handler.codec.http.websocketx.WebSocketFrame) User(org.spongepowered.api.entity.living.player.User) EMPTY_HEADERS(io.netty.handler.codec.http.HttpHeaders.EMPTY_HEADERS) HOST(io.netty.handler.codec.http.HttpHeaders.Names.HOST) PingWebSocketFrame(io.netty.handler.codec.http.websocketx.PingWebSocketFrame) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) InetSocketAddress(java.net.InetSocketAddress) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ChannelFuture(io.netty.channel.ChannelFuture) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) CommandManager(org.cubeengine.libcube.service.command.CommandManager) Charset(java.nio.charset.Charset) TextWebSocketFrame(io.netty.handler.codec.http.websocketx.TextWebSocketFrame) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) PongWebSocketFrame(io.netty.handler.codec.http.websocketx.PongWebSocketFrame) ChannelFutureListener(io.netty.channel.ChannelFutureListener) QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) WebSocketServerHandshaker(io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker) JsonNode(com.fasterxml.jackson.databind.JsonNode) CloseWebSocketFrame(io.netty.handler.codec.http.websocketx.CloseWebSocketFrame) Log(org.cubeengine.logscribe.Log) WebSocketServerHandshakerFactory(io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 SimpleChannelInboundHandler (io.netty.channel.SimpleChannelInboundHandler)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 EMPTY_HEADERS (io.netty.handler.codec.http.HttpHeaders.EMPTY_HEADERS)1 HOST (io.netty.handler.codec.http.HttpHeaders.Names.HOST)1 QueryStringDecoder (io.netty.handler.codec.http.QueryStringDecoder)1 CloseWebSocketFrame (io.netty.handler.codec.http.websocketx.CloseWebSocketFrame)1 PingWebSocketFrame (io.netty.handler.codec.http.websocketx.PingWebSocketFrame)1 PongWebSocketFrame (io.netty.handler.codec.http.websocketx.PongWebSocketFrame)1 TextWebSocketFrame (io.netty.handler.codec.http.websocketx.TextWebSocketFrame)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1 WebSocketServerHandshaker (io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker)1 WebSocketServerHandshakerFactory (io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1