Exemple #1
0
 public String getClassname(HttpServletRequest request) throws Exception {
   // TODO Auto-generated method stub
   if (initialize.compareAndSet(false, true)) {
     handlerMap = mWebApplicationContext.beansOfClassname();
   }
   String classname = handlerMap.get(getHandlerName(request));
   if (classname == null) {
     classname = handlerMap.get("404");
   }
   return classname;
 }
Exemple #2
0
 private WebApplicationContext initWebApplicationContext() {
   WebApplicationContext wac = new WebApplicationContext(getServletContext());
   wac.init();
   return wac;
 }
  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);
              }
            });
  }