EAP 7 fails app start up for one 'load-on-startup' servlet init error while EAP 6 does not
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
-
Remove any failing servlet declarations from the application
WEB-INF/web.xml -
This content is not included.JBEAP-24946 - UNDERTOW-2267 - Fix change in behaviour of Servlet.init() method when loadOnStartup is required fixed in EAP 7.4 Update 12
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
}
}
}
}
-
But Content from github.com is not included.compared to Undertow, a single servlet initialization failure now fails the whole application so its context is not registered to allow any access to any servlets or app content.
-
This content is not included.JBEAP-24946 - UNDERTOW-2267 - Fix change in behaviour of Servlet.init() method when loadOnStartup is required fixed in EAP 7.4 Update 12
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.