Search in sources :

Example 1 with ModuleMustStartException

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);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) Module(org.openmrs.module.Module) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) ServletException(javax.servlet.ServletException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) InputRequiredException(org.openmrs.util.InputRequiredException) ModuleMustStartException(org.openmrs.module.ModuleMustStartException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) MandatoryModuleException(org.openmrs.module.MandatoryModuleException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)1 Module (org.openmrs.module.Module)1 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)1 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)1 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)1 InputRequiredException (org.openmrs.util.InputRequiredException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1