本文整理汇总了Java中net.schmizz.sshj.common.SSHException类的典型用法代码示例。如果您正苦于以下问题:Java SSHException类的具体用法?Java SSHException怎么用?Java SSHException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SSHException类属于net.schmizz.sshj.common包,在下文中一共展示了SSHException类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeCommand
import net.schmizz.sshj.common.SSHException; //导入依赖的package包/类
@Override
public InputStream executeCommand(String logAccessConfigId, String shellCommand) throws LogAccessException {
// Get the LogAccessConfig
LogAccessConfig logAccessConfig = configService.getLogAccessConfig(logAccessConfigId);
// Create ssh client and authenticate
SSHClient sshClient = sshClientThreadLocal.get();
boolean closeSshClient = false;
if (sshClient == null) {
sshClient = connectAndAuthenticate(logAccessConfig);
closeSshClient = true;
}
// Define the precommand (if any)
String precommand = "";
if (StringUtils.hasText(logAccessConfig.getPreCommand())) {
precommand = logAccessConfig.getPreCommand() + " && ";
}
// Execute the shell command
Session session = null;
Command resultCommand;
try {
session = sshClient.startSession();
resultCommand = session.exec("cd \"" + logAccessConfig.getDirectory() + "\" && " + precommand + shellCommand);
}
catch (SSHException e) {
IOUtils.closeQuietly(session, sshClient);
throw new LogAccessException("Error when executing command " + shellCommand + " to " + logAccessConfig, e);
}
// Get and return the result stream
InputStream sequenceStream = new SequenceInputStream(resultCommand.getInputStream(), resultCommand.getErrorStream());
InputStream resultStream = new SshCloseFilterInputStream(sequenceStream, resultCommand, session, (closeSshClient ? sshClient : null));
return resultStream;
}
示例2: notifyDisconnect
import net.schmizz.sshj.common.SSHException; //导入依赖的package包/类
@Override
public void notifyDisconnect(final DisconnectReason reason, final String message) {
log.warn(String.format("Disconnected %s", reason));
failure = new SSHException(reason, message);
}
示例3: getFailure
import net.schmizz.sshj.common.SSHException; //导入依赖的package包/类
/**
* @return Last disconnect reason
*/
public SSHException getFailure() {
return failure;
}
示例4: testWrapped
import net.schmizz.sshj.common.SSHException; //导入依赖的package包/类
@Test
public void testWrapped() throws Exception {
assertEquals(InteroperabilityException.class,
new SFTPExceptionMappingService().map(new TransportException(DisconnectReason.UNKNOWN, new SSHException(DisconnectReason.PROTOCOL_ERROR))).getClass());
}