Java 类io.netty.handler.codec.http.websocketx.WebSocketHandshakeException 实例源码

项目:firebase-admin-java    文件:NettyWebSocketClient.java   
@Override
public void channelRead0(ChannelHandlerContext context, Object message) throws Exception {
  Channel channel = context.channel();
  if (message instanceof FullHttpResponse) {
    checkState(!handshaker.isHandshakeComplete());
    try {
      handshaker.finishHandshake(channel, (FullHttpResponse) message);
      delegate.onOpen();
    } catch (WebSocketHandshakeException e) {
      delegate.onError(e);
    }
  } else if (message instanceof TextWebSocketFrame) {
    delegate.onMessage(((TextWebSocketFrame) message).text());
  } else {
    checkState(message instanceof CloseWebSocketFrame);
    delegate.onClose();
  }
}
项目:jawampa    文件:WampServerWebsocketHandler.java   
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof WebSocketHandshakeException) {
        sendBadRequestAndClose(ctx, cause.getMessage());
    } else {
        ctx.close();
    }
}
项目:reactor-netty    文件:HttpClientWSOperations.java   
@Override
@SuppressWarnings("unchecked")
public void onInboundNext(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof FullHttpResponse) {
        started = true;
        channel().pipeline()
                 .remove(HttpObjectAggregator.class);
        FullHttpResponse response = (FullHttpResponse) msg;

        setNettyResponse(response);

        if (checkResponseCode(response)) {

            try {
                if (!handshaker.isHandshakeComplete()) {
                    handshaker.finishHandshake(channel(), response);
                }
            }
            catch (WebSocketHandshakeException wshe) {
                if (serverError) {
                    onInboundError(wshe);
                    return;
                }
            }

            parentContext().fireContextActive(this);
            handshakerResult.trySuccess();
        }
        return;
    }
    if (msg instanceof PingWebSocketFrame) {
        channel().writeAndFlush(new PongWebSocketFrame(((PingWebSocketFrame) msg).content()));
        ctx.read();
        return;
    }
    if (msg instanceof CloseWebSocketFrame &&
            ((CloseWebSocketFrame)msg).isFinalFragment()) {
        if (log.isDebugEnabled()) {
            log.debug("CloseWebSocketFrame detected. Closing Websocket");
        }

        CloseWebSocketFrame close = (CloseWebSocketFrame) msg;
        sendClose(new CloseWebSocketFrame(true,
                close.rsv(),
                close.content()));
    }
    else {
        super.onInboundNext(ctx, msg);
    }
}
项目:blynk-server    文件:WebSocketHandler.java   
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    if (cause instanceof WebSocketHandshakeException) {
        log.debug("Web Socket Handshake Exception.", cause);
    }
}