You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2020/04/16 07:14:13 UTC

[mina-sshd] 01/02: Access AbstractCommandSupport internal state values via getters where applicable

This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git

commit 001d2f67b6cbfd5422263c16ec8161977af1e8e6
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Sun Apr 12 20:02:07 2020 +0300

    Access AbstractCommandSupport internal state values via getters where applicable
---
 .../server/command/AbstractCommandSupport.java     | 23 ++++++++++++----------
 .../org/apache/sshd/server/scp/ScpCommand.java     | 14 +++++++------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
index 03d1e3f..e63a79b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/command/AbstractCommandSupport.java
@@ -48,17 +48,18 @@ public abstract class AbstractCommandSupport
         extends AbstractLoggingBean
         implements Command, Runnable, ExecutorServiceCarrier, SessionAware,
         SessionHolder<ServerSession>, ServerSessionHolder {
-    protected final String command;
-    protected InputStream in;
-    protected OutputStream out;
-    protected OutputStream err;
-    protected ExitCallback callback;
-    protected Environment environment;
-    protected Future<?> cmdFuture;
     protected volatile Thread cmdRunner;
     protected CloseableExecutorService executorService;
     protected boolean cbCalled;
-    protected ServerSession serverSession;
+
+    private final String command;
+    private InputStream in;
+    private OutputStream out;
+    private OutputStream err;
+    private ExitCallback callback;
+    private Environment environment;
+    private Future<?> cmdFuture;
+    private ServerSession serverSession;
 
     protected AbstractCommandSupport(String command, CloseableExecutorService executorService) {
         this.command = command;
@@ -144,9 +145,11 @@ public abstract class AbstractCommandSupport
     @Override
     public void start(ChannelSession channel, Environment env) throws IOException {
         environment = env;
+
+        String cmd = getCommand();
         try {
             if (log.isDebugEnabled()) {
-                log.debug("start({}) starting runner for command={}", channel, command);
+                log.debug("start({}) starting runner for command={}", channel, cmd);
             }
 
             CloseableExecutorService executors = getExecutorService();
@@ -157,7 +160,7 @@ public abstract class AbstractCommandSupport
         } catch (RuntimeException e) {    // e.g., RejectedExecutionException
             log.error("start(" + channel + ")"
                 + " Failed (" + e.getClass().getSimpleName() + ")"
-                + " to start command=" + command + ": " + e.getMessage(), e);
+                + " to start command=" + cmd + ": " + e.getMessage(), e);
             throw new IOException(e);
         }
     }
diff --git a/sshd-scp/src/main/java/org/apache/sshd/server/scp/ScpCommand.java b/sshd-scp/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
index c4a2317..5a60137 100644
--- a/sshd-scp/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
+++ b/sshd-scp/src/main/java/org/apache/sshd/server/scp/ScpCommand.java
@@ -30,6 +30,7 @@ import org.apache.sshd.common.util.GenericUtils;
 import org.apache.sshd.common.util.threads.CloseableExecutorService;
 import org.apache.sshd.common.util.threads.ThreadUtils;
 import org.apache.sshd.server.Environment;
+import org.apache.sshd.server.ExitCallback;
 import org.apache.sshd.server.channel.ChannelSession;
 import org.apache.sshd.server.command.AbstractFileSystemCommand;
 import org.apache.sshd.server.session.ServerSession;
@@ -41,9 +42,7 @@ import org.apache.sshd.server.session.ServerSession;
  *
  * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
  */
-public class ScpCommand
-        extends AbstractFileSystemCommand {
-
+public class ScpCommand extends AbstractFileSystemCommand {
     protected final int sendBufferSize;
     protected final int receiveBufferSize;
     protected final ScpFileOpener opener;
@@ -159,7 +158,9 @@ public class ScpCommand
         int exitValue = ScpHelper.OK;
         String exitMessage = null;
         ServerSession session = getServerSession();
-        ScpHelper helper = new ScpHelper(session, in, out, fileSystem, opener, listener);
+        String command = getCommand();
+        ScpHelper helper = new ScpHelper(
+            session, getInputStream(), getOutputStream(), fileSystem, opener, listener);
         try {
             if (optT) {
                 helper.receive(helper.resolveLocalPath(path), optR, optD, optP, receiveBufferSize);
@@ -199,6 +200,7 @@ public class ScpCommand
                 log.error("run(" + session + ")[" + command + "] command execution failure details", e);
             }
         } finally {
+            ExitCallback callback = getExitCallback();
             if (callback != null) {
                 callback.onExit(exitValue, GenericUtils.trimToEmpty(exitMessage));
             }
@@ -210,11 +212,11 @@ public class ScpCommand
             log.debug("writeCommandResponseMessage({}) command='{}', exit-status={}: {}",
                   getServerSession(), command, exitValue, exitMessage);
         }
-        ScpHelper.sendResponseMessage(out, exitValue, exitMessage);
+        ScpHelper.sendResponseMessage(getOutputStream(), exitValue, exitMessage);
     }
 
     @Override
     public String toString() {
-        return getClass().getSimpleName() + "(" + getSession() + ") " + command;
+        return super.toString() + "[" + getSession() + "]";
     }
 }
\ No newline at end of file