EAP 7 fails app start up for one 'load-on-startup' servlet init error while EAP 6 does not

Solution Unverified - Updated

Environment

  • JBoss Enterprise Application Platform (EAP) 7.x

Issue

  • We have a servlet throwing an initialization exception. EAP 6 would still start the app so it could be accessed. The app does not start up at all after migrating to EAP 7 with this servlet initialization exception and the application cannot be accessed.

Resolution

Root Cause

  • EAP 7 removes JBossWeb from EAP 6 and replaces it with Undertow. This is a difference in how Undertow now handles servlet initialization and any error it has compared to JBossWeb. If JBossWeb sees a servlet init exception, it just logs it and moves on to the next servlet init:
    public void loadOnStartup(Container children[]) {

        // Collect "load on startup" servlets that need to be initialized
        TreeMap<Integer, ArrayList<Wrapper>> map =
            new TreeMap<Integer, ArrayList<Wrapper>>();
        for (int i = 0; i < children.length; i++) {
            Wrapper wrapper = (Wrapper) children[i];
            int loadOnStartup = wrapper.getLoadOnStartup();
            if (loadOnStartup < 0)
                continue;
            Integer key = Integer.valueOf(loadOnStartup);
            ArrayList<Wrapper> list = map.get(key);
            if (list == null) {
                list = new ArrayList<Wrapper>();
                map.put(key, list);
            }
            list.add(wrapper);
        }

        // Load the collected "load on startup" servlets
        for (ArrayList<Wrapper> list : map.values()) {
            for (Wrapper wrapper : list) {
                try {
                    String servletClass = wrapper.getServletClass();
                    lifecycle.fireLifecycleEvent(Lifecycle.BEFORE_LOAD_ON_STARTUP_EVENT, servletClass);
                    wrapper.load();
                    lifecycle.fireLifecycleEvent(Lifecycle.AFTER_LOAD_ON_STARTUP_EVENT, servletClass);
                } catch (ServletException e) {
                    getLogger().error(MESSAGES.errorLoadingServlet(wrapper.getName()), StandardWrapper.getRootCause(e));
                    // NOTE: load errors (including a servlet that throws
                    // UnavailableException from tht init() method) are NOT
                    // fatal to application startup
                }
            }
        }

    }
Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.