Fix b/15114347: Better error message for invalid GSA hostname.
This change provides a more descriptive error messages in the log
if the configured GSA is not found at startup. The error messages
cover common GSA communication configuration problems.
Code Review: http://codereview.appspot.com/103620043
diff --git a/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java b/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
index da162af..b4fa6c3 100644
--- a/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
+++ b/src/com/google/enterprise/adaptor/GsaCommunicationHandler.java
@@ -32,6 +32,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
+import java.net.ConnectException;
+import java.net.UnknownHostException;
import java.net.URI;
import java.net.URISyntaxException;
import java.security.Key;
@@ -58,6 +60,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.net.ssl.SSLException;
/** This class handles the communications with GSA. */
public final class GsaCommunicationHandler {
@@ -356,7 +359,9 @@
// we're talking to a GSA whose version we don't understand
log.log(Level.FINE, "gsa provided incomprehensible version", iae);
config.setValue("gsa.version", "7.0.14-114");
- } // other IOException propagates out
+ } catch (IOException ioe) {
+ throw handleGsaException(config.getGsaHostname(), ioe);
+ }
}
private TransformPipeline createTransformPipeline() {
@@ -724,6 +729,26 @@
return context;
}
+ /** Wrap certain GSA communication problems with more descriptive messages. */
+ static IOException handleGsaException(String gsa, IOException e) {
+ if (e instanceof ConnectException) {
+ return new IOException("Failed to connect to the GSA at " + gsa + " . "
+ + "Please verify that the gsa.hostname configuration property "
+ + "is correct and the GSA is online, and is configured to accept "
+ + "feeds from this computer.", e);
+ } else if (e instanceof UnknownHostException) {
+ return new IOException("Failed to locate the GSA at " + gsa + " . "
+ + "Please verify that the gsa.hostname configuration property "
+ + "is correct.", e);
+ } else if (e instanceof SSLException) {
+ return new IOException("Failed to connect to the GSA at " + gsa + " . "
+ + "Please verify that the your SSL Certificates are properly "
+ + "configured for secure communication with the GSA.", e);
+ } else {
+ return e;
+ }
+ }
+
/**
* Runnable that calls {@link DocIdSender#pushDocIds}.
*/
diff --git a/src/com/google/enterprise/adaptor/GsaFeedFileSender.java b/src/com/google/enterprise/adaptor/GsaFeedFileSender.java
index 59be394..8e94a56 100644
--- a/src/com/google/enterprise/adaptor/GsaFeedFileSender.java
+++ b/src/com/google/enterprise/adaptor/GsaFeedFileSender.java
@@ -228,8 +228,13 @@
private void sendMessage(URL destUrl, byte msg[], boolean useCompression)
throws IOException {
- HttpURLConnection uc = setupConnection(destUrl, msg.length, useCompression);
- uc.connect();
+ HttpURLConnection uc;
+ try {
+ uc = setupConnection(destUrl, msg.length, useCompression);
+ uc.connect();
+ } catch (IOException ioe) {
+ throw GsaCommunicationHandler.handleGsaException(destUrl.toString(), ioe);
+ }
try {
writeToGsa(uc, msg, useCompression);
String reply = readGsaReply(uc);