From 20fffb6920351c745fb5827b6d25e00026fd5e68 Mon Sep 17 00:00:00 2001 From: Stefan Date: Thu, 18 Aug 2022 06:36:17 +0200 Subject: [PATCH] use open() method because getOpenFuture() method was removed from code in version 2.9.0 (without prior deprecation); Signed-off-by: Stefan Maute --- .../tunnel/TunnelChannelListener.java | 37 +++++++++++++------ .../tunnel/TunnelSessionListener.java | 1 + 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelChannelListener.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelChannelListener.java index f5ce4565f2..88dbc46d1f 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelChannelListener.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelChannelListener.java @@ -12,6 +12,8 @@ */ package org.eclipse.ditto.connectivity.service.messaging.tunnel; +import java.io.IOException; + import org.apache.sshd.client.future.OpenFuture; import org.apache.sshd.common.channel.Channel; import org.apache.sshd.common.channel.ChannelListener; @@ -37,7 +39,8 @@ final class TunnelChannelListener implements ChannelListener { * @param initialSshChannelWindowSize the initial window size to use for the RemoteWindow of the SSH channel * @param logger the logger */ - TunnelChannelListener(final ActorRef sshTunnelActor, final String initialSshChannelWindowSize, final LoggingAdapter logger) { + TunnelChannelListener(final ActorRef sshTunnelActor, final String initialSshChannelWindowSize, + final LoggingAdapter logger) { this.sshTunnelActor = sshTunnelActor; this.logger = logger; try { @@ -95,18 +98,28 @@ public void channelClosed(final Channel channel, final Throwable reason) { // attach a listener to the open future, otherwise we have no access to the exception that caused the opening // to fail (e.g. channelOpenFailure is not called with an exception) if (channel instanceof TcpipClientChannel tcpipClientChannel) { - final OpenFuture openFuture = tcpipClientChannel.getOpenFuture(); - if (openFuture != null) { - tcpipClientChannel.getOpenFuture() - .addListener(future -> { - final Throwable exception = future.getException(); - if (exception != null) { - final SshTunnelActor.TunnelClosed tunnelClosed = - new SshTunnelActor.TunnelClosed(TUNNEL_EXCEPTION_MESSAGE, exception); - sshTunnelActor.tell(tunnelClosed, ActorRef.noSender()); - } - }); + final OpenFuture openFuture; + try { + openFuture = tcpipClientChannel.open(); + if (openFuture != null) { + tcpipClientChannel.open() + .addListener(future -> { + final Throwable exception = future.getException(); + if (exception != null) { + tellExceptionToTunnelActor(exception); + } + }); + } + } catch (IOException e) { + tellExceptionToTunnelActor(e); } } } + + private void tellExceptionToTunnelActor(final Throwable exception) { + final SshTunnelActor.TunnelClosed tunnelClosed = + new SshTunnelActor.TunnelClosed(TUNNEL_EXCEPTION_MESSAGE, exception); + sshTunnelActor.tell(tunnelClosed, ActorRef.noSender()); + } + } diff --git a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelSessionListener.java b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelSessionListener.java index 67c94820f7..76ef693d06 100644 --- a/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelSessionListener.java +++ b/connectivity/service/src/main/java/org/eclipse/ditto/connectivity/service/messaging/tunnel/TunnelSessionListener.java @@ -68,4 +68,5 @@ public void sessionDisconnect(final Session session, final int reason, final Str logger.debug("SSH session disconnected: {}, reason: {}, msg: {}, initiator: {}", session, reason, msg, initiator ? "local" : "remote"); } + }