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);
}
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations