use of org.motechproject.commons.api.MotechException in project motech by motech.
the class SettingsFacade method registerProperties.
/**
* Registers properties from file with given name to the configuration service.
*
* @param filename the name of the file with properties
* @param properties properties to be registered
*/
protected void registerProperties(String filename, Properties properties) {
if (configurationService != null) {
try {
if (!configurationService.registersProperties(getBundleSymbolicName(), filename)) {
configurationService.addOrUpdateProperties(getBundleSymbolicName(), getBundleVersion(), filename, properties, defaultConfig.get(filename));
} else if (configurationService.registersProperties(getBundleSymbolicName(), filename)) {
configurationService.updatePropertiesAfterReinstallation(getBundleSymbolicName(), getBundleVersion(), filename, defaultConfig.get(filename), properties);
}
Properties registeredProps = configurationService.getBundleProperties(getBundleSymbolicName(), filename, defaultConfig.get(filename));
config.put(filename, registeredProps);
} catch (IOException e) {
throw new MotechException("Cant register settings", e);
}
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class ConfigLoader method loadSettingsFromStream.
private SettingsRecord loadSettingsFromStream(Resource motechSettings) {
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
try (DigestInputStream dis = new DigestInputStream(motechSettings.getInputStream(), digest)) {
// load configFileSettings and calculate MD5 hash
SettingsRecord settingsRecord = new SettingsRecord();
settingsRecord.load(dis);
settingsRecord.setConfigFileChecksum(new String(digest.digest()));
// startup loaded
return settingsRecord;
} catch (IOException e) {
throw new MotechException("Error loading configuration", e);
}
} catch (NoSuchAlgorithmException e) {
throw new MotechException("MD5 algorithm not available", e);
}
}
use of org.motechproject.commons.api.MotechException in project motech by motech.
the class BundleIconServiceImpl method loadBundleIcon.
private BundleIcon loadBundleIcon(URL iconURL) {
InputStream is = null;
try {
URLConnection urlConn = iconURL.openConnection();
is = urlConn.getInputStream();
String mime = urlConn.getContentType();
byte[] image = IOUtils.toByteArray(is);
return new BundleIcon(image, mime);
} catch (IOException e) {
throw new MotechException("Error loading icon.", e);
} finally {
IOUtils.closeQuietly(is);
}
}
Aggregations