Exemplo n.º 1
0
  @Override
  public void setUp() throws Exception {
    FactoryFinder.releaseFactories();
    super.setUp();
    for (int i = 0, len = FACTORIES.length; i < len; i++) {
      System.getProperties().remove(FACTORIES[i][0]);
    }

    FactoryFinder.releaseFactories();
    int len, i = 0;

    // simulate the "faces implementation specific" part
    for (i = 0, len = FACTORIES.length; i < len; i++) {
      FactoryFinder.setFactory(FACTORIES[i][0], FACTORIES[i][1]);
    }

    UIViewRoot root = facesContext.getApplication().getViewHandler().createView(facesContext, null);
    root.setViewId("/viewId");
    facesContext.setViewRoot(root);
    RenderKitFactory renderKitFactory =
        (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    RenderKit renderKit = new MockRenderKit();
    try {
      renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT, renderKit);
    } catch (IllegalArgumentException e) {;
    }
  }
Exemplo n.º 2
0
  /**
   * In the absence of webapp faces-config.xml and META-INF/services, verify that the overrides
   * specified in the implementation faces-config.xml take precedence.
   *
   * @throws java.lang.Exception
   */
  public void testJSFImplCase() throws Exception {
    Object factory = null;
    Class clazz = null;

    FactoryFinder.releaseFactories();
    int len, i = 0;

    // this testcase only simulates the "faces implementation
    // specific" part
    for (i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) {
      FactoryFinder.setFactory(
          FactoryFinderTestCase2.FACTORIES[i][0], FactoryFinderTestCase2.FACTORIES[i][1]);
    }

    for (i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) {
      clazz = Class.forName(FactoryFinderTestCase2.FACTORIES[i][0]);
      factory = FactoryFinder.getFactory(FactoryFinderTestCase2.FACTORIES[i][0]);
      assertTrue(
          "Factory for " + clazz.getName() + " not of expected type.",
          clazz.isAssignableFrom(factory.getClass()));
      clazz = Class.forName(FactoryFinderTestCase2.FACTORIES[i][1]);
      assertTrue(
          "Factory " + FactoryFinderTestCase2.FACTORIES[i][1] + " not of expected type",
          clazz.isAssignableFrom(factory.getClass()));
    }
  }
Exemplo n.º 3
0
 // Tear down instance variables required by ths test case
 @Override
 public void tearDown() throws Exception {
   super.tearDown();
   FactoryFinder.releaseFactories();
   for (int i = 0, len = FactoryFinderTestCase2.FACTORIES.length; i < len; i++) {
     System.getProperties().remove(FactoryFinderTestCase2.FACTORIES[i][0]);
   }
 }
Exemplo n.º 4
0
 /**
  * Calls through to {@link javax.faces.FactoryFinder#releaseFactories()} ignoring any exceptions.
  */
 private void releaseFactories() {
   try {
     FactoryFinder.releaseFactories();
   } catch (FacesException ignored) {
     if (LOGGER.isLoggable(Level.FINE)) {
       LOGGER.log(Level.FINE, "Exception thrown from FactoryFinder.releaseFactories()", ignored);
     }
   }
 }
Exemplo n.º 5
0
  public void contextDestroyed(ServletContextEvent sce) {
    ServletContext context = sce.getServletContext();
    InitFacesContext initContext = null;
    try {
      initContext = getInitFacesContext(context);
      if (null == initContext) {
        initContext = new InitFacesContext(context);
      }

      if (webAppListener != null) {
        webAppListener.contextDestroyed(sce);
        webAppListener = null;
      }
      if (webResourcePool != null) {
        webResourcePool.shutdownNow();
      }
      if (!ConfigManager.getInstance().hasBeenInitialized(context)) {
        return;
      }
      GroovyHelper helper = GroovyHelper.getCurrentInstance(context);
      if (helper != null) {
        helper.setClassLoader();
      }
      if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(
            Level.FINE, "ConfigureListener.contextDestroyed({0})", context.getServletContextName());
      }

      ELContext elctx = new ELContextImpl(initContext.getApplication().getELResolver());
      elctx.putContext(FacesContext.class, initContext);
      initContext.setELContext(elctx);
      Application app = initContext.getApplication();
      app.publishEvent(initContext, PreDestroyApplicationEvent.class, Application.class, app);

      Util.setNonFacesContextApplicationMap(null);

    } catch (Exception e) {
      if (LOGGER.isLoggable(Level.SEVERE)) {
        LOGGER.log(
            Level.SEVERE,
            "Unexpected exception when attempting to tear down the Mojarra runtime",
            e);
      }
    } finally {
      ApplicationAssociate.clearInstance(context);
      ApplicationAssociate.setCurrentInstance(null);
      // Release the initialization mark on this web application
      ConfigManager.getInstance().destroy(context);
      FactoryFinder.releaseFactories();
      ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
      WebConfiguration.clear(context);
      InitFacesContext.cleanupInitMaps(context);
    }
  }
Exemplo n.º 6
0
  /**
   * This method will be invoked {@link WebConfigResourceMonitor} when changes to any of the
   * faces-config.xml files included in WEB-INF are modified.
   */
  private void reload(ServletContext sc) {

    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.log(
          Level.INFO,
          "Reloading JSF configuration for context {0}",
          getServletContextIdentifier(sc));
    }
    GroovyHelper helper = GroovyHelper.getCurrentInstance();
    if (helper != null) {
      helper.setClassLoader();
    }
    // tear down the application
    try {
      // this will only be true in the automated test usage scenario
      if (null != webAppListener) {
        List<HttpSession> sessions = webAppListener.getActiveSessions();
        if (sessions != null) {
          for (HttpSession session : sessions) {
            if (LOGGER.isLoggable(Level.INFO)) {
              LOGGER.log(Level.INFO, "Invalidating Session {0}", session.getId());
            }
            session.invalidate();
          }
        }
      }
      ApplicationAssociate associate = ApplicationAssociate.getInstance(sc);
      if (associate != null) {
        BeanManager manager = associate.getBeanManager();
        for (Map.Entry<String, BeanBuilder> entry : manager.getRegisteredBeans().entrySet()) {
          String name = entry.getKey();
          BeanBuilder bean = entry.getValue();
          if (ELUtils.Scope.APPLICATION.toString().equals(bean.getScope())) {
            if (LOGGER.isLoggable(Level.INFO)) {
              LOGGER.log(Level.INFO, "Removing application scoped managed bean: {0}", name);
            }
            sc.removeAttribute(name);
          }
        }
      }
      // Release any allocated application resources
      FactoryFinder.releaseFactories();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      FacesContext initContext = new InitFacesContext(sc);
      ApplicationAssociate.clearInstance(initContext.getExternalContext());
      ApplicationAssociate.setCurrentInstance(null);
      // Release the initialization mark on this web application
      ConfigManager.getInstance().destory(sc);
      initContext.release();
      ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
      WebConfiguration.clear(sc);
    }

    // bring the application back up, avoid re-registration of certain JSP
    // artifacts.  No verification will be performed either to make this
    // light weight.

    // init a new WebAppLifecycleListener so that the cached ApplicationAssociate
    // is removed.
    webAppListener = new WebappLifecycleListener(sc);

    FacesContext initContext = new InitFacesContext(sc);
    ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());

    try {
      ConfigManager configManager = ConfigManager.getInstance();
      configManager.initialize(sc);

      registerELResolverAndListenerWithJsp(sc, true);
      ApplicationAssociate associate = ApplicationAssociate.getInstance(sc);
      if (associate != null) {
        Boolean errorPagePresent =
            (Boolean) sc.getAttribute(RIConstants.ERROR_PAGE_PRESENT_KEY_NAME);
        if (null != errorPagePresent) {
          associate.setErrorPagePresent(errorPagePresent);
          associate.setContextName(getServletContextIdentifier(sc));
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      initContext.release();
    }

    if (LOGGER.isLoggable(Level.INFO)) {
      LOGGER.log(Level.INFO, "Reload complete.", getServletContextIdentifier(sc));
    }
  }