Skip to content

Commit

Permalink
Validate the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuir committed Nov 3, 2009
1 parent 2ba64a0 commit 47cb824
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion impl/src/main/java/org/jboss/weld/servlet/WeldListener.java
Expand Up @@ -63,12 +63,29 @@ private ServletLifecycle getLifecycle()
private static BeanManagerImpl getBeanManager(ServletContext ctx)
{
BeanDeploymentArchive war = Container.instance().deploymentServices().get(ServletServices.class).getBeanDeploymentArchive(ctx);
return Container.instance().beanDeploymentArchives().get(war);
if (war == null)
{
throw new IllegalStateException("Unable to locate BeanDeploymentArchive. ServletContext: " + ctx);
}
BeanManagerImpl beanManager = Container.instance().beanDeploymentArchives().get(war);
if (beanManager == null)
{
throw new IllegalStateException("Unable to locate BeanManager. ServletContext: " + ctx + "; BeanDeploymentArchive: " + war);
}
return beanManager;
}

@Override
public void contextInitialized(ServletContextEvent sce)
{
if (!Container.instance().isInitialized())
{
throw new IllegalStateException("Weld bootstrap must be complete before contextInitialized event");
}
if (!Container.instance().deploymentServices().contains(ServletServices.class))
{
throw new IllegalStateException("Cannot use WeldListener without ServletServices");
}
super.contextInitialized(sce);
sce.getServletContext().setAttribute(BeanManager.class.getName(), getBeanManager(sce.getServletContext()));
}
Expand Down

0 comments on commit 47cb824

Please sign in to comment.