use of org.springframework.context.ApplicationContext in project druid by alibaba.
the class DruidStatServiceTest method test_statService_getSpringDetail.
public void test_statService_getSpringDetail() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:com/alibaba/druid/stat/spring-config-stat.xml");
UserService userService = (UserService) context.getBean("userService");
userService.save();
String result = DruidStatService.getInstance().service("/spring-detail.json?class=com.alibaba.druid.stat.spring.UserService&method=save()");
Map<String, Object> resultMap = (Map<String, Object>) JSONUtils.parse(result);
Map<String, Object> contentMap = (Map<String, Object>) resultMap.get("Content");
assertThat((Integer) contentMap.get("ExecuteCount"), equalTo(1));
// second test
userService.save();
result = DruidStatService.getInstance().service("/spring-detail.json?class=com.alibaba.druid.stat.spring.UserService&method=save()");
resultMap = (Map<String, Object>) JSONUtils.parse(result);
contentMap = (Map<String, Object>) resultMap.get("Content");
assertThat((Integer) contentMap.get("ExecuteCount"), equalTo(2));
}
use of org.springframework.context.ApplicationContext in project dubbo by alibaba.
the class SpringStatusChecker method check.
public Status check() {
ApplicationContext context = ServiceBean.getSpringContext();
if (context == null) {
return new Status(Status.Level.UNKNOWN);
}
Status.Level level = Status.Level.OK;
if (context instanceof Lifecycle) {
if (((Lifecycle) context).isRunning()) {
level = Status.Level.OK;
} else {
level = Status.Level.ERROR;
}
} else {
level = Status.Level.UNKNOWN;
}
StringBuilder buf = new StringBuilder();
try {
Class<?> cls = context.getClass();
Method method = null;
while (cls != null && method == null) {
try {
method = cls.getDeclaredMethod("getConfigLocations", new Class<?>[0]);
} catch (NoSuchMethodException t) {
cls = cls.getSuperclass();
}
}
if (method != null) {
if (!method.isAccessible()) {
method.setAccessible(true);
}
String[] configs = (String[]) method.invoke(context, new Object[0]);
if (configs != null && configs.length > 0) {
for (String config : configs) {
if (buf.length() > 0) {
buf.append(",");
}
buf.append(config);
}
}
}
} catch (Throwable t) {
logger.warn(t.getMessage(), t);
}
return new Status(level, buf.toString());
}
use of org.springframework.context.ApplicationContext in project head by mifos.
the class ETLReportDWHelper method execute.
@Override
public void execute(final long timeInMillis) throws BatchJobException {
new ApplicationContextHolder();
ArrayList<String> errors = new ArrayList<String>();
ApplicationContext ach = ApplicationContextHolder.getApplicationContext();
DriverManagerDataSource ds = (DriverManagerDataSource) ach.getBean("dataSource");
DriverManagerDataSource dsDW = (DriverManagerDataSource) ach.getBean("dataSourcePentahoDW");
Pattern pat = Pattern.compile(DATA_WAREHOUSE_DB_NAME_PATTERN);
Matcher m = pat.matcher(dsDW.getUrl());
String nameOfDataBase = null;
if (m.find()) {
nameOfDataBase = m.group(6);
}
if (!nameOfDataBase.equals("")) {
try {
dsDW.getConnection();
} catch (SQLException ex) {
errors.add("Data Warehouse is not configured");
throw new BatchJobException("Data warehouse database", errors);
}
ConfigurationLocator configurationLocator = new ConfigurationLocator();
String configPath = configurationLocator.getConfigurationDirectory();
createPropertiesFileForPentahoDWReports(ds, dsDW);
String path = configPath + "/ETL/MifosDataWarehouseETL/" + FILENAME;
String jarPath = configPath + "/ETL/mifos-etl-plugin-1.0-SNAPSHOT.one-jar.jar";
String javaHome = System.getProperty("java.home") + "/bin/java";
String pathToLog = configPath + "/ETL/log";
if (File.separatorChar == '\\') {
// windows platform
javaHome = javaHome.replaceAll("/", "\\\\");
javaHome = '"' + javaHome + '"';
jarPath = jarPath.replaceAll("/", "\\\\");
path = path.replaceAll("/", "\\\\");
pathToLog = pathToLog.replaceAll("/", "\\\\");
}
PrintWriter fw = null;
try {
boolean hasErrors = false;
boolean notRun = true;
ProcessBuilder processBuilder = new ProcessBuilder(javaHome, "-jar", jarPath, path, "false", dsDW.getUsername(), dsDW.getPassword(), dsDW.getUrl());
processBuilder.redirectErrorStream(true);
Process p = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
if (new File(pathToLog).exists()) {
new File(pathToLog).delete();
}
File file = new File(pathToLog);
fw = new PrintWriter(file);
while ((line = reader.readLine()) != null) {
fw.println(line);
if (line.matches("^ERROR.*")) {
hasErrors = true;
}
notRun = false;
}
if (notRun) {
errors.add("Data Warehouse is not configured properly");
throw new BatchJobException("Data warehouse database", errors);
}
if (hasErrors) {
errors.add("ETL error, for more details see log file: " + pathToLog);
throw new BatchJobException("ETL error", errors);
}
} catch (IOException ex) {
throw new BatchJobException(ex.getCause());
} finally {
if (fw != null) {
fw.close();
}
}
} else {
errors.add("Data Warehouse is not configured");
throw new BatchJobException("Data warehouse database", errors);
}
}
use of org.springframework.context.ApplicationContext in project head by mifos.
the class ApplicationInitializer method init.
public void init(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
try {
// prevent ehcache "phone home"
System.setProperty("net.sf.ehcache.skipUpdateCheck", "true");
// prevent quartz "phone home"
System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
synchronized (ApplicationInitializer.class) {
ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
if (servletContext != null) {
dbUpgrade(applicationContext);
}
initJNDIforPentaho(applicationContext);
setAttributesOnContext(servletContext);
copyResources(servletContext);
copyLogo(servletContext);
}
} catch (Exception e) {
String errMsgStart = "unable to start Mifos web application";
if (null == logger) {
System.err.println(errMsgStart + " and logger is not available!");
e.printStackTrace();
} else {
logger.error(errMsgStart, e);
}
throw new Error(e);
}
logger.info("Mifos is ready.");
}
use of org.springframework.context.ApplicationContext in project head by mifos.
the class DashboardServiceFacadeWebTier method getCustomerHeaders.
@Override
public String[] getCustomerHeaders() {
String[] headers = new String[5];
Locale locale = getLocale();
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Locale prefferedLocale = Localization.getInstance().getLocaleById(user.getPreferredLocaleId());
if (prefferedLocale != null) {
locale = prefferedLocale;
}
ApplicationContext context = ApplicationContextHolder.getApplicationContext();
headers[0] = context.getMessage("DashboardDetail.GlobalNumber", null, locale);
headers[1] = context.getMessage("DashboardDetail.ClientName", null, locale);
headers[2] = context.getMessage("DashboardDetail.State", null, locale);
headers[3] = context.getMessage("DashboardDetail.LoanOfficer", null, locale);
headers[4] = context.getMessage("DashboardDetail.LoanBalance", null, locale);
return headers;
}
Aggregations