Search in sources :

Example 1 with MandatoryModuleException

use of org.openmrs.module.MandatoryModuleException 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)

Example 2 with MandatoryModuleException

use of org.openmrs.module.MandatoryModuleException in project openmrs-core by openmrs.

the class Listener method startOpenmrs.

/**
 * Do the work of starting openmrs.
 *
 * @param servletContext
 * @throws ServletException
 */
public static void startOpenmrs(ServletContext servletContext) throws ServletException {
    // start openmrs
    try {
        // load bundled modules that are packaged into the webapp
        Listener.loadBundledModules(servletContext);
        Context.startup(getRuntimeProperties());
    } catch (DatabaseUpdateException | InputRequiredException updateEx) {
        throw new ServletException("Should not be here because updates were run previously", updateEx);
    } catch (MandatoryModuleException mandatoryModEx) {
        throw new ServletException(mandatoryModEx);
    } catch (OpenmrsCoreModuleException coreModEx) {
        // in the StartupErrorFilter class
        throw coreModEx;
    }
    try {
        // web load modules
        Listener.performWebStartOfModules(servletContext);
        // start the scheduled tasks
        SchedulerUtil.startup(getRuntimeProperties());
    } catch (Exception t) {
        Context.shutdown();
        WebModuleUtil.shutdownModules(servletContext);
        throw new ServletException(t);
    } finally {
        Context.closeSession();
    }
}
Also used : ServletException(javax.servlet.ServletException) InputRequiredException(org.openmrs.util.InputRequiredException) DatabaseUpdateException(org.openmrs.util.DatabaseUpdateException) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) 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)2 ServletException (javax.servlet.ServletException)2 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)2 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)2 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)2 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)2 InputRequiredException (org.openmrs.util.InputRequiredException)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 Module (org.openmrs.module.Module)1