use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class AdministrationServiceImpl method getSystemInformation.
/**
* @see org.openmrs.api.AdministrationService#getSystemInformation()
*/
@Override
@Transactional(readOnly = true)
public Map<String, Map<String, String>> getSystemInformation() throws APIException {
Map<String, Map<String, String>> systemInfoMap = new LinkedHashMap<>();
systemInfoMap.put("SystemInfo.title.openmrsInformation", new LinkedHashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("SystemInfo.OpenMRSInstallation.systemDate", new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
put("SystemInfo.OpenMRSInstallation.systemTime", new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()));
put("SystemInfo.OpenMRSInstallation.openmrsVersion", OpenmrsConstants.OPENMRS_VERSION);
try {
put("SystemInfo.hostname", InetAddress.getLocalHost().getCanonicalHostName());
} catch (UnknownHostException e) {
put("SystemInfo.hostname", "Unknown host: " + e.getMessage());
}
}
});
systemInfoMap.put("SystemInfo.title.javaRuntimeEnvironmentInformation", new LinkedHashMap<String, String>() {
Properties properties = System.getProperties();
private static final long serialVersionUID = 1L;
{
put("SystemInfo.JavaRuntimeEnv.operatingSystem", properties.getProperty("os.name"));
put("SystemInfo.JavaRuntimeEnv.operatingSystemArch", properties.getProperty("os.arch"));
put("SystemInfo.JavaRuntimeEnv.operatingSystemVersion", properties.getProperty("os.version"));
put("SystemInfo.JavaRuntimeEnv.javaVersion", properties.getProperty("java.version"));
put("SystemInfo.JavaRuntimeEnv.javaVendor", properties.getProperty("java.vendor"));
put("SystemInfo.JavaRuntimeEnv.jvmVersion", properties.getProperty("java.vm.version"));
put("SystemInfo.JavaRuntimeEnv.jvmVendor", properties.getProperty("java.vm.vendor"));
put("SystemInfo.JavaRuntimeEnv.javaRuntimeName", properties.getProperty("java.runtime.name"));
put("SystemInfo.JavaRuntimeEnv.javaRuntimeVersion", properties.getProperty("java.runtime.version"));
put("SystemInfo.JavaRuntimeEnv.userName", properties.getProperty("user.name"));
put("SystemInfo.JavaRuntimeEnv.systemLanguage", properties.getProperty("user.language"));
put("SystemInfo.JavaRuntimeEnv.systemTimezone", properties.getProperty("user.timezone"));
put("SystemInfo.JavaRuntimeEnv.fileSystemEncoding", properties.getProperty("sun.jnu.encoding"));
put("SystemInfo.JavaRuntimeEnv.userDirectory", properties.getProperty("user.dir"));
put("SystemInfo.JavaRuntimeEnv.tempDirectory", properties.getProperty("java.io.tmpdir"));
}
});
systemInfoMap.put("SystemInfo.title.memoryInformation", new LinkedHashMap<String, String>() {
private static final long serialVersionUID = 1L;
Runtime runtime = Runtime.getRuntime();
{
put("SystemInfo.Memory.totalMemory", convertToMegaBytes(runtime.totalMemory()));
put("SystemInfo.Memory.freeMemory", convertToMegaBytes(runtime.freeMemory()));
put("SystemInfo.Memory.maximumHeapSize", convertToMegaBytes(runtime.maxMemory()));
}
});
systemInfoMap.put("SystemInfo.title.dataBaseInformation", new LinkedHashMap<String, String>() {
Properties properties = Context.getRuntimeProperties();
private static final long serialVersionUID = 1L;
{
put("SystemInfo.Database.name", OpenmrsConstants.DATABASE_NAME);
put("SystemInfo.Database.connectionURL", properties.getProperty("connection.url"));
put("SystemInfo.Database.userName", properties.getProperty("connection.username"));
put("SystemInfo.Database.driver", properties.getProperty("hibernate.connection.driver_class"));
put("SystemInfo.Database.dialect", properties.getProperty("hibernate.dialect"));
}
});
systemInfoMap.put("SystemInfo.title.moduleInformation", new LinkedHashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("SystemInfo.Module.repositoryPath", ModuleUtil.getModuleRepository().getAbsolutePath());
Collection<Module> loadedModules = ModuleFactory.getLoadedModules();
for (Module module : loadedModules) {
String moduleInfo = module.getVersion() + " " + (module.isStarted() ? "" : Context.getMessageSourceService().getMessage("Module.notStarted"));
put(module.getName(), moduleInfo);
}
}
});
return systemInfoMap;
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class ModuleServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.debug("In service method for module servlet: " + request.getPathInfo());
String servletName = request.getPathInfo();
int end = servletName.indexOf("/", 1);
String moduleId = null;
if (end > 0) {
moduleId = servletName.substring(1, end);
}
log.debug("ModuleId: " + moduleId);
Module mod = ModuleFactory.getModuleById(moduleId);
// where in the path to start trimming
int start = 1;
if (mod != null) {
log.debug("Module with id " + moduleId + " found. Looking for servlet name after " + moduleId + " in url path");
start = moduleId.length() + 2;
// this skips over the moduleId that is in the path
}
end = servletName.indexOf("/", start);
if (end == -1 || end > servletName.length()) {
end = servletName.length();
}
servletName = servletName.substring(start, end);
log.debug("Servlet name: " + servletName);
HttpServlet servlet = WebModuleUtil.getServlet(servletName);
if (servlet == null) {
log.warn("No servlet with name: " + servletName + " was found");
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
}
servlet.service(request, response);
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class Listener method performWebStartOfModules.
public static void performWebStartOfModules(Collection<Module> startedModules, ServletContext servletContext) throws ModuleMustStartException, Exception {
boolean someModuleNeedsARefresh = false;
for (Module mod : startedModules) {
try {
boolean thisModuleCausesRefresh = WebModuleUtil.startModule(mod, servletContext, /* delayContextRefresh */
true);
someModuleNeedsARefresh = someModuleNeedsARefresh || thisModuleCausesRefresh;
} catch (Exception e) {
mod.setStartupErrorMessage("Unable to start module", e);
}
}
if (someModuleNeedsARefresh) {
try {
WebModuleUtil.refreshWAC(servletContext, true, null);
} catch (ModuleMustStartException | BeanCreationException ex) {
// pass this up to the calling method so that openmrs loading stops
throw ex;
} catch (Exception e) {
Throwable rootCause = getActualRootCause(e, true);
if (rootCause != null) {
log.error(MarkerFactory.getMarker("FATAL"), "Unable to refresh the spring application context. Root Cause was:", rootCause);
} else {
log.error(MarkerFactory.getMarker("FATAL"), "nable to refresh the spring application context. Unloading all modules, Error was:", e);
}
try {
WebModuleUtil.shutdownModules(servletContext);
for (Module mod : ModuleFactory.getLoadedModules()) {
// use loadedModules to avoid a concurrentmodificationexception
if (!mod.isCoreModule() && !mod.isMandatory()) {
try {
ModuleFactory.stopModule(mod, true, true);
} catch (Exception t3) {
// just keep going if we get an error shutting down. was probably caused by the module
// that actually got us to this point!
log.trace("Unable to shutdown module:" + mod, t3);
}
}
}
WebModuleUtil.refreshWAC(servletContext, true, null);
} catch (MandatoryModuleException ex) {
// pass this up to the calling method so that openmrs loading stops
throw new MandatoryModuleException(ex.getModuleId(), "Got an error while starting a mandatory module: " + e.getMessage() + ". Check the server logs for more information");
} catch (Exception t2) {
// a mandatory or core module is causing spring to fail to start up. We don't want those
// stopped so we must report this error to the higher authorities
log.warn("caught another error: ", t2);
throw t2;
}
}
}
// (this is to protect servlets/filters that depend on their module's spring xml config being available)
for (Module mod : ModuleFactory.getStartedModules()) {
WebModuleUtil.loadServlets(mod, servletContext);
WebModuleUtil.loadFilters(mod, servletContext);
}
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class WebModuleUtilTest method startModule_dwrModuleXmlshouldContainModuleInfo.
/**
* @throws ParserConfigurationException
* @throws FileNotFoundException
* @see WebModuleUtil#startModule(Module, ServletContext, boolean)
*/
@Test
public void startModule_dwrModuleXmlshouldContainModuleInfo() throws ParserConfigurationException, FileNotFoundException {
// create dummy module and start it
Module mod = buildModuleForMessageTest();
ModuleFactory.getStartedModulesMap().put(mod.getModuleId(), mod);
ServletContext servletContext = mock(ServletContext.class);
String realPath = servletContext.getRealPath("");
if (realPath == null)
realPath = System.getProperty("user.dir");
WebModuleUtil.startModule(mod, servletContext, true);
// test if dwr-modules.xml contains id of started dummy module
File f = new File(realPath + "/WEB-INF/dwr-modules.xml");
Scanner scanner = new Scanner(f);
boolean found = false;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line.contains(mod.getModuleId())) {
found = true;
break;
}
}
if (scanner != null)
scanner.close();
assertTrue(found);
ModuleFactory.getStartedModulesMap().clear();
}
use of org.openmrs.module.Module in project openmrs-core by openmrs.
the class ModuleResourcesServlet method getFile.
/**
* Turns the given request/path into a File object
*
* @param request the current http request
* @return the file being requested or null if not found
*/
protected File getFile(HttpServletRequest request) {
String path = request.getPathInfo();
Module module = ModuleUtil.getModuleForPath(path);
if (module == null) {
log.warn("No module handles the path: " + path);
return null;
}
String relativePath = ModuleUtil.getPathForResource(module, path);
String realPath = getServletContext().getRealPath("") + MODULE_PATH + module.getModuleIdAsPath() + "/resources" + relativePath;
// if in dev mode, load resources from the development directory
File devDir = ModuleUtil.getDevelopmentDirectory(module.getModuleId());
if (devDir != null) {
realPath = devDir.getAbsolutePath() + "/omod/target/classes/web/module/resources" + relativePath;
}
realPath = realPath.replace("/", File.separator);
File f = new File(realPath);
if (!f.exists()) {
log.warn("No file with path '" + realPath + "' exists for module '" + module.getModuleId() + "'");
return null;
}
return f;
}
Aggregations