fix #7844 Add timeout to login dialog
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Oct 2018 11:43:40 +0000 (13:43 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 23 Oct 2018 11:43:40 +0000 (13:43 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/RemotingLoginDialog.java
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/ui/dialogs/CdmServerInfoTest.java

index f4cd608625a619a0d0fb589af288fb799354deef..e2ecfa793be2e3e6a15c4c8d4d4f6b4b08abbc10 100644 (file)
@@ -13,6 +13,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -272,21 +273,15 @@ public class CdmServerInfo {
         return null;
     }
 
-    public boolean pingServer() {
+    public boolean pingServer() throws CDMServerException, IOException {
         if(isLocalhostMgd()) {
             return true;
         }
-        try {
-            Socket s = new Socket(server, port);
-            logger.info("[CDM-Server] Available @ " + server + ":" + port );
-            updateInfo();
-            return true;
-        } catch (IOException ioe) {
-
-        } catch (CDMServerException e) {
-
-        }
-        return false;
+        Socket s = new Socket();
+        s.connect(new InetSocketAddress(server, port), 2000);
+        logger.info("[CDM-Server] Available @ " + server + ":" + port );
+        updateInfo();
+        return true;
     }
 
     public boolean pingInstance(CdmInstanceInfo instance, int port) throws CDMServerException  {
index c832de57e1ca8e297c884d8eb25b7b117dc34b88..caec734e0d74a1a846790662e5c5efa70cfc8315 100644 (file)
@@ -155,46 +155,129 @@ public class Messages extends NLS {
     public static String PresenceAbsenceTermDetailElement_COLOR_NOT_SET;
     public static String PresenceAbsenceTermDetailElement_LABEL_COLOR;
     public static String RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER;
+
+
     public static String RemotingLoginDialog_DEFAULT_LOGIN;
+
+
        public static String RemotingLoginDialog_LABEL_ADVANCED;
+
+
        public static String RemotingLoginDialog_LABEL_CDM_INSTANCE;
+
+
        public static String RemotingLoginDialog_LABEL_CDM_SERVER;
+
+
        public static String RemotingLoginDialog_LABEL_CONNECT;
+
+
        public static String RemotingLoginDialog_LABEL_EDITOR_CDM_VERSION;
+
+
        public static String RemotingLoginDialog_LABEL_EDITOR_CDMLIB_VERSION;
+
+
        public static String RemotingLoginDialog_LABEL_LOGIN;
+
+
        public static String RemotingLoginDialog_LABEL_LOGIN_COLON;
+
+
        public static String RemotingLoginDialog_LABEL_PASSWORD;
+
+
        public static String RemotingLoginDialog_LABEL_PORT;
+
+
        public static String RemotingLoginDialog_LABEL_REFRESH;
+
+
        public static String RemotingLoginDialog_LABEL_REMEMBER_ME;
+
+
        public static String RemotingLoginDialog_RETRIEVE_SERVER_INSTANCES;
+
+
        public static String RemotingLoginDialog_LABEL_SERVER_CDM_VERSION;
+
+
        public static String RemotingLoginDialog_LABEL_SERVER_CDMLIB_VERSION;
+
+
        public static String RemotingLoginDialog_LABEL_STOP_MANAGED_SERVER;
+
+
        public static String RemotingLoginDialog_LOGIN_CANNOT_BE_EMPTY;
+
+
        public static String RemotingLoginDialog_MESSAGE_PORT_SHOULD_BE_INTEGER;
+
+
        public static String RemotingLoginDialog_PASSWORD_CANNOT_BE_EMPTY;
+
+
        public static String RemotingLoginDialog_SERVER_LAUNCH_ERROR;
+
+
        public static String RemotingLoginDialog_STATUS_AVAILABLE;
+
+
        public static String RemotingLoginDialog_STATUS_CHECKING;
+
+
        public static String RemotingLoginDialog_STATUS_ERROR;
        public static String RemotingLoginDialog_STATUS_NO_INSTANCES_FOUND;
+
+
        public static String RemotingLoginDialog_STATUS_NOT_AVAILABLE;
+
+
        public static String RemotingLoginDialog_STATUS_NOT_COMPATIBLE;
+
+
        public static String RemotingLoginDialog_STATUS_NOT_STARTED;
+
+
        public static String RemotingLoginDialog_STATUS_REMOTING_NOT_ACTIVATED;
        public static String RemotingLoginDialog_STATUS_RETRIEVING;
+
+
        public static String RemotingLoginDialog_STATUS_STARTED;
+
+
        public static String RemotingLoginDialog_UPDATE_EDITOR;
-       public static String RemotingLoginDialog_COULD_NOT_STOP_SERVER;
+
+
+       public static String RemotingLoginDialog_CONNECTION_FAILED_MESSAGE;
+
+
+    public static String RemotingLoginDialog_CONNECTION_FAILED_TITLE;
+
+
+    public static String RemotingLoginDialog_COULD_NOT_STOP_SERVER;
+
+
        public static String RemotingLoginDialog_ERROR_GENERATING_CONFIG_FILE;
+
+
        public static String RemotingLoginDialog_ERROR_STARTING_SERVER;
+
+
        public static String RemotingLoginDialog_ERROR_STOPPING_SERVER;
+
+
        public static String RemotingLoginDialog_GENERATING_CONFIG_FILE;
+
+
        public static String RemotingLoginDialog_JOB_SERVER_LAUNCH;
+
+
        public static String RemotingLoginDialog_STARTING_MGD_SERVER;
+
        public static String RemotingLoginDialog_TASK_LAUNCHING_SERVER;
+
+
     public static String SearchManager_LARGE_RESULT_EXPECTED;
     public static String SearchManager_LONG_SEARCH_WARNING;
        public static String SupplementalDataViewPart_VIEWER_NAME;
index c6de25a4c0b8c1f6f528a1a1814fb988052e4c5c..57817e185371ec29419a853d459ae81fcc226281 100644 (file)
@@ -80,6 +80,8 @@ CdmStoreConnector_UPDATE_DATASOUREC_OR_CHOOSE_NEW_DATASOURCE=Please update the c
 CdmStoreConnector_UPDATE_EDITOR_OR_CHOOSE_COMPATIBLE_DATASOURCE=Please update the Taxonomic Editor (Help->Check for Updates) or choose a compatible datasource
 ConfiguratorComposite_CONFIGURE=Configure
 
+RemotingLoginDialog_CONNECTION_FAILED_MESSAGE=Could not connect to CDM Server.
+RemotingLoginDialog_CONNECTION_FAILED_TITLE=Connection failed
 RemotingLoginDialog_DEFAULT_LOGIN=Default: %s (login), %s (password)
 RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER=Please choose a compatible cdm-server or update the chosen cdm-server
 RemotingLoginDialog_LABEL_ADVANCED=advanced
index 8ac1ed053e6c40e2cccb36a875f7a112e7aba7a7..4a41dcde6c6fbca700c4ce20ec8cf3d6d14a5f69 100644 (file)
@@ -80,6 +80,8 @@ CdmStoreConnector_UPDATE_DATASOUREC_OR_CHOOSE_NEW_DATASOURCE=Bitte aktualisieren
 CdmStoreConnector_UPDATE_EDITOR_OR_CHOOSE_COMPATIBLE_DATASOURCE=Bitte aktualisieren Sie den Taxonomic Editor (Hilfe->Suche nach Updates) oder wählen sie eine kompatible Datenquelle
 ConfiguratorComposite_CONFIGURE=Einstellungen
 
+RemotingLoginDialog_CONNECTION_FAILED_MESSAGE=Eine Verbindung zum CDM-Server konnte nicht hergestellt werden.
+RemotingLoginDialog_CONNECTION_FAILED_TITLE=Verbindung fehlgeschlagen
 RemotingLoginDialog_DEFAULT_LOGIN=Standard: %s (Login), %s (Kennwort)
 RemotingLoginDialog_CHOOSE_COMPATIBLE_CDM_SERVER=Bitte wählen Sie einen kompatiblen CDM-Server oder aktualisieren sie den CDM-Server
 RemotingLoginDialog_LABEL_ADVANCED=Erweitert
index 060ac6292ca7e75c5eb71c65cdd3e402e5b58171..c66bc40e2531e5800de8f43937df02d78f711488 100644 (file)
@@ -88,11 +88,11 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
     /**
      *
      */
-    private static final String DEFAULT_PASS = "00000";
+    private static final String DEFAULT_PASS = "00000"; //$NON-NLS-1$
     /**
      *
      */
-    private static final String DEFAULT_USER = "admin";
+    private static final String DEFAULT_USER = "admin"; //$NON-NLS-1$
     private static final String UBUNTU = "Ubuntu"; //$NON-NLS-1$
        protected Object result;
     protected Shell shlConnect;
@@ -591,15 +591,21 @@ public class RemotingLoginDialog extends Dialog implements ICDMServerError {
                     txtPort.setEditable(true);
                     txtPort.setEnabled(true);
                 }
-                if(selectedCsii.pingServer()) {
-                    txtCdmServerStatus.setText(STATUS_AVAILABLE);
-                    populateCdmInstanceCombo(true);
-                    String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
-                    txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
-                } else {
-                    txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
-                    comboCdmInstance.removeAll();
-                    disableCdmInstanceControls("", "");
+                try {
+                    if(selectedCsii.pingServer()) {
+                        txtCdmServerStatus.setText(STATUS_AVAILABLE);
+                        populateCdmInstanceCombo(true);
+                        String serverVersionTimestamp = generateLastModifiedTooltip(selectedCsii.getCdmlibLastModified());
+                        txtServerVersion.setText(selectedCsii.getCdmlibServicesVersion() + ":" + serverVersionTimestamp); //$NON-NLS-1$
+                    } else {
+                        txtCdmServerStatus.setText(STATUS_NOT_AVAILABLE);
+                        comboCdmInstance.removeAll();
+                        disableCdmInstanceControls("", ""); //$NON-NLS-1$ //$NON-NLS-2$
+                    }
+                } catch (CDMServerException | IOException e) {
+                    MessagingUtils.errorDialog(Messages.RemotingLoginDialog_CONNECTION_FAILED_TITLE, this,
+                            Messages.RemotingLoginDialog_CONNECTION_FAILED_MESSAGE,
+                            TaxeditorStorePlugin.PLUGIN_ID, e, true, true);
                 }
             }
             updatePort();
index d294c17dd1754111c14fc251f7a733573fac2844..3c4297b2a8cd377e210e5b4a12365dea5667166b 100644 (file)
@@ -8,6 +8,7 @@
  */
 package eu.etaxonomy.taxeditor.ui.dialogs;
 
+import java.io.IOException;
 import java.util.List;
 
 import org.junit.Assert;
@@ -31,7 +32,7 @@ import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfoConfig;
 public class CdmServerInfoTest extends UnitilsJUnit4 {
 
     @Test
-    public void pingServersTest() {
+    public void pingServersTest() throws CDMServerException, IOException {
         List<CdmServerInfo> servers = CdmServerInfo.getCdmServers();
         for(CdmServerInfo server : servers) {
             server.pingServer();