Uploaded image for project: 'Application Server 7'
  1. Application Server 7
  2. AS7-5746

Webapp's ENC destroyed before ServletContextListener invoked

    XMLWordPrintable

Details

    Description

      It looks as if when javax.servlet.ServletContextListener#contextDestroyed(ServletContextEvent) is invoked the naming service / context has already been shut down.

      Consider the following class

      public class BindingListener implements ServletContextListener {
      	
      	private static final Logger LOG = Logger.getLogger("binding-listener");
      	private static final String NAME = "java:global/env/foo";
      	private static final String VALUE = "FOO";
      
      	@Override
      	public void contextInitialized(ServletContextEvent sce) {
      		LOG.info("contextInitialized");
      		try {
      			Context context = new InitialContext();
      			context.rebind(NAME, VALUE);
      		} catch (NamingException e) {
      			LOG.log(Level.SEVERE, "could not bind value", e);
      		}
      		
      	}
      
      	@Override
      	public void contextDestroyed(ServletContextEvent sce) {
      		LOG.info("contextDestroyed");
      		try {
      			Context context = new InitialContext();
      			context.unbind(NAME);
      		} catch (NamingException e) {
      			LOG.log(Level.SEVERE, "could not unbind value", e);
      		}
      	}
      
      }
      

      This results in the following exception when shutting down the container.

      00:50:51,171 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/context-listener-0.1.0-SNAPSHOT]] (MSC service thread 1-3) JBWEB000306: Exception sending context destroyed event to listener instance of class com.github.marschall.BindingListener: java.lang.IllegalArgumentException: JBAS011857: NamingStore is null
      	at org.jboss.as.naming.NamingContext.<init>(NamingContext.java:151)
      	at org.jboss.as.naming.NamingContext.<init>(NamingContext.java:124)
      	at org.jboss.as.naming.InitialContext.<init>(InitialContext.java:86)
      	at org.jboss.as.naming.InitialContextFactory.getInitialContext(InitialContextFactory.java:44)
      	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) [rt.jar:1.8.0-ea]
      	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:311) [rt.jar:1.8.0-ea]
      	at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:339) [rt.jar:1.8.0-ea]
      	at javax.naming.InitialContext.unbind(InitialContext.java:439) [rt.jar:1.8.0-ea]
      	at com.github.marschall.BindingListener.contextDestroyed(BindingListener.java:41) [classes:]
      	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3419) [jbossweb-7.2.0.Alpha2.jar:7.2.0.Alpha2]
      	at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3912) [jbossweb-7.2.0.Alpha2.jar:7.2.0.Alpha2]
      	at org.jboss.as.web.deployment.WebDeploymentService.stop(WebDeploymentService.java:118) [jboss-as-web-7.2.0.Alpha1-SNAPSHOT.jar:7.2.0.Alpha1-SNAPSHOT]
      	at org.jboss.msc.service.ServiceControllerImpl$StopTask.stopService(ServiceControllerImpl.java:1911)
      	at org.jboss.msc.service.ServiceControllerImpl$StopTask.run(ServiceControllerImpl.java:1874)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.8.0-ea]
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.8.0-ea]
      	at java.lang.Thread.run(Thread.java:722) [rt.jar:1.8.0-ea]
      

      This seems to be a reappearance of JBAS-672.

      See also this Stackoverflow thread
      http://stackoverflow.com/questions/12497538/jndi-lookup-in-servletcontextlistener-contextdestroyed

      I would provide a patch/pull request if somebody can point me in the right direction.

      Attachments

        Activity

          People

            emartins@redhat.com Eduardo Martins
            pmarscha Philippe Marschall (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: