Revert "Bump apache mina to 1.2.0"
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / ssh / client / AsyncSshHandler.java
index 05cb0eb3e8c2fd8f61b5da2706e0d2dab1bf9e57..cb642c1a9954cba715cbb381431f9467c3c731c3 100644 (file)
@@ -17,13 +17,14 @@ import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GenericFutureListener;
 import java.io.IOException;
 import java.net.SocketAddress;
-import org.apache.sshd.client.SshClient;
-import org.apache.sshd.client.channel.ClientChannel;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.sshd.ClientChannel;
+import org.apache.sshd.ClientSession;
+import org.apache.sshd.SshClient;
 import org.apache.sshd.client.future.AuthFuture;
 import org.apache.sshd.client.future.ConnectFuture;
 import org.apache.sshd.client.future.OpenFuture;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionCreator;
 import org.apache.sshd.common.future.CloseFuture;
 import org.apache.sshd.common.future.SshFutureListener;
 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
@@ -44,9 +45,13 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
 
     public static final SshClient DEFAULT_CLIENT;
     static {
+        final Map<String, String> props = new HashMap<>();
+        props.put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+        props.put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
         final SshClient c = SshClient.setUpDefaultClient();
-        c.getProperties().put(SshClient.AUTH_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
-        c.getProperties().put(SshClient.IDLE_TIMEOUT, Long.toString(DEFAULT_TIMEOUT));
+
+        c.setProperties(props);
         // TODO make configurable, or somehow reuse netty threadpool
         c.setNioWorkers(SSH_DEFAULT_NIO_WORKERS);
         c.start();
@@ -54,7 +59,7 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     }
 
     private final AuthenticationHandler authenticationHandler;
-    private final ClientSessionCreator sshClient;
+    private final SshClient sshClient;
     private Future<?> negotiationFuture;
 
     private AsyncSshHandlerReader sshReadAsyncListener;
@@ -65,8 +70,8 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
     private ChannelPromise connectPromise;
     private GenericFutureListener negotiationFutureListener;
 
-    public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient,
-            final Future<?> negotiationFuture) {
+    public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient,
+            final Future<?> negotiationFuture) throws IOException {
         this(authenticationHandler, sshClient);
         this.negotiationFuture = negotiationFuture;
     }
@@ -75,31 +80,33 @@ public class AsyncSshHandler extends ChannelOutboundHandlerAdapter {
      *
      * @param authenticationHandler
      * @param sshClient started SshClient
+     * @throws IOException
      */
-    public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final ClientSessionCreator sshClient) {
+    public AsyncSshHandler(final AuthenticationHandler authenticationHandler, final SshClient sshClient) throws IOException {
         this.authenticationHandler = Preconditions.checkNotNull(authenticationHandler);
         this.sshClient = Preconditions.checkNotNull(sshClient);
     }
 
-    public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) {
+    public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler) throws IOException {
         return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT);
     }
 
     /**
      *
-     * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful
-     * NETCONF negotiation.
+     * Create AsyncSshHandler for netconf subsystem. Negotiation future has to be set to success after successful netconf
+     * negotiation.
      *
      * @param authenticationHandler
      * @param negotiationFuture
      * @return
+     * @throws IOException
      */
     public static AsyncSshHandler createForNetconfSubsystem(final AuthenticationHandler authenticationHandler,
-            final Future<?> negotiationFuture) {
+            final Future<?> negotiationFuture) throws IOException {
         return new AsyncSshHandler(authenticationHandler, DEFAULT_CLIENT, negotiationFuture);
     }
 
-    private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) throws IOException {
+    private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) {
         LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel());
 
         final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address);