Search in sources :

Example 16 with MotechException

use of org.motechproject.commons.api.MotechException in project motech by motech.

the class MotechMBeanServer method getBrokerViewMBean.

private BrokerViewMBean getBrokerViewMBean(String mBeanName) {
    try {
        ObjectName activeMQ = new ObjectName(mBeanName);
        BrokerViewMBean brokerViewMBean = MBeanServerInvocationHandler.newProxyInstance(openConnection(), activeMQ, BrokerViewMBean.class, true);
        LOGGER.info("Retrieving BrokerViewMBean from Broker version: " + brokerViewMBean.getBrokerVersion());
        return brokerViewMBean;
    } catch (MalformedObjectNameException ex) {
        throw new MotechException(ex.getMessage(), ex);
    }
}
Also used : BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) MotechException(org.motechproject.commons.api.MotechException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName)

Example 17 with MotechException

use of org.motechproject.commons.api.MotechException in project motech by motech.

the class MotechMBeanServer method createConnection.

private void createConnection() {
    try {
        JMXConnector jmxc = JMXConnectorFactory.connect(new JMXServiceURL(getUrl()));
        connection = jmxc.getMBeanServerConnection();
    } catch (IOException ioEx) {
        throw new MotechException(String.format("JMX connection could not be acquired from url %s", getUrl()), ioEx);
    }
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) MotechException(org.motechproject.commons.api.MotechException) JMXConnector(javax.management.remote.JMXConnector) IOException(java.io.IOException)

Example 18 with MotechException

use of org.motechproject.commons.api.MotechException in project motech by motech.

the class StartupManager method syncSettingsWithDb.

private void syncSettingsWithDb() {
    try {
        if (dbSettings.getLastRun() == null) {
            markPlatformStateAs(FIRST_RUN);
        } else {
            markPlatformStateAs(NORMAL_RUN);
        }
        if (isFirstRun() || motechSettings == null || !motechSettings.getConfigFileChecksum().equals(dbSettings.getConfigFileChecksum())) {
            LOGGER.info("Updating database startup");
            dbSettings.updateSettings(motechSettings.getConfigFileChecksum(), motechSettings.getFilePath(), motechSettings.asProperties());
        }
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            dbSettings.setConfigFileChecksum(new String(digest.digest(dbSettings.asProperties().toString().getBytes())));
        } catch (NoSuchAlgorithmException e) {
            throw new MotechException("MD5 algorithm not available", e);
        }
        dbSettings.setLastRun(DateTime.now());
        dbSettings.setPlatformInitialized(true);
        configurationService.savePlatformSettings(dbSettings);
    } catch (RuntimeException e) {
        LOGGER.error(e.getMessage(), e);
        markPlatformStateAs(DB_ERROR);
    }
}
Also used : MotechException(org.motechproject.commons.api.MotechException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 19 with MotechException

use of org.motechproject.commons.api.MotechException in project motech by motech.

the class FileSystemAwareUIHttpContext method getResource.

@Override
public URL getResource(String name) {
    File resourceFile = new File(resourceRootDirectoryPath, name);
    String resourcePath = resourceFile.getAbsolutePath();
    LOGGER.info("Using FileSystemAwareUIHttpContext to deliver resource " + resourcePath);
    if (resourceFile.exists()) {
        try {
            if (LOGGER.isDebugEnabled()) {
                print(resourceFile);
            }
            return resourceFile.toURI().toURL();
        } catch (IOException e) {
            throw new MotechException(format("Exception when try to resolve %s", resourcePath), e);
        }
    }
    LOGGER.warn("Resource " + resourcePath + " does not exist");
    return getContext().getResource(name);
}
Also used : MotechException(org.motechproject.commons.api.MotechException) IOException(java.io.IOException) File(java.io.File)

Example 20 with MotechException

use of org.motechproject.commons.api.MotechException in project motech by motech.

the class BundleContextWrapper method getBundleApplicationContext.

/**
 * Returns the Spring {@link org.springframework.context.ApplicationContext} created by Blueprint for the
 * bundle the underlying bundle context comes from. The context is retrieved from the bundle context, since
 * Blueprint publishes application contexts as OSGi services.
 * @return the context created by Blueprint for the bundle the underlying context comes from, or null if there is no context
 */
public ApplicationContext getBundleApplicationContext() {
    ApplicationContext applicationContext = null;
    String filter = String.format("(%s=%s)", CONTEXT_SERVICE_NAME, getCurrentBundleSymbolicName());
    ServiceReference[] serviceReferences;
    try {
        serviceReferences = bundleContext.getServiceReferences(ApplicationContext.class.getName(), filter);
    } catch (InvalidSyntaxException e) {
        throw new MotechException(e.getMessage(), e);
    }
    if (ArrayUtils.isNotEmpty(serviceReferences)) {
        applicationContext = (ApplicationContext) bundleContext.getService(serviceReferences[0]);
    }
    if (applicationContext != null) {
        LOGGER.debug("Application context is " + applicationContext.getDisplayName());
    }
    return applicationContext;
}
Also used : MotechException(org.motechproject.commons.api.MotechException) ApplicationContext(org.springframework.context.ApplicationContext) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

MotechException (org.motechproject.commons.api.MotechException)33 IOException (java.io.IOException)25 InputStream (java.io.InputStream)9 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)6 MessageDigest (java.security.MessageDigest)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 HashMap (java.util.HashMap)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 Map (java.util.Map)3 ObjectName (javax.management.ObjectName)3 SettingsRecord (org.motechproject.config.domain.SettingsRecord)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStream (java.io.OutputStream)2 DigestInputStream (java.security.DigestInputStream)2 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)2 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)2 Bundle (org.osgi.framework.Bundle)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Resource (org.springframework.core.io.Resource)2