Example usage for io.netty.handler.ssl SslHandler getHandshakeTimeoutMillis

List of usage examples for io.netty.handler.ssl SslHandler getHandshakeTimeoutMillis

Introduction

In this page you can find the example usage for io.netty.handler.ssl SslHandler getHandshakeTimeoutMillis.

Prototype

public long getHandshakeTimeoutMillis() 

Source Link

Usage

From source file:org.waarp.common.crypto.ssl.WaarpSslUtility.java

License:Open Source License

/**
 * Wait for the handshake on the given channel (better to use addSslHandler when handler is added after channel is active)
 * /*www .j  a  va 2 s . com*/
 * @param channel
 * @return True if the Handshake is done correctly
 */
public static boolean waitForHandshake(Channel channel) {
    final ChannelHandler handler = channel.pipeline().first();
    if (handler instanceof SslHandler) {
        logger.debug("Start handshake SSL: " + channel);
        final SslHandler sslHandler = (SslHandler) handler;
        // Get the SslHandler and begin handshake ASAP.
        // Get notified when SSL handshake is done.
        Future<Channel> handshakeFuture = sslHandler.handshakeFuture();
        try {
            handshakeFuture.await(sslHandler.getHandshakeTimeoutMillis() + 100);
        } catch (InterruptedException e1) {
        }
        logger.debug("Handshake: " + handshakeFuture.isSuccess() + ": " + channel, handshakeFuture.cause());
        if (!handshakeFuture.isSuccess()) {
            channel.close();
            return false;
        }
        return true;
    } else {
        logger.error("SSL Not found but connected: " + handler.getClass().getName());
        return true;
    }
}