changeset 967:2dc71d3fbeed

Make GUI prompt with dialog on wrong URL in prefs. Reviewed-by: vanaltj Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-February/005495.html PR1294
author Severin Gehwolf <sgehwolf@redhat.com>
date Fri, 08 Feb 2013 19:09:24 +0100
parents bab2eabfab98
children 23df86b8f59a
files client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java
diffstat 1 files changed, 30 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Mon Feb 11 16:56:46 2013 -0500
+++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/Main.java	Fri Feb 08 19:09:24 2013 +0100
@@ -71,6 +71,7 @@
 import com.redhat.thermostat.storage.core.Connection.ConnectionStatus;
 import com.redhat.thermostat.storage.core.DbService;
 import com.redhat.thermostat.storage.core.DbServiceFactory;
+import com.redhat.thermostat.storage.core.StorageException;
 import com.redhat.thermostat.storage.dao.HostInfoDAO;
 import com.redhat.thermostat.storage.dao.VmInfoDAO;
 import com.redhat.thermostat.utils.keyring.Keyring;
@@ -114,8 +115,17 @@
         this.appSvc = appSvc;
         this.uiFacadeFactory = uiFacadeFactory;
         this.dbServiceFactory = dbServiceFactory;
-        this.dbService = dbServiceFactory.createDbService(username, password,
+        try {
+            // See IcedTea BZ#1294
+            // This may throw a StorageException if no suitable storage provider
+            // is registered. This most likely means a user has a wrong
+            // connection-url saved in her preferences. Continue, and catch
+            // this case in ConnectionSetup#run()
+            this.dbService = dbServiceFactory.createDbService(username, password,
                 connectionURL);
+        } catch (StorageException e) {
+            logger.log(Level.WARNING, "Error looking up storage provider", e);
+        }
     }
 
     private void setLAF() {
@@ -200,6 +210,12 @@
         @Override
         public void run() {
             ConnectionListener connectionListener = new ConnectionHandler(service);
+            // dbService may be null at this point (see constructor). Fire
+            // failed connection attempt immediately.
+            if (dbService == null) {
+                connectionListener.changed(ConnectionStatus.FAILED_TO_CONNECT);
+                return;
+            }
             dbService.addConnectionListener(connectionListener);
             try {
                 dbService.connect();
@@ -270,9 +286,19 @@
         
         @Override
         public void reconnect(ClientPreferences prefs) {
-            // Recreate DbService with potentially modified parameters
-            dbService = dbServiceFactory.createDbService(prefs.getUserName(), prefs.getPassword(), prefs.getConnectionUrl());
-            dbService.addConnectionListener(new ConnectionHandler(service));
+            ConnectionHandler connectionListener = new ConnectionHandler(service);
+            try {
+                // Recreate DbService with potentially modified parameters.
+                dbService = dbServiceFactory.createDbService(prefs.getUserName(), prefs.getPassword(), prefs.getConnectionUrl());
+            } catch (StorageException e) {
+                // Prevent Icedtea BZ#1294, where no matching StorageProvider
+                // could potentially be found for the given connection URL.
+                // Indicate connection failure immediately.
+                logger.log(Level.WARNING, "Error looking up storage provider", e);
+                connectionListener.changed(ConnectionStatus.FAILED_TO_CONNECT);
+                return;
+            }
+            dbService.addConnectionListener(connectionListener);
             connect(service);
         }