Example usage for io.netty.handler.ssl SslHandshakeCompletionEvent cause

List of usage examples for io.netty.handler.ssl SslHandshakeCompletionEvent cause

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslHandshakeCompletionEvent cause.

Prototype

public final Throwable cause() 

Source Link

Document

Return the Throwable if #isSuccess() returns false and so the completion failed.

Usage

From source file:com.linkedin.r2.transport.http.client.Http2AlpnHandler.java

License:Apache License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
        if (handshakeEvent.isSuccess()) {
            LOG.debug("SSL handshake succeeded");
            SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
            if (sslHandler == null) {
                ctx.fireExceptionCaught(
                        new IllegalStateException("cannot find a SslHandler in the pipeline (required for "
                                + "application-level protocol negotiation)"));
                return;
            }// w  w w  .ja v  a 2  s.  c o m
            String protocol = sslHandler.applicationProtocol();
            if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
                LOG.debug("HTTP/2 is negotiated");

                // Add HTTP/2 handler
                ctx.pipeline().addAfter("sslHandler", "http2Handler", _http2Handler);

                // Remove handler from pipeline after negotiation is complete
                ctx.pipeline().remove(this);
                _alpnPromise.setSuccess();
            } else {
                LOG.error("Protocol {}, instead of HTTP/2, is negotiated through ALPN", protocol);
                _alpnPromise.setFailure(new IllegalStateException("HTTP/2 ALPN negotiation failed"));
            }
        } else {
            LOG.error("SSL handshake failed", handshakeEvent.cause());
            _alpnPromise.setFailure(handshakeEvent.cause());
        }
    }

    ctx.fireUserEventTriggered(evt);
}

From source file:reactor.ipc.netty.channel.SslReadHandler.java

License:Open Source License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        handshakeDone = true;//w ww .  j  a  va  2  s  . c om
        if (ctx.pipeline().context(this) != null) {
            ctx.pipeline().remove(this);
        }
        SslHandshakeCompletionEvent handshake = (SslHandshakeCompletionEvent) evt;
        if (handshake.isSuccess()) {
            ctx.fireChannelActive();
        } else {
            sink.error(handshake.cause());
        }
    }
    super.userEventTriggered(ctx, evt);
}

From source file:reactor.ipc.netty.tcp.SslReadHandler.java

License:Open Source License

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof SslHandshakeCompletionEvent) {
        handshakeDone = true;/*from ww w . j a  v  a  2 s .c o m*/
        SslHandshakeCompletionEvent handshake = (SslHandshakeCompletionEvent) evt;
        if (handshake.isSuccess()) {
            ctx.fireChannelActive();
        } else {
            sink.error(handshake.cause());
        }
    }
    super.userEventTriggered(ctx, evt);
}

From source file:vn.com.onesoft.bigfox.server.io.core.channel.websocket.WebSocketServerHandler.java

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    if (evt instanceof SslHandshakeCompletionEvent) {
        if (!((SslHandshakeCompletionEvent) evt).isSuccess()) {
            SslHandshakeCompletionEvent evs = (SslHandshakeCompletionEvent) evt;
            BFLogger.getInstance().error(evs, evs.cause());
        }//from  w  w  w .j av a2 s.c om

    }
}