Search in sources :

Example 1 with MCRConfigurationDirSetup

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();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) MCRSession(org.mycore.common.MCRSession) IOException(java.io.IOException) MCRConfigurationDirSetup(org.mycore.common.config.MCRConfigurationDirSetup) TransformerException(javax.xml.transform.TransformerException) ServletException(javax.servlet.ServletException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 2 with MCRConfigurationDirSetup

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);
}
Also used : MCRURIResolver(org.mycore.common.xml.MCRURIResolver) Logger(org.apache.logging.log4j.Logger) MCRRuntimeComponentDetector(org.mycore.common.config.MCRRuntimeComponentDetector) MCRConfigurationDirSetup(org.mycore.common.config.MCRConfigurationDirSetup) ServletContext(javax.servlet.ServletContext) MCRConfiguration(org.mycore.common.config.MCRConfiguration) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) MCRConfigurationDirSetup(org.mycore.common.config.MCRConfigurationDirSetup)

Aggregations

MCRConfigurationDirSetup (org.mycore.common.config.MCRConfigurationDirSetup)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Collections (java.util.Collections)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 TransformerException (javax.xml.transform.TransformerException)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MCRSession (org.mycore.common.MCRSession)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)1 MCRRuntimeComponentDetector (org.mycore.common.config.MCRRuntimeComponentDetector)1 MCRURIResolver (org.mycore.common.xml.MCRURIResolver)1 SAXException (org.xml.sax.SAXException)1 SAXParseException (org.xml.sax.SAXParseException)1