Example #1
0
 private Iterable<Metadata<Extension>> getExtensions(
     ClassLoader classLoader, Bootstrap bootstrap) {
   Set<Metadata<Extension>> result = new HashSet<Metadata<Extension>>();
   if (discoveryEnabled) {
     Iterables.addAll(result, bootstrap.loadExtensions(classLoader));
   }
   if (!extensions.isEmpty()) {
     result.addAll(extensions);
   }
   // Ensure that WeldSEBeanRegistrant is present
   WeldSEBeanRegistrant weldSEBeanRegistrant = null;
   for (Metadata<Extension> metadata : result) {
     if (metadata.getValue().getClass().getName().equals(WeldSEBeanRegistrant.class.getName())) {
       weldSEBeanRegistrant = (WeldSEBeanRegistrant) metadata.getValue();
       break;
     }
   }
   if (weldSEBeanRegistrant == null) {
     try {
       weldSEBeanRegistrant = SecurityActions.newInstance(WeldSEBeanRegistrant.class);
       result.add(
           new MetadataImpl<Extension>(
               weldSEBeanRegistrant,
               SYNTHETIC_LOCATION_PREFIX + WeldSEBeanRegistrant.class.getName()));
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
   if (!beanBuilders.isEmpty()) {
     weldSEBeanRegistrant.setBeanBuilders(beanBuilders);
   }
   return result;
 }
Example #2
0
  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    bootstrap.shutdown();

    if (container != null) container.destroy(new ContainerContext(sce, null));

    super.contextDestroyed(sce);
  }
 public ModularWeldDeployment(
     Bootstrap bootstrap, ResourceLoader resourceLoader, ModuleScanResult scanResult) {
   super(bootstrap);
   getServices()
       .add(
           BootstrapConfiguration.class,
           new PerformanceTunedBootstrapConfiguration(resourceLoader));
   this.beanDeploymentArchive =
       new ImmutableBeanDeploymentArchive(
           "classpath",
           scanResult.getDiscoveredClasses(),
           bootstrap.parse(scanResult.getDiscoveredResourceUrls()));
   this.beanDeploymentArchive.getServices().add(ResourceLoader.class, resourceLoader);
 }
Example #4
0
 /**
  * Shutdown the container.
  *
  * @see Weld#initialize()
  */
 public synchronized void shutdown() {
   if (isRunning()) {
     try {
       manager.fireEvent(new ContainerShutdown(id), DestroyedLiteral.APPLICATION);
     } finally {
       SINGLETON.clear(id);
       RUNNING_CONTAINER_IDS.remove(id);
       // Destroy all the dependent beans correctly
       creationalContext.release();
       bootstrap.shutdown();
       WeldSELogger.LOG.weldContainerShutdown(id);
     }
   } else {
     if (WeldSELogger.LOG.isTraceEnabled()) {
       WeldSELogger.LOG.tracev(
           "Spurious call to shutdown from: {0}",
           (Object[]) Thread.currentThread().getStackTrace());
     }
     throw WeldSELogger.LOG.weldContainerAlreadyShutDown(id);
   }
 }
Example #5
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {

    ClassLoader classLoader = Reflections.getClassLoader();
    ServletContext context = sce.getServletContext();

    URLScanner scanner = createUrlScanner(classLoader, context);
    if (scanner != null) {
      context.setAttribute(URLScanner.class.getName(), scanner);
    }

    ServletDeployment deployment = createServletDeployment(context, bootstrap);
    try {
      deployment
          .getWebAppBeanDeploymentArchive()
          .getServices()
          .add(ResourceInjectionServices.class, new ServletResourceInjectionServices() {});
    } catch (NoClassDefFoundError e) {
      // Support GAE
      log.warn("@Resource injection not available in simple beans");
    }

    bootstrap.startContainer(Environments.SERVLET, deployment).startInitialization();
    WeldManager manager = bootstrap.getManager(deployment.getWebAppBeanDeploymentArchive());

    ContainerContext cc = new ContainerContext(sce, manager);
    StringBuilder dump = new StringBuilder();
    Container container = findContainer(cc, dump);
    if (container == null) {
      log.info(
          "No supported servlet container detected, CDI injection will NOT be available in Servlets, Filters or Listeners");
      log.debug("Exception dump from Container lookup: {}", dump);
    } else {
      container.initialize(cc);
      this.container = container;
    }

    // Push the manager into the servlet context so we can access in JSF
    context.setAttribute(BEAN_MANAGER_ATTRIBUTE_NAME, manager);

    if (JspFactory.getDefaultFactory() != null) {
      JspApplicationContext jspApplicationContext =
          JspFactory.getDefaultFactory().getJspApplicationContext(context);

      // Register the ELResolver with JSP
      jspApplicationContext.addELResolver(manager.getELResolver());

      // Register ELContextListener with JSP
      jspApplicationContext.addELContextListener(
          Reflections.<ELContextListener>newInstance("org.jboss.weld.el.WeldELContextListener"));

      // Push the wrapped expression factory into the servlet context so that Tomcat or Jetty can
      // hook it in using a container code
      context.setAttribute(
          EXPRESSION_FACTORY_NAME,
          manager.wrapExpressionFactory(jspApplicationContext.getExpressionFactory()));
    }

    bootstrap.deployBeans().validateBeans().endInitialization();
    super.contextInitialized(sce);
  }