예제 #1
0
  public static void apply(final ServletContext context) {
    // Maybe configurable?
    context.removeAttribute("javax.faces.FACELETS_REFRESH_PERIOD");
    context.setAttribute("javax.faces.FACELETS_REFRESH_PERIOD", "1");

    context.removeAttribute("facelets.REFRESH_PERIOD");
    context.setAttribute("facelets.REFRESH_PERIOD", "1");

    context.removeAttribute("javax.faces.PROJECT_STAGE");
    context.setAttribute("javax.faces.PROJECT_STAGE", "Development");

    context.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", "1");
    context.setInitParameter("javax.faces.PROJECT_STAGE", "Development");
    context.setInitParameter("facelets.REFRESH_PERIOD", "1");

    if (LOGGER.isLevelEnabled(Level.TRACE)) {
      Enumeration<String> names = context.getAttributeNames();
      if (names != null) {
        while (names.hasMoreElements()) {
          String k = names.nextElement();
          LOGGER.trace("CONTEXT ATTRIBUTE {} value: {}", k, context.getAttribute(k));
        }
      }

      names = context.getInitParameterNames();
      if (names != null) {
        while (names.hasMoreElements()) {
          String k = names.nextElement();
          LOGGER.trace("CONTEXT INIT PARAM {} value: {}", k, context.getInitParameter(k));
        }
      }
    }
  }
  @Test
  public void access_of_keys_is_case_insensitive() {
    ServletContext context = newMock(ServletContext.class);

    String key1 = "fred";
    String value1 = "Fred Flintstone";
    String key2 = "barney";
    String value2 = "Barney Rubble";

    expect(context.getInitParameterNames()).andReturn(toEnumeration(key1, key2));

    expect(context.getInitParameter(key1)).andReturn(value1);
    expect(context.getInitParameter(key2)).andReturn(value2);

    replay();

    SymbolProvider p = new ServletContextSymbolProvider(context);

    assertEquals(p.valueForSymbol(key1), value1);
    assertEquals(p.valueForSymbol(key2), value2);

    // Not in config is null
    assertNull(p.valueForSymbol("wilma"));

    // Check for case insensitivity
    assertEquals(p.valueForSymbol("FRED"), value1);

    verify();
  }
예제 #3
0
  /**
   * Adds all com.sun.faces init parameter names to a list. This allows callers to determine if a
   * parameter was explicitly set.
   *
   * @param servletContext the ServletContext of interest
   */
  private void initSetList(ServletContext servletContext) {

    for (Enumeration e = servletContext.getInitParameterNames(); e.hasMoreElements(); ) {
      String name = e.nextElement().toString();
      if (name.startsWith("com.sun.faces") || name.startsWith("javax.faces")) {
        setParams.add(name);
      }
    }
  }
예제 #4
0
 private Map<String, String> getInitParametersAsMap(ServletContext context) {
   Map<String, String> initParameters = new HashMap<String, String>();
   Enumeration<String> e = context.getInitParameterNames();
   while (e.hasMoreElements()) {
     String initParameterName = e.nextElement();
     initParameters.put(initParameterName, context.getInitParameter(initParameterName));
   }
   return initParameters;
 }
예제 #5
0
  @Test
  public void getSetInitParameters() {
    ServletContext context = new ServletContext1(new MockWebContext());
    // name0 = value0
    context.setInitParameter("name0", "value0");
    Enumeration<String> initParametersNames = context.getInitParameterNames();
    assertTrue(initParametersNames.hasMoreElements());
    assertEquals("name0", initParametersNames.nextElement());
    assertFalse(initParametersNames.hasMoreElements());

    assertEquals("value0", context.getInitParameter("name0"));
    assertNull(context.getInitParameter("name1"));

    // name0 = value0, name1 = value1
    context.setInitParameter("name1", "value1");
    initParametersNames = context.getInitParameterNames();
    assertTrue(initParametersNames.hasMoreElements());
    String name = initParametersNames.nextElement();
    assertTrue(name.equals("name0") || name.equals("name1"));
    assertTrue(initParametersNames.hasMoreElements());
    name = initParametersNames.nextElement();
    assertTrue(name.equals("name0") || name.equals("name1"));
    assertFalse(initParametersNames.hasMoreElements());

    assertEquals("value0", context.getInitParameter("name0"));
    assertEquals("value1", context.getInitParameter("name1"));

    // name0 = edited, name1 = value1
    assertFalse(context.setInitParameter("name0", "edited"));
    initParametersNames = context.getInitParameterNames();
    assertTrue(initParametersNames.hasMoreElements());
    name = initParametersNames.nextElement();
    assertTrue(name.equals("name0") || name.equals("name1"));
    assertTrue(initParametersNames.hasMoreElements());
    name = initParametersNames.nextElement();
    assertTrue(name.equals("name0") || name.equals("name1"));
    assertFalse(initParametersNames.hasMoreElements());

    assertEquals("value0", context.getInitParameter("name0"));
    assertEquals("value1", context.getInitParameter("name1"));
  }
예제 #6
0
  public GenericWebAppContext(
      ServletContext servletContext,
      HttpServletRequest request,
      HttpServletResponse response,
      SessionProvider sessionProvider,
      ManageableRepository repository) {

    initialize(servletContext, request, response);

    this.sessionProvider = sessionProvider;
    this.repository = repository;

    // log.info("WEb context ---------------");
    // initialize context with all props
    Enumeration en = servletContext.getInitParameterNames();
    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      put(name, servletContext.getInitParameter(name));
      LOG.debug("ServletContext init param: " + name + "=" + servletContext.getInitParameter(name));
    }

    en = servletContext.getAttributeNames();
    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      put(name, servletContext.getAttribute(name));
      LOG.debug("ServletContext: " + name + "=" + servletContext.getAttribute(name));
    }

    HttpSession session = request.getSession(false);
    if (session != null) {
      en = session.getAttributeNames();
      while (en.hasMoreElements()) {
        String name = (String) en.nextElement();
        put(name, session.getAttribute(name));
        LOG.debug("Session: " + name + "=" + session.getAttribute(name));
      }
    }

    en = request.getAttributeNames();
    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      put(name, request.getAttribute(name));
    }

    en = request.getParameterNames();
    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      put(name, request.getParameter(name));
      LOG.debug("Request: " + name + "=" + request.getParameter(name));
    }
  }
  protected Properties getContextParameters(ServletContext servletContext) {

    Properties properties = new Properties();
    Enumeration parameterNames = servletContext.getInitParameterNames();
    while (parameterNames.hasMoreElements()) {

      String paramName = (String) parameterNames.nextElement();
      String parameter = servletContext.getInitParameter(paramName);
      if (parameter != null && !parameter.isEmpty()) {
        System.out.println("Setting " + paramName + " to " + parameter);
        properties.put(paramName, parameter);
      }
    }

    return properties;
  }
  /**
   * Register web-specific environment beans ("contextParameters", "contextAttributes") with the
   * given BeanFactory, as used by the WebApplicationContext.
   *
   * @param bf the BeanFactory to configure
   * @param sc the ServletContext that we're running within
   * @param config the ServletConfig of the containing Portlet
   */
  public static void registerEnvironmentBeans(
      ConfigurableListableBeanFactory bf, ServletContext sc, ServletConfig config) {

    if (sc != null && !bf.containsBean(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME)) {
      bf.registerSingleton(WebApplicationContext.SERVLET_CONTEXT_BEAN_NAME, sc);
    }

    if (config != null
        && !bf.containsBean(ConfigurableWebApplicationContext.SERVLET_CONFIG_BEAN_NAME)) {
      bf.registerSingleton(ConfigurableWebApplicationContext.SERVLET_CONFIG_BEAN_NAME, config);
    }

    if (!bf.containsBean(WebApplicationContext.CONTEXT_PARAMETERS_BEAN_NAME)) {
      Map<String, String> parameterMap = new HashMap<String, String>();
      if (sc != null) {
        Enumeration<?> paramNameEnum = sc.getInitParameterNames();
        while (paramNameEnum.hasMoreElements()) {
          String paramName = (String) paramNameEnum.nextElement();
          parameterMap.put(paramName, sc.getInitParameter(paramName));
        }
      }
      if (config != null) {
        Enumeration<?> paramNameEnum = config.getInitParameterNames();
        while (paramNameEnum.hasMoreElements()) {
          String paramName = (String) paramNameEnum.nextElement();
          parameterMap.put(paramName, config.getInitParameter(paramName));
        }
      }
      bf.registerSingleton(
          WebApplicationContext.CONTEXT_PARAMETERS_BEAN_NAME,
          Collections.unmodifiableMap(parameterMap));
    }

    if (!bf.containsBean(WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME)) {
      Map<String, Object> attributeMap = new HashMap<String, Object>();
      if (sc != null) {
        Enumeration<?> attrNameEnum = sc.getAttributeNames();
        while (attrNameEnum.hasMoreElements()) {
          String attrName = (String) attrNameEnum.nextElement();
          attributeMap.put(attrName, sc.getAttribute(attrName));
        }
      }
      bf.registerSingleton(
          WebApplicationContext.CONTEXT_ATTRIBUTES_BEAN_NAME,
          Collections.unmodifiableMap(attributeMap));
    }
  }
예제 #9
0
  protected final void logInitParameters(@Nonnull final ServletContext aSC) {
    // Put them in a sorted map
    final Map<String, String> aParams = new TreeMap<String, String>();
    final Enumeration<?> aEnum = aSC.getInitParameterNames();
    while (aEnum.hasMoreElements()) {
      final String sName = (String) aEnum.nextElement();
      final String sValue = aSC.getInitParameter(sName);
      aParams.put(sName, sValue);
    }

    if (aParams.isEmpty()) s_aLogger.info("No servlet context init-parameters present");
    else {
      // Emit them
      s_aLogger.info("Servlet context init-parameters:");
      for (final Map.Entry<String, String> aEntry : aParams.entrySet())
        s_aLogger.info("  " + aEntry.getKey() + "=" + aEntry.getValue());
    }
  }
 @Test
 public void onDifferentPortInServletContainer() throws Exception {
   this.applicationContext.register(
       RootConfig.class,
       EndpointConfig.class,
       DifferentPortConfig.class,
       BaseConfiguration.class,
       EndpointWebMvcAutoConfiguration.class,
       ErrorMvcAutoConfiguration.class);
   ServletContext servletContext = mock(ServletContext.class);
   given(servletContext.getInitParameterNames()).willReturn(new Vector<String>().elements());
   given(servletContext.getAttributeNames()).willReturn(new Vector<String>().elements());
   this.applicationContext.setServletContext(servletContext);
   this.applicationContext.refresh();
   assertContent("/controller", ports.get().management, null);
   assertContent("/endpoint", ports.get().management, null);
   this.applicationContext.close();
   assertAllClosed();
 }
예제 #11
0
  private void servletEnv() {
    if (!log.isDebugEnabled()) return;

    try {
      java.net.URL url = servletContext.getResource("/");
      log.trace("Joseki base directory: " + url);
    } catch (Exception ex) {
    }

    if (servletConfig != null) {
      String tmp = servletConfig.getServletName();
      log.trace("Servlet = " + (tmp != null ? tmp : "<null>"));
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletConfig.getInitParameterNames();

      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.trace("Servlet parameter: " + s + " = " + servletConfig.getInitParameter(s));
      }
    }
    if (servletContext != null) {
      // Name of webapp
      String tmp = servletContext.getServletContextName();
      // msg(Level.FINE, "Webapp = " + (tmp != null ? tmp : "<null>"));
      log.debug("Webapp = " + (tmp != null ? tmp : "<null>"));

      // NB This servlet may not have been loaded as part of a web app
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletContext.getInitParameterNames();
      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.debug("Webapp parameter: " + s + " = " + servletContext.getInitParameter(s));
      }
    }
    /*
    for ( Enumeration enum = servletContext.getAttributeNames() ;  enum.hasMoreElements() ; )
    {
        String s = (String)enum.nextElement() ;
        logger.log(LEVEL, "Webapp attribute: "+s+" = "+context.getAttribute(s)) ;
    }
     */
  }
  public List getApplicationInitParams(Context context) {
    // We'll try to determine if a parameter value comes from a deployment descriptor or a context
    // descriptor.
    // assumption: Context.findParameter() returns only values of parameters that are declared in a
    // deployment descriptor.
    // If a parameter is declared in a context descriptor with override=false and redeclared in a
    // deployment descriptor,
    // Context.findParameter() still returns its value, even though the value is taken from a
    // context descriptor.
    // context.findApplicationParameters() returns all parameters that are declared in a context
    // descriptor regardless
    // of whether they are overridden in a deployment descriptor or not or not.

    // creating a set of parameter names that are declared in a context descriptor
    // and can not be ovevridden in a deployment descriptor.
    Set nonOverridableParams = new HashSet();
    ApplicationParameter[] appParams = context.findApplicationParameters();
    for (int i = 0; i < appParams.length; i++) {
      if (appParams[i] != null && !appParams[i].getOverride()) {
        nonOverridableParams.add(appParams[i].getName());
      }
    }

    List initParams = new ArrayList();
    ServletContext servletCtx = context.getServletContext();
    for (Enumeration e = servletCtx.getInitParameterNames(); e.hasMoreElements(); ) {
      String paramName = (String) e.nextElement();

      ApplicationParam param = new ApplicationParam();
      param.setName(paramName);
      param.setValue(servletCtx.getInitParameter(paramName));
      // if the parameter is declared in a deployment descriptor
      // and it is not declared in a context descriptor with override=false,
      // the value comes from the deployment descriptor
      param.setFromDeplDescr(
          context.findParameter(paramName) != null && !nonOverridableParams.contains(paramName));
      initParams.add(param);
    }

    return initParams;
  }
예제 #13
0
  /**
   * Initializes the servlet context, based on the servlet context. Parses all context parameters
   * and passes them on to the database context.
   *
   * @param sc servlet context
   * @throws IOException I/O exception
   */
  static synchronized void init(final ServletContext sc) throws IOException {
    // skip process if context has already been initialized
    if (context != null) return;

    // set servlet path as home directory
    final String path = sc.getRealPath("/");
    System.setProperty(Prop.PATH, path);

    // parse all context parameters
    final HashMap<String, String> map = new HashMap<String, String>();
    // store default web root
    map.put(MainProp.HTTPPATH[0].toString(), path);

    final Enumeration<?> en = sc.getInitParameterNames();
    while (en.hasMoreElements()) {
      final String key = en.nextElement().toString();
      if (!key.startsWith(Prop.DBPREFIX)) continue;

      // only consider parameters that start with "org.basex."
      String val = sc.getInitParameter(key);
      if (eq(key, DBUSER, DBPASS, DBMODE, DBVERBOSE)) {
        // store servlet-specific parameters as system properties
        System.setProperty(key, val);
      } else {
        // prefix relative paths with absolute servlet path
        if (key.endsWith("path") && !new File(val).isAbsolute()) {
          val = path + File.separator + val;
        }
        // store remaining parameters (without project prefix) in map
        map.put(key.substring(Prop.DBPREFIX.length()).toUpperCase(Locale.ENGLISH), val);
      }
    }
    context = new Context(map);

    if (SERVER.equals(System.getProperty(DBMODE))) {
      new BaseXServer(context);
    } else {
      context.log = new Log(context);
    }
  }
예제 #14
0
  public static void showServletInfo(HttpServlet servlet, PrintStream out) {
    out.println("Servlet Info");
    out.println(" getServletName(): " + servlet.getServletName());
    out.println(" getRootPath(): " + getRootPath());
    out.println(" Init Parameters:");
    Enumeration params = servlet.getInitParameterNames();
    while (params.hasMoreElements()) {
      String name = (String) params.nextElement();
      out.println("  " + name + ": " + servlet.getInitParameter(name));
    }
    out.println();

    ServletContext context = servlet.getServletContext();
    out.println("Context Info");

    try {
      out.println(" context.getResource('/'): " + context.getResource("/"));
    } catch (java.net.MalformedURLException e) {
    } // cant happen
    out.println(" context.getServerInfo(): " + context.getServerInfo());
    out.println("  name: " + getServerInfoName(context.getServerInfo()));
    out.println("  version: " + getServerInfoVersion(context.getServerInfo()));

    out.println(" context.getInitParameterNames():");
    params = context.getInitParameterNames();
    while (params.hasMoreElements()) {
      String name = (String) params.nextElement();
      out.println("  " + name + ": " + context.getInitParameter(name));
    }

    out.println(" context.getAttributeNames():");
    params = context.getAttributeNames();
    while (params.hasMoreElements()) {
      String name = (String) params.nextElement();
      out.println("  context.getAttribute(\"" + name + "\"): " + context.getAttribute(name));
    }

    out.println();
  }
예제 #15
0
  /**
   * Initializes the database context, based on the initial servlet context. Parses all context
   * parameters and passes them on to the database context.
   *
   * @param sc servlet context
   * @throws IOException I/O exception
   */
  public static synchronized void init(final ServletContext sc) throws IOException {
    // check if HTTP context has already been initialized
    if (init) return;
    init = true;

    // set web application path as home directory and HTTPPATH
    final String webapp = sc.getRealPath("/");
    Options.setSystem(Prop.PATH, webapp);
    Options.setSystem(GlobalOptions.WEBPATH, webapp);

    // bind all parameters that start with "org.basex." to system properties
    final Enumeration<String> en = sc.getInitParameterNames();
    while (en.hasMoreElements()) {
      final String key = en.nextElement();
      if (!key.startsWith(Prop.DBPREFIX)) continue;

      String val = sc.getInitParameter(key);
      if (key.endsWith("path") && !new File(val).isAbsolute()) {
        // prefix relative path with absolute servlet path
        Util.debug(key.toUpperCase(Locale.ENGLISH) + ": " + val);
        val = new IOFile(webapp, val).path();
      }
      Options.setSystem(key, val);
    }

    // create context, update options
    if (context == null) {
      context = new Context(false);
    } else {
      context.globalopts.setSystem();
      context.options.setSystem();
    }

    // start server instance
    if (!context.globalopts.get(GlobalOptions.HTTPLOCAL)) new BaseXServer(context);
  }
 @SuppressWarnings("rawtypes")
 public Enumeration getInitParameterNames() {
   return context.getInitParameterNames();
 }
예제 #17
0
 public Enumeration getInitParameterNames() {
   return delegate.getInitParameterNames();
 }
예제 #18
0
 @Test
 public void emptyInitParameters() {
   ServletContext context = new ServletContext1(new MockWebContext());
   Enumeration<String> initParameterNames = context.getInitParameterNames();
   assertFalse(initParameterNames.hasMoreElements());
 }
예제 #19
0
  @Test
  public void testPluginWithServletRefreshedAfterOtherPluginUpgraded() throws Exception {
    final PluginJarBuilder firstBuilder = new PluginJarBuilder("first");
    firstBuilder
        .addPluginInformation("first", "Some name", "1.0")
        .addFormattedJava("first.MyInterface", "package first;", "public interface MyInterface {}")
        .addFormattedResource(
            "META-INF/MANIFEST.MF",
            "Manifest-Version: 1.0",
            "Bundle-SymbolicName: first",
            "Bundle-Version: 1.0",
            "Export-Package: first",
            "")
        .build(pluginsDir);

    new PluginJarBuilder("asecond", firstBuilder.getClassLoader())
        .addFormattedResource(
            "maera-plugin.xml",
            "<maera-plugin name='Test' key='asecond' pluginsVersion='2'>",
            "    <plugin-info>",
            "        <version>1.0</version>",
            "    </plugin-info>",
            "    <servlet key='foo' class='second.MyServlet'>",
            "       <url-pattern>/foo</url-pattern>",
            "    </servlet>",
            "</maera-plugin>")
        .addFormattedJava(
            "second.MyServlet",
            "package second;",
            "import org.maera.plugin.osgi.Callable2;",
            "public class MyServlet extends javax.servlet.http.HttpServlet implements first.MyInterface {",
            "   private Callable2 callable;",
            "   public MyServlet(Callable2 cal) { this.callable = cal; }",
            "   public String getServletInfo() {",
            "       try {return callable.call() + ' bob';} catch (Exception ex) { throw new RuntimeException(ex);}",
            "   }",
            "}")
        .build(pluginsDir);

    HostComponentProvider prov =
        new HostComponentProvider() {

          public void provide(ComponentRegistrar registrar) {
            registrar
                .register(Callable2.class)
                .forInstance(
                    new Callable2() {

                      public String call() {
                        return "hi";
                      }
                    });
          }
        };

    ServletContext ctx = mock(ServletContext.class);
    when(ctx.getInitParameterNames()).thenReturn(Collections.enumeration(Collections.emptyList()));
    ServletConfig servletConfig = mock(ServletConfig.class);
    when(servletConfig.getServletContext()).thenReturn(ctx);

    ServletModuleManager mgr = new DefaultServletModuleManager(pluginEventManager);
    hostContainer =
        createHostContainer(
            Collections.<Class<?>, Object>singletonMap(ServletModuleManager.class, mgr));
    initPluginManager(
        prov,
        new SingleModuleDescriptorFactory(hostContainer, "servlet", ServletModuleDescriptor.class));

    assertEquals(2, pluginManager.getEnabledPlugins().size());
    assertTrue(pluginManager.getPlugin("first").getPluginState() == PluginState.ENABLED);
    assertNotNull(pluginManager.getPlugin("asecond").getPluginState() == PluginState.ENABLED);
    assertEquals("hi bob", mgr.getServlet("/foo", servletConfig).getServletInfo());

    final File updatedJar =
        new PluginJarBuilder("first-updated")
            .addPluginInformation("foo", "Some name", "1.0")
            .addFormattedJava(
                "first.MyInterface", "package first;", "public interface MyInterface {}")
            .addFormattedResource(
                "META-INF/MANIFEST.MF",
                "Manifest-Version: 1.0",
                "Bundle-SymbolicName: foo",
                "Bundle-Version: 1.0",
                "Export-Package: first",
                "")
            .build();
    pluginManager.installPlugin(new JarPluginArtifact(updatedJar));

    WaitUntil.invoke(
        new BasicWaitCondition() {

          public boolean isFinished() {
            return pluginManager.isPluginEnabled("asecond");
          }
        });

    assertEquals("hi bob", mgr.getServlet("/foo", servletConfig).getServletInfo());
  }
예제 #20
0
 @Override
 public Enumeration<String> getInitParameterNames() {
   return proxy.getInitParameterNames();
 }
예제 #21
0
 /** {@inheritDoc} */
 public Enumeration getNames() {
   return servletContext.getInitParameterNames();
 }
  public void contextInitialized(final ServletContextEvent event) {

    context = event.getServletContext();

    String encoding = getServerParameter("encoding"); // $NON-NLS-1$
    if (encoding != null) {
      LocaleHelper.setSystemEncoding(encoding);
    }

    String textDirection = getServerParameter("text-direction"); // $NON-NLS-1$
    if (textDirection != null) {
      LocaleHelper.setTextDirection(textDirection);
    }

    String localeLanguage = getServerParameter("locale-language"); // $NON-NLS-1$
    String localeCountry = getServerParameter("locale-country"); // $NON-NLS-1$
    boolean localeSet = false;
    if (!StringUtils.isEmpty(localeLanguage) && !StringUtils.isEmpty(localeCountry)) {
      Locale[] locales = Locale.getAvailableLocales();
      if (locales != null) {
        for (Locale element : locales) {
          if (element.getLanguage().equals(localeLanguage)
              && element.getCountry().equals(localeCountry)) {
            LocaleHelper.setLocale(element);
            localeSet = true;
            break;
          }
        }
      }
    }
    if (!localeSet) {
      // do this thread in the default locale
      LocaleHelper.setLocale(Locale.getDefault());
    }
    LocaleHelper.setDefaultLocale(LocaleHelper.getLocale());
    // log everything that goes on here
    logger.info(
        Messages.getInstance()
            .getString("SolutionContextListener.INFO_INITIALIZING")); // $NON-NLS-1$
    logger.info(
        Messages.getInstance()
            .getString("SolutionContextListener.INFO_SERVLET_CONTEXT", context)); // $NON-NLS-1$
    SolutionContextListener.contextPath = context.getRealPath(""); // $NON-NLS-1$
    logger.info(
        Messages.getInstance()
            .getString(
                "SolutionContextListener.INFO_CONTEXT_PATH",
                SolutionContextListener.contextPath)); // $NON-NLS-1$

    SolutionContextListener.solutionPath = PentahoHttpSessionHelper.getSolutionPath(context);
    if (StringUtils.isEmpty(SolutionContextListener.solutionPath)) {
      String errorMsg =
          Messages.getInstance()
              .getErrorString("SolutionContextListener.ERROR_0001_NO_ROOT_PATH"); // $NON-NLS-1$
      logger.error(errorMsg);
      /*
       * Since we couldn't find solution repository path there is no point in going forward and the user should know
       * that a major config setting was not found. So we are throwing in a RunTimeException with the requisite message.
       */
      throw new RuntimeException(errorMsg);
    }

    logger.info(
        Messages.getInstance()
            .getString(
                "SolutionContextListener.INFO_ROOT_PATH",
                SolutionContextListener.solutionPath)); // $NON-NLS-1$

    String fullyQualifiedServerUrl =
        getServerParameter("fully-qualified-server-url"); // $NON-NLS-1$
    if (fullyQualifiedServerUrl == null) {
      // assume this is a demo installation
      // TODO: Create a servlet that's loaded on startup to set this value
      fullyQualifiedServerUrl = "http://localhost:8080/pentaho/"; // $NON-NLS-1$
    }

    IApplicationContext applicationContext =
        new WebApplicationContext(
            SolutionContextListener.solutionPath,
            fullyQualifiedServerUrl,
            context.getRealPath(""),
            context); //$NON-NLS-1$

    /*
     * Copy out all the Server.properties from to the application context
     */
    Properties props = new Properties();
    ISystemConfig systemConfig = PentahoSystem.get(ISystemConfig.class);
    if (systemConfig != null) {
      IConfiguration config = systemConfig.getConfiguration("server");
      if (config != null) {
        try {
          props.putAll(config.getProperties());
        } catch (IOException e) {
          logger.error("Could not find/read the server.properties file.");
        }
      }
    }

    /*
     * Copy out all the initParameter values from the servlet context and put them in the application context.
     */
    Enumeration<?> initParmNames = context.getInitParameterNames();
    String initParmName;
    while (initParmNames.hasMoreElements()) {
      initParmName = (String) initParmNames.nextElement();
      props.setProperty(initParmName, getServerParameter(initParmName, true));
    }
    ((WebApplicationContext) applicationContext).setProperties(props);

    setSystemCfgFile(context);
    setObjectFactory(context);

    PentahoSystem.init(applicationContext, true);

    final String fullyQualifiedServerUrlOut = fullyQualifiedServerUrl;
    ServerStatusProvider.getInstance()
        .registerServerStatusChangeListener(
            new IServerStatusChangeListener() {
              @Override
              public void onStatusChange() {
                if (ServerStatusProvider.getInstance().getStatus()
                    != IServerStatusProvider.ServerStatus.STARTING) {
                  showInitializationMessage(
                      ServerStatusProvider.getInstance().getStatus()
                          == IServerStatusProvider.ServerStatus.STARTED,
                      fullyQualifiedServerUrlOut);
                }
                ServerStatusProvider.getInstance().removeServerStatusChangeListener(this);
              }
            });
  }