From 06b0a511fd8d009392b688d65c8a474cde500e65 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Fri, 30 Jul 2010 12:57:02 +0000
Subject: [PATCH] Improves error message printed when the client tools time out during  the establishment of the connection.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
index 5cdcf93..5310fe2 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPToolUtils.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2006-2009 Sun Microsystems, Inc.
+ *      Copyright 2006-2010 Sun Microsystems, Inc.
  */
 package org.opends.server.tools;
 import org.opends.messages.Message;
@@ -31,7 +31,9 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.net.SocketTimeoutException;
 
+import org.opends.server.protocols.asn1.ASN1Exception;
 import org.opends.server.protocols.ldap.LDAPControl;
 import org.opends.server.protocols.ldap.LDAPResultCode;
 import org.opends.server.types.DN;
@@ -277,5 +279,43 @@
       err.println(ERR_TOOL_MATCHED_DN.get(matchedDN.toString()));
     }
   }
+
+  /**
+   * Returns the message to be displayed to the user when an exception occurs.
+   * <br>
+   * The code simply checks that the exception corresponds to a client side
+   * time out.
+   * @param ae the asn1exception that occurred connecting to the server or
+   * handling the response from the server.
+   * @return the message to be displayed to the user when an exception occurs.
+   */
+  public static String getMessageForConnectionException(ASN1Exception ae)
+  {
+    String msg;
+    Throwable cause = ae.getCause();
+    if (cause != null)
+    {
+      boolean isTimeout = false;
+      while (cause != null && !isTimeout)
+      {
+        isTimeout = cause instanceof SocketTimeoutException;
+        cause = cause.getCause();
+      }
+      if (isTimeout)
+      {
+        msg = ERR_CLIENT_SIDE_TIMEOUT.get(
+            ae.getMessageObject().toString()).toString();
+      }
+      else
+      {
+        msg = ae.getMessageObject().toString();
+      }
+    }
+    else
+    {
+      msg = ae.getMessageObject().toString();
+    }
+    return msg;
+  }
 }
 

--
Gitblit v1.10.0