Search in sources :

Example 1 with OpenmrsCoreModuleException

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

the class StartupErrorFilter method doPost.

/**
 * @see org.openmrs.web.filter.StartupFilter#doPost(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
    // if they are uploading modules
    if (getModel().errorAtStartup instanceof OpenmrsCoreModuleException) {
        RequestContext requestContext = new ServletRequestContext(httpRequest);
        if (!ServletFileUpload.isMultipartContent(requestContext)) {
            throw new ServletException("The request is not a valid multipart/form-data upload request");
        }
        FileItemFactory factory = new DiskFileItemFactory();
        ServletFileUpload upload = new ServletFileUpload(factory);
        try {
            Context.openSession();
            List<FileItem> items = upload.parseRequest(requestContext);
            for (FileItem item : items) {
                InputStream uploadedStream = item.getInputStream();
                ModuleUtil.insertModuleFile(uploadedStream, item.getName());
            }
        } catch (FileUploadException ex) {
            throw new ServletException("Error while uploading file(s)", ex);
        } finally {
            Context.closeSession();
        }
        Map<String, Object> map = new HashMap<>();
        map.put("success", Boolean.TRUE);
        renderTemplate("coremoduleerror.vm", map, httpResponse);
    // TODO restart openmrs here instead of going to coremodulerror template
    }
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) ServletRequestContext(org.apache.commons.fileupload.servlet.ServletRequestContext) OpenmrsCoreModuleException(org.openmrs.module.OpenmrsCoreModuleException) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) FileItemFactory(org.apache.commons.fileupload.FileItemFactory) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) ServletException(javax.servlet.ServletException) FileItem(org.apache.commons.fileupload.FileItem) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) ServletRequestContext(org.apache.commons.fileupload.servlet.ServletRequestContext) RequestContext(org.apache.commons.fileupload.RequestContext) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 2 with OpenmrsCoreModuleException

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

ServletException (javax.servlet.ServletException)2 OpenmrsCoreModuleException (org.openmrs.module.OpenmrsCoreModuleException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 FileItem (org.apache.commons.fileupload.FileItem)1 FileItemFactory (org.apache.commons.fileupload.FileItemFactory)1 FileUploadException (org.apache.commons.fileupload.FileUploadException)1 RequestContext (org.apache.commons.fileupload.RequestContext)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 ServletRequestContext (org.apache.commons.fileupload.servlet.ServletRequestContext)1 MandatoryModuleException (org.openmrs.module.MandatoryModuleException)1 ModuleMustStartException (org.openmrs.module.ModuleMustStartException)1 DatabaseUpdateException (org.openmrs.util.DatabaseUpdateException)1 InputRequiredException (org.openmrs.util.InputRequiredException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1