use of org.openmrs.module.ModuleMustStartException 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);
}
}
Aggregations