use of org.mycore.common.config.MCRConfigurationDirSetup in project mycore by MyCoRe-Org.
the class MCRServlet method doGetPost.
/**
* This private method handles both GET and POST requests and is invoked by doGet() and doPost().
*
* @param req
* the HTTP request instance
* @param res
* the HTTP response instance
* @exception IOException
* for java I/O errors.
* @exception ServletException
* for errors from the servlet engine.
*/
private void doGetPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException, SAXException, TransformerException {
if (MCRConfiguration.instance() == null) {
// removes NullPointerException below, if somehow Servlet is not yet
// intialized
init();
}
// Try to set encoding of form values
String ReqCharEncoding = req.getCharacterEncoding();
if (ReqCharEncoding == null) {
// Set default to UTF-8
ReqCharEncoding = MCRConfiguration.instance().getString("MCR.Request.CharEncoding", "UTF-8");
req.setCharacterEncoding(ReqCharEncoding);
LOGGER.debug("Setting ReqCharEncoding to: {}", ReqCharEncoding);
}
if ("true".equals(req.getParameter("reload.properties"))) {
MCRConfigurationDirSetup setup = new MCRConfigurationDirSetup();
setup.startUp(getServletContext());
}
if (SERVLET_URL == null) {
prepareBaseURLs(getServletContext(), req);
}
MCRServletJob job = new MCRServletJob(req, res);
MCRSession session = getSession(job.getRequest());
bindSessionToRequest(req, getServletName(), session);
try {
// transaction around 1st phase of request
Exception thinkException = processThinkPhase(job);
// first phase completed, start rendering phase
processRenderingPhase(job, thinkException);
} catch (Exception ex) {
if (getProperty(req, INITIAL_SERVLET_NAME_KEY).equals(getServletName())) {
// current Servlet not called via RequestDispatcher
session.rollbackTransaction();
}
if (isBrokenPipe(ex)) {
LOGGER.info("Ignore broken pipe.");
return;
}
if (ex.getMessage() == null) {
LOGGER.error("Exception while in rendering phase.", ex);
} else {
LOGGER.error("Exception while in rendering phase: {}", ex.getMessage());
}
if (ex instanceof ServletException) {
throw (ServletException) ex;
} else if (ex instanceof IOException) {
throw (IOException) ex;
} else if (ex instanceof SAXException) {
throw (SAXException) ex;
} else if (ex instanceof TransformerException) {
throw (TransformerException) ex;
} else if (ex instanceof RuntimeException) {
throw (RuntimeException) ex;
} else {
throw new RuntimeException(ex);
}
} finally {
// in case that Thread pooling will be used by servlet engine
if (getProperty(req, INITIAL_SERVLET_NAME_KEY).equals(getServletName())) {
// current Servlet not called via RequestDispatcher
MCRSessionMgr.releaseCurrentSession();
}
}
}
use of org.mycore.common.config.MCRConfigurationDirSetup in project mycore by MyCoRe-Org.
the class MCRStartupHandler method startUp.
public static void startUp(ServletContext servletContext) {
// setup configuration
MCRConfigurationDirSetup dirSetup = new MCRConfigurationDirSetup();
dirSetup.startUp(servletContext);
LOGGER.info("I have these components for you: {}", MCRRuntimeComponentDetector.getAllComponents());
LOGGER.info("I have these mycore components for you: {}", MCRRuntimeComponentDetector.getMyCoReComponents());
LOGGER.info("I have these app modules for you: {}", MCRRuntimeComponentDetector.getApplicationModules());
if (servletContext != null) {
LOGGER.info("Library order: {}", servletContext.getAttribute(ServletContext.ORDERED_LIBS));
}
MCRConfiguration.instance().getStrings("MCR.Startup.Class", Collections.emptyList()).stream().map(MCRStartupHandler::getAutoExecutable).sorted((o1, o2) -> Integer.compare(o2.getPriority(), o1.getPriority())).forEachOrdered(autoExecutable -> startExecutable(servletContext, autoExecutable));
// initialize MCRURIResolver
MCRURIResolver.init(servletContext);
}
Aggregations