/**
  * Register a {@link ContextLoaderListener} against the given servlet context. The {@code
  * ContextLoaderListener} is initialized with the application context returned from the {@link
  * #createRootApplicationContext()} template method.
  *
  * @param servletContext the servlet context to register the listener against
  */
 protected void registerContextLoaderListener(ServletContext servletContext) {
   WebApplicationContext rootAppContext = createRootApplicationContext();
   mylog.debug("创建WebApplicationContext,如果不为空并注册ContextLoaderListener");
   if (rootAppContext != null) {
     ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
     listener.setContextInitializers(getRootApplicationContextInitializers());
     servletContext.addListener(listener);
   } else {
     logger.debug(
         "No ContextLoaderListener registered, as "
             + "createRootApplicationContext() did not return an application context");
   }
 }
 protected void tearDown() throws Exception {
   super.tearDown();
   // cleanup: close sessionFactory and related resources (search index locks)
   springListener.closeWebApplicationContext(sc);
   springListener = null;
   listener = null;
   sc = null;
 }
 public void contextInitialized(ServletContextEvent event) {
   super.contextInitialized(event);
   WebApplicationContext wac =
       WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
   IFunctionService resourceService = (IFunctionService) wac.getBean("functionService");
   resourceService.findAllUrl();
   event.getServletContext().setAttribute(Constants.APP_MANAGER_THEME, "default");
 }
 protected void setUp() throws Exception {
   super.setUp();
   servletContext = new MockServletContext();
   servletContext.addInitParameter(
       "contextConfigLocation",
       "classpath*:idp/conf/internal.xml, classpath*:idp/conf/service.xml,classpath*:idp/conf/spring-beans-*.xml");
   contextLoaderListener = new ContextLoaderListener();
   contextLoaderListener.initWebApplicationContext(servletContext);
 }
  protected void setUp() throws Exception {
    super.setUp();
    sc = new MockServletContext("");

    // initialize Spring
    sc.addInitParameter(
        ContextLoader.CONFIG_LOCATION_PARAM,
        "classpath:/applicationContext-dao.xml, "
            + "classpath:/applicationContext-service.xml, "
            + "classpath:/applicationContext-resources.xml");

    springListener = new ContextLoaderListener();
    springListener.contextInitialized(new ServletContextEvent(sc));
    listener = new StartupListener();
  }
  @Override
  public void contextDestroyed(ServletContextEvent sce) {
    try {
      OpenFlameDataSource bean = OpenFlameSpringContext.getBean(OpenFlameDataSource.class);
      bean.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    try {
      Scheduler scheduler = OpenFlameSpringContext.getBean(Scheduler.class);
      scheduler.shutdown();
    } catch (SchedulerException e) {
      e.printStackTrace();
    }
    Env.clean();
    JAXBContextCache.clearCaches();
    ClassFactory.cleanCache();
    CachedIntrospectionResults.clearClassLoader(getClass().getClassLoader());

    super.contextDestroyed(sce);
  }
  @Override
  public void contextInitialized(ServletContextEvent sce) {
    File app = Env.getDefaultEnvFile();
    File keyStore = InstallUtils.getKeyStore();

    Map<String, String> propertiesMap = KeyUtils.getMapProperties(app, keyStore);
    ConfigContainer.putAll(propertiesMap);

    File xmlProp = InstallUtils.getXmlEnv();
    if (!ConfigContainer.isAppInstalled() && xmlProp.exists()) {
      Map<String, String> settings = EnvironmentsUtils.convertFromXml(xmlProp);
      ConfigContainer.putAll(settings);
    }

    File propFile = InstallUtils.getPropEnv();
    if (!ConfigContainer.isAppInstalled() && propFile.exists()) {
      ConfigContainer.putAll(MiscUtils.getProperties(propFile));
    }

    if (!xmlProp.exists()) {
      if (!OpenFlameConfig.DOMAIN_URL.exist())
        OpenFlameConfig.DOMAIN_URL.setValue(TomcatUtils.getCatalinaHost(sce));
      if (!OpenFlameConfig.PORT.exist())
        OpenFlameConfig.PORT.setValue(TomcatUtils.getCatalinaPort(sce).toString());
      if (!OpenFlameConfig.CONTEXT_URL.exist())
        OpenFlameConfig.CONTEXT_URL.setValue(TomcatUtils.getCatalinaContext(sce));
    }

    String domainUrl = OpenFlameConfig.DOMAIN_URL.getValue();
    String port = OpenFlameConfig.PORT.getValue();
    String contextUrl = OpenFlameConfig.CONTEXT_URL.getValue();
    if (domainUrl != null && port != null && contextUrl != null) {
      Env.FIREJACK_URL.setValue(WebUtils.getNormalizedUrl(domainUrl, port, contextUrl));
    }

    ConfigContainer.setHost(TomcatUtils.getCatalinaHost(sce));
    ConfigContainer.setPort(TomcatUtils.getCatalinaPort(sce));

    super.contextInitialized(sce);
  }
 @Override
 public void contextInitialized(ServletContextEvent event) {
   ApplicationHelper.changeLogLvl();
   super.contextInitialized(event);
 }
  public void contextInitialized(ServletContextEvent event) {
    if (log.isDebugEnabled()) {
      log.debug("initializing context...");
    }

    // call Spring's context ContextLoaderListener to initialize
    // all the context files specified in web.xml
    super.contextInitialized(event);

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map config = (HashMap) context.getAttribute(Constants.CONFIG);

    if (config == null) {
      config = new HashMap();
    }

    if (context.getInitParameter(Constants.CSS_THEME) != null) {
      config.put(Constants.CSS_THEME, context.getInitParameter(Constants.CSS_THEME));
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    boolean encryptPassword = false;
    try {
      ProviderManager provider = (ProviderManager) ctx.getBean("authenticationManager");
      for (Iterator it = provider.getProviders().iterator(); it.hasNext(); ) {
        AuthenticationProvider p = (AuthenticationProvider) it.next();
        if (p instanceof RememberMeAuthenticationProvider) {
          config.put("rememberMeEnabled", Boolean.TRUE);
        }
      }

      if (ctx.containsBean("passwordEncoder")) {
        encryptPassword = true;
        config.put(Constants.ENCRYPT_PASSWORD, Boolean.TRUE);
        String algorithm = "SHA";
        if (ctx.getBean("passwordEncoder") instanceof Md5PasswordEncoder) {
          algorithm = "MD5";
        }
        config.put(Constants.ENC_ALGORITHM, algorithm);
      }
    } catch (NoSuchBeanDefinitionException n) {
      // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
      log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
      log.debug("Encrypt Passwords? " + encryptPassword);
      if (encryptPassword) {
        log.debug("Encryption Algorithm: " + config.get(Constants.ENC_ALGORITHM));
      }
      log.debug("Populating drop-downs...");
    }

    setupContext(context);
  }
 @Override
 public void contextInitialized(ServletContextEvent event) {
   System.out.println("初始化系统的上下文,初始化所有的bean");
   super.contextInitialized(event);
 }