Search in sources :

Example 16 with MotechConfigurationException

use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.

the class BootstrapManagerImpl method readBootstrapConfigFromFile.

private BootstrapConfig readBootstrapConfigFromFile(File configFile, String errorMessage) {
    try {
        LOGGER.debug("Trying to load bootstrap configuration from " + configFile.getAbsolutePath());
        Properties properties = ConfigPropertiesUtils.getPropertiesFromFile(configFile);
        return BootstrapConfigPropertyMapper.fromProperties(properties);
    } catch (IOException e) {
        throw new MotechConfigurationException("Error loading bootstrap properties from config file " + configFile + " " + errorMessage, e);
    }
}
Also used : IOException(java.io.IOException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) Properties(java.util.Properties)

Example 17 with MotechConfigurationException

use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.

the class QueueURLValidator method validateUriContainSpecificScheme.

private void validateUriContainSpecificScheme(String queueUrl, URI uri) {
    String scheme = uri.getScheme();
    if (scheme != null && ("static".equals(scheme) || "broker".equals(scheme))) {
        if (isCompositeURI(uri)) {
            try {
                URISupport.CompositeData data = parseComposite(uri);
                validateCompositeDataUri(queueUrl, data);
            } catch (URISyntaxException e) {
                throw new MotechConfigurationException(URL_INVALID, e);
            }
        } else {
            isValidUri(queueUrl, uri.toString());
        }
    } else {
        isValidUri(queueUrl, uri.toString());
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) URISupport(org.apache.activemq.util.URISupport)

Example 18 with MotechConfigurationException

use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.

the class DbConfigManagerImpl method getProperties.

private Properties getProperties(String fileName, String varName, String descForLogs) {
    String configLocation = environment.getConfigDir();
    Properties properties;
    if (StringUtils.isNotBlank(configLocation)) {
        return readPropertiesFromFile(new File(configLocation, fileName), descForLogs);
    }
    properties = environment.getProperties(varName);
    if (properties != null && !properties.isEmpty()) {
        return properties;
    }
    LOGGER.debug("Could not find all {} configuration values from environment variables. So, trying to load from classpath", descForLogs);
    try {
        LOGGER.debug("Loading {} properties from default configuration directory", descForLogs);
        properties = loadPropertiesFromDefaultLocation(fileName, descForLogs);
    } catch (MotechConfigurationException e) {
        LOGGER.warn(e.getMessage());
    }
    LOGGER.debug("Loading {} properties from classpath", descForLogs);
    if (properties == null || properties.isEmpty()) {
        properties = loadPropertiesFromClasspath(fileName, descForLogs);
    }
    return properties;
}
Also used : MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) Properties(java.util.Properties) File(java.io.File)

Example 19 with MotechConfigurationException

use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.

the class ConfigLoader method loadMotechSettings.

/**
 * Loads MOTECH settings containing core platform settings.
 *
 * @return the {SettingsRecord} object
 */
public SettingsRecord loadMotechSettings() {
    SettingsRecord settingsRecord;
    ConfigLocation configLocation = coreConfigurationService.getConfigLocation();
    Resource configLocationResource = configLocation.toResource();
    try {
        Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME);
        settingsRecord = loadSettingsFromStream(motechSettings);
        settingsRecord.setFilePath(configLocationResource.getURL().getPath());
        checkSettingsRecord(settingsRecord);
    } catch (IOException e) {
        throw new MotechConfigurationException(String.format("Could not read settings from file at location %s", configLocation), e);
    }
    return settingsRecord;
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException)

Aggregations

MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)19 IOException (java.io.IOException)6 Test (org.junit.Test)5 Properties (java.util.Properties)4 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)4 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 URI (java.net.URI)2 URISupport (org.apache.activemq.util.URISupport)2 URISupport.isCompositeURI (org.apache.activemq.util.URISupport.isCompositeURI)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Resource (org.springframework.core.io.Resource)2 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1