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

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

Introduction

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

Prototype

public Future<Channel> sslCloseFuture() 

Source Link

Document

Return the Future that will get notified if the inbound of the SSLEngine is closed.

Usage

From source file:org.maodian.flyingcat.xmpp.state.DefaultElementVisitor.java

License:Apache License

@Override
public State handleTLS(XmppContext xmppCtx, TLS tls) throws XMLStreamException {
    ChannelHandlerContext ctx = xmppCtx.getNettyChannelHandlerContext();
    SSLEngine engine = SecureSslContextFactory.getServerContext().createSSLEngine();
    engine.setUseClientMode(false);/* w  w w.  j a  v a2s .co  m*/
    SslHandler sslHandler = new SslHandler(engine, true);
    sslHandler.sslCloseFuture().addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            log.info("Close the socket since SSL connection has been closed by client");
            future.channel().close();
        }
    });
    ctx.pipeline().addFirst("ssl", sslHandler);

    StringWriter writer = new StringWriter();
    XMLStreamWriter xmlsw = XMLOutputFactoryHolder.getXMLOutputFactory().createXMLStreamWriter(writer);
    xmlsw.writeEmptyElement("", "proceed", XmppNamespace.TLS);
    xmlsw.setPrefix("", XmppNamespace.TLS);
    xmlsw.writeNamespace("", XmppNamespace.TLS);
    xmlsw.writeEndDocument();
    xmppCtx.flush(writer.toString());
    return xmppCtx.getGlobalContext().getTlsStreamState();
}