本文整理匯總了Java中com.jcraft.jsch.JSchException.getMessage方法的典型用法代碼示例。如果您正苦於以下問題:Java JSchException.getMessage方法的具體用法?Java JSchException.getMessage怎麽用?Java JSchException.getMessage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.jcraft.jsch.JSchException
的用法示例。
在下文中一共展示了JSchException.getMessage方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setupJSch
import com.jcraft.jsch.JSchException; //導入方法依賴的package包/類
private boolean setupJSch (FS fs, String host, CredentialItem.StringType identityFile, URIish uri, boolean preferAgent) throws TransportException {
boolean agentUsed;
if (sshConfig == null) {
sshConfig = OpenSshConfig.get(fs);
}
final OpenSshConfig.Host hc = sshConfig.lookup(host);
try {
JSch jsch = getJSch(hc, fs);
agentUsed = setupJSchIdentityRepository(jsch, identityFile.getValue(), preferAgent);
} catch (JSchException ex) {
throw new TransportException(uri, ex.getMessage(), ex);
}
return agentUsed;
}
示例2: start
import com.jcraft.jsch.JSchException; //導入方法依賴的package包/類
private synchronized static ChannelStreams start(final JSchWorker<ChannelStreams> worker, final ExecutionEnvironment env, final int attempts) throws IOException, JSchException, InterruptedException {
int retry = attempts;
while (retry-- > 0) {
try {
return worker.call();
} catch (JSchException ex) {
String message = ex.getMessage();
Throwable cause = ex.getCause();
if (cause != null && cause instanceof NullPointerException) {
// Jsch bug... retry?
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Retrying", ex); // NOI18N
} else if ("java.io.InterruptedIOException".equals(message)) { // NOI18N
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Retrying in 0.5 seconds", ex); // NOI18N
try {
Thread.sleep(500);
} catch (InterruptedException ex1) {
Thread.currentThread().interrupt();
break;
}
} else if ("channel is not opened.".equals(message)) { // NOI18N
log.log(Level.INFO, "JSch exception opening channel to " + env + ". Reconnecting and retrying", ex); // NOI18N
// Now reconnect disconnects old session and creates new, so this might help
ConnectionManagerAccessor.getDefault().reconnect(env);
} else {
throw ex;
}
} catch (NullPointerException npe) {
// Jsch bug... retry? ;)
log.log(Level.FINE, "Exception from JSch", npe); // NOI18N
}
}
throw new IOException("Failed to execute " + worker.toString()); // NOI18N
}
示例3: startNewSession
import com.jcraft.jsch.JSchException; //導入方法依賴的package包/類
private Session startNewSession(boolean acquireChannel) throws JSchException, InterruptedException {
Session newSession = null;
final AtomicBoolean cancelled = new AtomicBoolean(false);
ConnectingProgressHandle.startHandle(env, new Cancellable() {
@Override
public boolean cancel() {
cancelled.set(true);
return true;
}
});
try {
while (!cancelled.get()) {
try {
newSession = jsch.getSession(env.getUser(), env.getHostAddress(), env.getSSHPort());
int serverAliveInterval = Integer.getInteger("jsch.server.alive.interval", 0); // NOI18N
if (serverAliveInterval > 0) {
newSession.setServerAliveInterval(serverAliveInterval);
int serverAliveCount = Integer.getInteger("jsch.server.alive.count", 5); // NOI18N
newSession.setServerAliveCountMax(serverAliveCount);
}
newSession.setUserInfo(userInfo);
for (Entry<String, String> entry : jschSessionConfig.entrySet()) {
newSession.setConfig(entry.getKey(), entry.getValue());
}
Authentication auth = Authentication.getFor(env);
final String preferredAuthKey = "PreferredAuthentications"; // NOI18N
if (!jschSessionConfig.containsKey(preferredAuthKey)) {
String methods = auth.getAuthenticationMethods().toJschString();
if (methods != null) {
log.finest("Setting auth method list to " + methods); //NOI18N
newSession.setConfig(preferredAuthKey, methods);
}
}
if (USE_JZLIB) {
newSession.setConfig("compression.s2c", "[email protected],zlib,none"); // NOI18N
newSession.setConfig("compression.c2s", "[email protected],zlib,none"); // NOI18N
newSession.setConfig("compression_level", "9"); // NOI18N
}
if (RemoteStatistics.COLLECT_STATISTICS && RemoteStatistics.COLLECT_TRAFFIC) {
newSession.setSocketFactory(MeasurableSocketFactory.getInstance());
}
newSession.connect(auth.getTimeout()*1000);
break;
} catch (JSchException ex) {
if (!UNIT_TEST_MODE) {
String msg = ex.getMessage();
if (msg == null) {
throw ex;
}
if (msg.startsWith("Auth fail") || msg.startsWith("SSH_MSG_DISCONNECT: 2")) { // NOI18N
PasswordManager.getInstance().clearPassword(env);
}
} else {
throw ex;
}
} catch (CancellationException cex) {
cancelled.set(true);
}
}
if (cancelled.get()) {
throw new InterruptedException("StartNewSession was cancelled ..."); // NOI18N
}
// In case of any port-forwarding previously set for this env
// init the new session appropriately
portForwarding.initSession(newSession);
sessions.put(newSession, new AtomicInteger(JSCH_CHANNELS_PER_SESSION - (acquireChannel ? 1 : 0)));
log.log(Level.FINE, "New session [{0}] started.", new Object[]{System.identityHashCode(newSession)}); // NOI18N
} finally {
ConnectingProgressHandle.stopHandle(env);
}
return newSession;
}