Commit c9ef9d1b authored by Tom Evans's avatar Tom Evans

OF-850: Improve default initialization state

Minor changes to system utility classes to improve initial state of the
system, particularly during unit testing.
parent 2f2f5ba5
...@@ -29,6 +29,7 @@ import java.sql.PreparedStatement; ...@@ -29,6 +29,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement; import java.sql.Statement;
import java.util.MissingResourceException;
import org.jivesoftware.util.ClassUtils; import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
...@@ -619,6 +620,9 @@ public class DbConnectionManager { ...@@ -619,6 +620,9 @@ public class DbConnectionManager {
// Check to see if the database schema needs to be upgraded. // Check to see if the database schema needs to be upgraded.
schemaManager.checkOpenfireSchema(con); schemaManager.checkOpenfireSchema(con);
} }
catch (MissingResourceException mre) {
Log.error(mre.getMessage());
}
catch (Exception e) { catch (Exception e) {
Log.error(e.getMessage(), e); Log.error(e.getMessage(), e);
} }
......
...@@ -28,7 +28,6 @@ import java.sql.SQLException; ...@@ -28,7 +28,6 @@ import java.sql.SQLException;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -316,12 +315,6 @@ public class JiveGlobals { ...@@ -316,12 +315,6 @@ public class JiveGlobals {
if (openfireProperties == null) { if (openfireProperties == null) {
loadOpenfireProperties(); loadOpenfireProperties();
} }
// home not loaded?
if (openfireProperties == null) {
return null;
}
return openfireProperties.getProperty(name); return openfireProperties.getProperty(name);
} }
...@@ -349,11 +342,6 @@ public class JiveGlobals { ...@@ -349,11 +342,6 @@ public class JiveGlobals {
loadOpenfireProperties(); loadOpenfireProperties();
} }
// home not loaded?
if (openfireProperties == null) {
return defaultValue;
}
String value = openfireProperties.getProperty(name); String value = openfireProperties.getProperty(name);
if (value == null) { if (value == null) {
value = defaultValue; value = defaultValue;
...@@ -445,12 +433,8 @@ public class JiveGlobals { ...@@ -445,12 +433,8 @@ public class JiveGlobals {
if (openfireProperties == null) { if (openfireProperties == null) {
loadOpenfireProperties(); loadOpenfireProperties();
} }
// jiveHome not loaded?
if (openfireProperties != null) {
openfireProperties.setProperty(name, value); openfireProperties.setProperty(name, value);
} }
}
/** /**
* Sets multiple local properties at once. If a property doesn't already exists, a new * Sets multiple local properties at once. If a property doesn't already exists, a new
...@@ -472,11 +456,8 @@ public class JiveGlobals { ...@@ -472,11 +456,8 @@ public class JiveGlobals {
if (openfireProperties == null) { if (openfireProperties == null) {
loadOpenfireProperties(); loadOpenfireProperties();
} }
if (openfireProperties != null) {
openfireProperties.setProperties(propertyMap); openfireProperties.setProperties(propertyMap);
} }
}
/** /**
* Return all immediate children property values of a parent local property as a list of strings, * Return all immediate children property values of a parent local property as a list of strings,
...@@ -505,11 +486,6 @@ public class JiveGlobals { ...@@ -505,11 +486,6 @@ public class JiveGlobals {
loadOpenfireProperties(); loadOpenfireProperties();
} }
// jiveHome not loaded?
if (openfireProperties == null) {
return Collections.EMPTY_LIST;
}
String[] propNames = openfireProperties.getChildrenProperties(parent); String[] propNames = openfireProperties.getChildrenProperties(parent);
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
for (String propName : propNames) { for (String propName : propNames) {
...@@ -518,7 +494,6 @@ public class JiveGlobals { ...@@ -518,7 +494,6 @@ public class JiveGlobals {
values.add(value); values.add(value);
} }
} }
return values; return values;
} }
...@@ -531,12 +506,6 @@ public class JiveGlobals { ...@@ -531,12 +506,6 @@ public class JiveGlobals {
if (openfireProperties == null) { if (openfireProperties == null) {
loadOpenfireProperties(); loadOpenfireProperties();
} }
// jiveHome not loaded?
if (openfireProperties == null) {
return Collections.emptyList();
}
return openfireProperties.getAllPropertyNames(); return openfireProperties.getAllPropertyNames();
} }
...@@ -797,6 +766,9 @@ public class JiveGlobals { ...@@ -797,6 +766,9 @@ public class JiveGlobals {
if (isSetupMode()) { if (isSetupMode()) {
return; return;
} }
if (openfireProperties == null) {
loadOpenfireProperties();
}
openfireProperties.migrateProperty(name); openfireProperties.migrateProperty(name);
} }
...@@ -969,10 +941,18 @@ public class JiveGlobals { ...@@ -969,10 +941,18 @@ public class JiveGlobals {
openfireProperties = new XMLProperties(home + File.separator + getConfigName()); openfireProperties = new XMLProperties(home + File.separator + getConfigName());
} }
catch (IOException ioe) { catch (IOException ioe) {
Log.error(ioe.getMessage(), ioe); Log.error(ioe.getMessage());
failedLoading = true; failedLoading = true;
} }
} }
// create a default/empty XML properties set (helpful for unit testing)
if (openfireProperties == null) {
try {
openfireProperties = new XMLProperties();
} catch (IOException e) {
Log.error("Failed to setup default openfire properties", e);
}
}
} }
} }
...@@ -989,12 +969,6 @@ public class JiveGlobals { ...@@ -989,12 +969,6 @@ public class JiveGlobals {
msg.append("Critical Error! The home directory has not been configured, \n"); msg.append("Critical Error! The home directory has not been configured, \n");
msg.append("which will prevent the application from working correctly.\n\n"); msg.append("which will prevent the application from working correctly.\n\n");
System.err.println(msg.toString()); System.err.println(msg.toString());
try {
securityProperties = new XMLProperties();
} catch (IOException ioe) {
Log.error("Failed to setup default secuirty properties", ioe);
}
} }
// Create a manager with the full path to the security XML file. // Create a manager with the full path to the security XML file.
else { else {
...@@ -1014,10 +988,18 @@ public class JiveGlobals { ...@@ -1014,10 +988,18 @@ public class JiveGlobals {
}, 1000); }, 1000);
} }
catch (IOException ioe) { catch (IOException ioe) {
Log.error(ioe.getMessage(), ioe); Log.error(ioe.getMessage());
failedLoading = true; failedLoading = true;
} }
} }
// create a default/empty XML properties set (helpful for unit testing)
if (securityProperties == null) {
try {
securityProperties = new XMLProperties();
} catch (IOException e) {
Log.error("Failed to setup default security properties", e);
}
}
} }
} }
......
...@@ -741,6 +741,10 @@ public class XMLProperties { ...@@ -741,6 +741,10 @@ public class XMLProperties {
* used during the writing process for maximum safety. * used during the writing process for maximum safety.
*/ */
private synchronized void saveProperties() { private synchronized void saveProperties() {
if (file == null) {
Log.error("Unable to save XML properties; no file specified");
return;
}
boolean error = false; boolean error = false;
// Write data out to a temporary file first. // Write data out to a temporary file first.
File tempFile = null; File tempFile = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment