RestForwarder: Avoid retrying non recoverable exceptions

According to the documentation [1], there are other exceptions that are
considered non recoverable and that should not be retried. This includes
the cases when, for example, the URL is absent or malformed or any other
error in the HTTP protocol.

[1] https://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e279

Change-Id: Ic9141606e87f283d9308081443e9f52eef35284c
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
index aaa1e6b..e430fea 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
@@ -28,6 +28,8 @@
 import com.google.inject.Inject;
 import java.io.IOException;
 import javax.net.ssl.SSLException;
+import org.apache.http.HttpException;
+import org.apache.http.client.ClientProtocolException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -198,7 +200,10 @@
     abstract HttpResult send() throws IOException;
 
     boolean isRecoverable(IOException e) {
-      return !(e instanceof SSLException);
+      Throwable cause = e.getCause();
+      return !(e instanceof SSLException
+          || cause instanceof HttpException
+          || cause instanceof ClientProtocolException);
     }
   }
 }