/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.qpid.jms.transports.netty;

import io.netty.channel.Channel;
import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

import java.net.URI;

import org.apache.qpid.jms.transports.TransportListener;
import org.apache.qpid.jms.transports.TransportOptions;
import org.apache.qpid.jms.transports.TransportSslOptions;
import org.apache.qpid.jms.transports.TransportSupport;
import org.apache.qpid.jms.util.IOExceptionSupport;

/**
 * Extends the Netty based TCP transport to add SSL support.
 */
public class NettySslTransport extends NettyTcpTransport {

    /**
     * Create a new transport instance
     *
     * @param remoteLocation
     *        the URI that defines the remote resource to connect to.
     * @param options
     *        the transport options used to configure the socket connection.
     */
    public NettySslTransport(URI remoteLocation, TransportOptions options) {
        this(null, remoteLocation, options);
    }

    /**
     * Create a new transport instance
     *
     * @param listener
     *        the TransportListener that will receive events from this Transport.
     * @param remoteLocation
     *        the URI that defines the remote resource to connect to.
     * @param options
     *        the transport options used to configure the socket connection.
     */
    public NettySslTransport(TransportListener listener, URI remoteLocation, TransportOptions options) {
        super(listener, remoteLocation, options);
    }

    @Override
    protected void configureChannel(Channel channel) throws Exception {
        channel.pipeline().addLast(TransportSupport.createSslHandler(getSslOptions()));

        super.configureChannel(channel);
    }

    @Override
    protected void handleConnected(final Channel channel) throws Exception {
        SslHandler sslHandler = channel.pipeline().get(SslHandler.class);

        Future<Channel> channelFuture = sslHandler.handshakeFuture();
        channelFuture.addListener(new GenericFutureListener<Future<Channel>>() {
            @Override
            public void operationComplete(Future<Channel> future) throws Exception {
                if (future.isSuccess()) {
                    connectionEstablished(channel);
                } else {
                    connectionFailed(IOExceptionSupport.create(future.cause()));
                }
            }
        });
    }

    private TransportSslOptions getSslOptions() {
        return (TransportSslOptions) options;
    }
}

@@ -1314,16 +1314,73 @@
 Support;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0A/**%0A *
@@ -1502,16 +1502,105 @@
 port %7B%0A%0A
+    private static final Logger LOG = LoggerFactory.getLogger(NettySslTransport.class);%0A%0A
     /**%0A
@@ -2681,17 +2681,16 @@
 ns()));%0A
-%0A
         
@@ -3219,64 +3219,211 @@
     
-connectionEstablished(channel);%0A                %7D else %7B
+LOG.trace(%22SSL Handshake has completed: %7B%7D%22, channel);%0A                    connectionEstablished(channel);%0A                %7D else %7B%0A                    LOG.trace(%22SSL Handshake has failed: %7B%7D%22, channel);
 %0A   

Add logging for the SSL handshake events.