diff --git a/src/main/java/hudson/remoting/Engine.java b/src/main/java/hudson/remoting/Engine.java index c6880cebe..6285c14ab 100644 --- a/src/main/java/hudson/remoting/Engine.java +++ b/src/main/java/hudson/remoting/Engine.java @@ -302,12 +302,24 @@ public void run() { Channel channel = null; // Try available protocols. + boolean triedAtLeastOneProtocol = false; for (JnlpProtocol protocol : protocols) { + if (!protocol.isEnabled()) { + events.status("Protocol " + protocol.getName() + " is not enabled, skipping"); + continue; + } + triedAtLeastOneProtocol = true; events.status("Trying protocol: " + protocol.getName()); try { channel = protocol.establishChannel(jnlpSocket, channelBuilder); } catch (IOException ioe) { - events.status("Protocol failed to establish channel", ioe); + events.status("Protocol " + protocol.getName() + " failed to establish channel", ioe); + } catch (RuntimeException e) { + events.status("Protocol " + protocol.getName() + " encountered a runtime error", e); + } catch (Error e) { + events.status("Protocol " + protocol.getName() + " could not be completed due to an error", e); + } catch (Throwable e) { + events.status("Protocol " + protocol.getName() + " encountered an unexpected exception", e); } // On success do not try other protocols. @@ -322,7 +334,12 @@ public void run() { // If no protocol worked. if (channel == null) { - onConnectionRejected("None of the protocols were accepted"); + if (triedAtLeastOneProtocol) { + onConnectionRejected("None of the protocols were accepted"); + } else { + onConnectionRejected("None of the protocols are enabled"); + return; // exit + } continue; } diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol.java index 0ddfb577f..29a4d7050 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol.java @@ -57,6 +57,14 @@ public abstract class JnlpProtocol { this.events = events; } + /** + * Whether this protocol is enabled for connecting. + * @return {@code true} if this protocol is enabled. + */ + public boolean isEnabled() { + return !Boolean.getBoolean(getClass().getName()+".disabled"); + } + /** * Get the name of the protocol. */