diff options
author | Jiri Vanek <[email protected]> | 2014-01-27 16:17:07 +0100 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2014-01-27 16:17:07 +0100 |
commit | fac61336d7d4f342458a8c0905b0aec56911de70 (patch) | |
tree | 11de1b337a0e7ee31dc0585f92636b5ef5fda548 | |
parent | 4394eef2518663d12672dbf593632cc29e6f37ec (diff) |
Tuning of properties loading.
Jnlp runtime now correctly dies in case of ConfigurationException and initialisation of config is failing to defaults instead of die with NoClassDefFoundError
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java | 42 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/resources/Messages.properties | 1 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java | 21 |
4 files changed, 64 insertions, 15 deletions
@@ -1,3 +1,18 @@ +2014-01-20 Jiri Vanek <[email protected]> + + Tuning of properties loading. + * netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java: added + (resetToDefaults) methods to set default values to map. + (loadSystemConfiguration) now throws ConfigurationException. Added more + verbose error messages. The ioexception is now also cause of ConfigurationException + if mandatory is on. + * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java: now correctly fails to + initiate if ConfigurationException appeared. + Init of (configuration) now catch general exception, and fall back to default + (instead of die fatally with NoClassDefFoundError). User is warned. + * netx/net/sourceforge/jnlp/resources/Messages.properties: new key of + (RFailingToDefault) added. + 2014-01-24 Andrew Azores <[email protected]> http://mail.openjdk.java.net/pipermail/distro-pkg-dev/2014-January/025971.html diff --git a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java index 3441fee..ae66457 100644 --- a/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java +++ b/netx/net/sourceforge/jnlp/config/DeploymentConfiguration.java @@ -215,6 +215,10 @@ public final class DeploymentConfiguration { public ConfigurationException getLoadingException() { return loadingException; } + + public void resetToDefaults() { + currentConfiguration = Defaults.getDefaults(); + } public enum ConfigType { @@ -495,7 +499,7 @@ public final class DeploymentConfiguration { * Reads the system configuration file and sets the relevant * system-properties related variables */ - private boolean loadSystemConfiguration(File configFile) { + private boolean loadSystemConfiguration(File configFile) throws ConfigurationException { OutputController.getLogger().log("Loading system configuation from: " + configFile); @@ -503,7 +507,7 @@ public final class DeploymentConfiguration { try { systemConfiguration = parsePropertiesFile(configFile); } catch (IOException e) { - OutputController.getLogger().log("No System level " + DEPLOYMENT_PROPERTIES + " found."); + OutputController.getLogger().log("No System level " + DEPLOYMENT_CONFIG_FILE + " found."); OutputController.getLogger().log(e); return false; } @@ -512,29 +516,36 @@ public final class DeploymentConfiguration { * at this point, we have read the system deployment.config file * completely */ - + String urlString = null; try { - String urlString = systemConfiguration.get("deployment.system.config").getValue(); - if (urlString == null) { - OutputController.getLogger().log("No System level " + DEPLOYMENT_PROPERTIES + " found."); + Setting<String> urlSettings = systemConfiguration.get("deployment.system.config"); + if (urlSettings == null || urlSettings.getValue() == null) { + OutputController.getLogger().log("No System level " + DEPLOYMENT_PROPERTIES + " found in "+configFile.getAbsolutePath()); return false; } + urlString = urlSettings.getValue(); + Setting<String> mandatory = systemConfiguration.get("deployment.system.config.mandatory"); + systemPropertiesMandatory = Boolean.valueOf(mandatory == null ? null : mandatory.getValue()); //never null + OutputController.getLogger().log("System level settings " + DEPLOYMENT_PROPERTIES + " are mandatory:" + systemPropertiesMandatory); URL url = new URL(urlString); if (url.getProtocol().equals("file")) { systemPropertiesFile = new File(url.getFile()); - OutputController.getLogger().log("Using System level" + DEPLOYMENT_PROPERTIES + ": " - + systemPropertiesFile); - Setting<String> mandatory = systemConfiguration.get("deployment.system.config.mandatory"); - systemPropertiesMandatory = Boolean.valueOf(mandatory == null ? null : mandatory.getValue()); + OutputController.getLogger().log("Using System level" + DEPLOYMENT_PROPERTIES + ": " + systemPropertiesFile); return true; } else { - OutputController.getLogger().log("Remote + " + DEPLOYMENT_PROPERTIES + " not supported"); + OutputController.getLogger().log("Remote + " + DEPLOYMENT_PROPERTIES + " not supported: " + urlString + "in " + configFile.getAbsolutePath()); return false; } } catch (MalformedURLException e) { - OutputController.getLogger().log("Invalid url for " + DEPLOYMENT_PROPERTIES); + OutputController.getLogger().log("Invalid url for " + DEPLOYMENT_PROPERTIES+ ": " + urlString + "in " + configFile.getAbsolutePath()); OutputController.getLogger().log(e); - return false; + if (systemPropertiesMandatory){ + ConfigurationException ce = new ConfigurationException("Invalid url to system properties, which are mandatory"); + ce.initCause(e); + throw ce; + } else { + return false; + } } } @@ -562,6 +573,11 @@ public final class DeploymentConfiguration { try { return parsePropertiesFile(file); } catch (IOException e) { + if (mandatory){ + ConfigurationException ce = new ConfigurationException("Exception during loading of " + file + " which is mandatory to read"); + ce.initCause(e); + throw ce; + } OutputController.getLogger().log(e); return null; } diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties index 3d22d2c..93a2bdf 100644 --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -179,6 +179,7 @@ RNestedJarExtration=Unable to extract nested jar. RUnexpected=Unexpected {0} at {1} RConfigurationError=Fatal error while reading the configuration, continuing with empty. Please fix RConfigurationFatal=ERROR: a fatal error has occurred while loading configuration. Perhaps a global configuration was required but could not be found +RFailingToDefault=Failing to default configuration RPRoxyPacNotSupported=Using Proxy Auto Config (PAC) files is not supported. RProxyFirefoxNotFound=Unable to use Firefox's proxy settings. Using "DIRECT" as proxy type. RProxyFirefoxOptionNotImplemented=Browser proxy option "{0}" ({1}) not supported yet. diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java index 12bcfa8..c9d7397 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java @@ -42,6 +42,7 @@ import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; +import javax.swing.JOptionPane; import javax.swing.UIManager; import javax.swing.text.html.parser.ParserDelegator; @@ -187,7 +188,13 @@ public class JNLPRuntime { JavaConsole.getConsole().showConsoleLater(); } /* exit if there is a fatal exception loading the configuration */ - if (isApplication && getConfiguration().getLoadingException() != null) { + if (getConfiguration().getLoadingException() != null) { + if (getConfiguration().getLoadingException() instanceof ConfigurationException){ + // ConfigurationException is thrown only if deployment.config's field + // deployment.system.config.mandatory is true, and the destination + //where deployment.system.config points is not readable + throw new RuntimeException(getConfiguration().getLoadingException()); + } OutputController.getLogger().log(OutputController.Level.WARNING_ALL, getMessage("RConfigurationError")+": "+getConfiguration().getLoadingException().getMessage()); } KeyStores.setConfiguration(getConfiguration()); @@ -364,9 +371,19 @@ public class JNLPRuntime { config.load(); config.copyTo(System.getProperties()); } catch (ConfigurationException ex) { - OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, getMessage("RConfigurationError")); + OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, Translator.R("RConfigurationError")); //mark this exceptionas we can die on it later config.setLoadingException(ex); + //to be sure - we MUST die - http://docs.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/properties.html + }catch(Exception t){ + //all exceptions are causing InstantiatizationError so this do it much more readble + OutputController.getLogger().log(OutputController.Level.ERROR_ALL, t); + OutputController.getLogger().log(OutputController.Level.WARNING_ALL, Translator.R("RFailingToDefault")); + if (!JNLPRuntime.isHeadless()){ + JOptionPane.showMessageDialog(null, getMessage("RFailingToDefault")+"\n"+t.toString()); + } + //try to survive this unlikely exception + config.resetToDefaults(); } finally { OutputController.getLogger().startConsumer(); } |