Ejemplo n.º 1
0
  private void addInternalBeans() {
    beanManager.getInjectionResolver().clearCaches();

    if (!hasBean(beanManager, HttpServletRequest.class)) {
      beanManager.addInternalBean(new HttpServletRequestBean(webBeansContext));
    }
    if (!hasBean(beanManager, HttpSession.class)) {
      beanManager.addInternalBean(
          new InternalBean<>(webBeansContext, HttpSession.class, HttpSession.class));
    }
    if (!hasBean(beanManager, ServletContext.class)) {
      beanManager.addInternalBean(
          new InternalBean<>(webBeansContext, ServletContext.class, ServletContext.class));
    }

    beanManager
        .getInjectionResolver()
        .clearCaches(); // hasBean() usage can have cached several things
  }
Ejemplo n.º 2
0
  private static <T> T newInstance(final OpenEjbConfig config, final Class<T> clazz)
      throws Exception {
    final WebBeansContext webBeansContext = WebBeansContext.currentInstance();
    if (webBeansContext == null) {
      return clazz.newInstance();
    }

    final BeanManagerImpl beanManager = webBeansContext.getBeanManagerImpl();
    if (!beanManager.isInUse()) {
      return clazz.newInstance();
    }

    final AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz);
    final InjectionTarget<T> it = beanManager.createInjectionTarget(annotatedType);
    final CreationalContext<T> context = beanManager.createCreationalContext(null);
    final T instance = it.produce(context);
    it.inject(instance, context);
    it.postConstruct(instance);

    config.releasables.add(new Releasable<T>(context, it, instance));

    return instance;
  }
Ejemplo n.º 3
0
  @Override
  public void stopApplication(final Object endObject) {
    logger.debug("OpenWebBeans Container is stopping.");

    try {
      // Fire shut down
      if (WebappBeanManager.class.isInstance(beanManager)) {
        WebappBeanManager.class.cast(beanManager).beforeStop();
      }

      webBeansContext.getContextsService().endContext(RequestScoped.class, endObject);
      webBeansContext.getContextsService().endContext(ConversationScoped.class, endObject);
      webBeansContext.getContextsService().endContext(SessionScoped.class, endObject);
      webBeansContext.getContextsService().endContext(ApplicationScoped.class, endObject);
      webBeansContext.getContextsService().endContext(Singleton.class, endObject);

      // clean up the EL caches after each request
      ELContextStore elStore = ELContextStore.getInstance(false);
      if (elStore != null) {
        elStore.destroyELContextStore();
      }

      this.beanManager.fireEvent(new BeforeShutdownImpl(), true);

      // this will now even destroy the ExtensionBeans and other internal stuff
      this.contextsService.destroy(endObject);

      // Unbind BeanManager
      if (jndiService != null) {
        jndiService.unbind(WebBeansConstants.WEB_BEANS_MANAGER_JNDI_NAME);
      }

      // Free all plugin resources
      ((CdiPlugin) webBeansContext.getPluginLoader().getEjbPlugin()).clearProxies();
      webBeansContext.getPluginLoader().shutDown();

      // Clear extensions
      webBeansContext.getExtensionLoader().clear();

      // Delete Resolutions Cache
      beanManager.getInjectionResolver().clearCaches();

      // Delete AnnotateTypeCache
      webBeansContext.getAnnotatedElementFactory().clear();

      // After Stop
      // Clear the resource injection service
      final ResourceInjectionService injectionServices =
          webBeansContext.getService(ResourceInjectionService.class);
      if (injectionServices != null) {
        injectionServices.clear();
      }

      // Comment out for commit OWB-502
      // ContextFactory.cleanUpContextFactory();

      CdiAppContextsService.class.cast(contextsService).removeThreadLocals();

      WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());

      // Clear BeanManager
      this.beanManager.clear();

      // Clear singleton list
      WebBeansFinder.clearInstances(WebBeansUtil.getCurrentClassLoader());

    } catch (final Exception e) {
      logger.error("An error occured while stopping the container.", e);
    }
  }
Ejemplo n.º 4
0
 private static boolean hasBean(final BeanManagerImpl beanManagerImpl, final Class<?> type) {
   return !beanManagerImpl.getInjectionResolver().implResolveByType(false, type).isEmpty();
 }