コード例 #1
0
  @Override
  public void contextInitialized(ServletContextEvent sce) {

    ServletContext context = sce.getServletContext();
    cdiContainer = (CdiContainer) context.getAttribute("org.ops4j.pax.cdi.container");
    cdiContainer.start(context);
    WeldManager manager = cdiContainer.unwrap(WeldManager.class);

    CdiInstanceFactoryBuilder builder = new CdiInstanceFactoryBuilder(manager);
    @SuppressWarnings("unchecked")
    Map<String, Object> attributes =
        (Map<String, Object>) context.getAttribute("org.ops4j.pax.web.attributes");
    if (attributes != null) {
      attributes.put("org.ops4j.pax.cdi.ClassIntrospecter", builder);
      log.info("registered CdiInstanceFactoryBuilder for Undertow");
    }
    context.setAttribute("org.ops4j.pax.cdi.BeanManager", cdiContainer.getBeanManager());

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

      jspApplicationContext.addELResolver(manager.getELResolver());
      jspApplicationContext.addELContextListener(new WeldELContextListener());
    }
    super.contextInitialized(sce);
  }
コード例 #2
0
ファイル: EnhancedListener.java プロジェクト: NovanHsiu/core
 @Override
 public void requestInitialized(ServletRequestEvent sre) {
   if (isOriginalListenerUsed) {
     return;
   }
   super.requestInitialized(sre);
 }
コード例 #3
0
ファイル: EnhancedListener.java プロジェクト: NovanHsiu/core
 @Override
 public void sessionDestroyed(HttpSessionEvent se) {
   if (isOriginalListenerUsed) {
     return;
   }
   super.sessionDestroyed(se);
 }
コード例 #4
0
 @Override
 public void contextDestroyed(ServletContextEvent sce) {
   cdiContainer.stop();
   ServletContext context = sce.getServletContext();
   context.removeAttribute("org.ops4j.pax.cdi.ClassIntrospecter");
   context.removeAttribute("org.ops4j.pax.cdi.BeanManager");
   super.contextDestroyed(sce);
 }
コード例 #5
0
ファイル: Listener.java プロジェクト: nmansard/core
  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    bootstrap.shutdown();

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

    super.contextDestroyed(sce);
  }
コード例 #6
0
ファイル: EnhancedListener.java プロジェクト: NovanHsiu/core
 @Override
 public void onStartup(Set<Class<?>> classes, ServletContext context) throws ServletException {
   log.info("Initialize Weld using ServletContainerInitializer");
   lifecycle = new WeldServletLifecycle();
   lifecycle.initialize(context);
   context.setAttribute(WeldServletLifecycle.INSTANCE_ATTRIBUTE_NAME, lifecycle);
   context.setAttribute(
       WeldServletLifecycle.LISTENER_CLASS_FLAG_ATTRIBUTE_NAME, this.getClass().getName());
   context.addListener(this);
   super.contextInitialized(new ServletContextEvent(context));
 }
コード例 #7
0
ファイル: Listener.java プロジェクト: rain4226/core
  @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);
  }
コード例 #8
0
ファイル: EnhancedListener.java プロジェクト: NovanHsiu/core
 @Override
 public void contextDestroyed(ServletContextEvent sce) {
   lifecycle.destroy(sce.getServletContext());
   super.contextDestroyed(sce);
 }