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
}
}
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();
}
}
Aggregations