Svetlin Zarev created TOMEE-2074: ------------------------------------ Summary: TomcatWebAppBuilder does not correctly set NamingContextListener.setExceptionOnFailedWrite() Key: TOMEE-2074 URL: https://issues.apache.org/jira/browse/TOMEE-2074 Project: TomEE Issue Type: Bug Reporter: Svetlin Zarev Attachments: sample.zip
The TomcatWebAppBuilder does not correctly set the NamingContextListener.setExceptionOnFailedWrite() property - it always sets the default value which is "true", instead of the one specified in the context.xml Execution flow: 1. TomcatWebAppBuilder:890 creates new NamingContextLisener 2. TomcatWebAppBuilder sets the "exceptionOnFailedWrite" property on the NamingContextLisener to the value retrieved from the standard context - at this point in time it's the default value, because the context.xml has not been processed yet. 3. The context.xml is processed -> OpenEJBContextConfig::contextConfig() 4. The Digester sets that property on the StandardContext instance 5. The NamingContextListener configures the write-ability of the naming context {code} namingContext.setExceptionOnFailedWrite(getExceptionOnFailedWrite()); {code} Where getExceptionOnFailedWrite() returns the value we set in step 2 (i.e. it returns the default value). 6. As a result the naming context is not configured with the user-provided configuration in context.xml Steps to reproduce: 1. Edit <TOMEE_HOME>/conf/context.xml and add jndiExceptionOnFailedWrite='false' attribute to the context element. {code} <Context jndiExceptionOnFailedWrite='false'> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> </Context> {code} 2. Execute this simple servlet: {code} @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/plain"); final PrintWriter writer = resp.getWriter(); try { final InitialContext ctx = new InitialContext(); final Context compEnv = (Context) ctx.lookup("java:comp/env"); compEnv.close(); writer.println("Closed"); } catch (Exception ex) { writer.println("Failed to close context: "); ex.printStackTrace(writer); } } {code} WebApp is attached for convenience -- This message was sent by Atlassian JIRA (v6.4.14#64029)