コード例 #1
0
  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
    if (System.getProperty("pippo.hideLogo") == null) {
      log.info(PippoUtils.getPippoLogo());
    }

    // check for runtime mode in filter init parameter
    String mode = filterConfig.getInitParameter(MODE_PARAM);
    if (!StringUtils.isNullOrEmpty(mode)) {
      System.setProperty(PippoConstants.SYSTEM_PROPERTY_PIPPO_MODE, mode);
    }

    if (application == null) {
      createApplication(filterConfig);
      log.debug("Created application '{}'", application);
    }

    ServletContext servletContext = filterConfig.getServletContext();
    application.setServletContext(servletContext);

    try {
      String contextPath = StringUtils.addStart(servletContext.getContextPath(), "/");
      application.getRouter().setContextPath(contextPath);

      if (filterPath == null) {
        initFilterPath(filterConfig);
      }
      String applicationPath =
          StringUtils.addEnd(contextPath, "/") + StringUtils.removeStart(filterPath, "/");
      application.getRouter().setApplicationPath(applicationPath);

      if (!contextPath.equals(applicationPath)) {
        log.debug("Context path is '{}'", contextPath);
      }
      log.debug("Serving application on path '{}'", applicationPath);

      log.debug("Initializing Route Dispatcher");
      routeDispatcher = new RouteDispatcher(application);
      routeDispatcher.init();

      String runtimeMode = application.getRuntimeMode().toString().toUpperCase();
      log.info("Pippo started ({})", runtimeMode);
    } catch (Exception e) {
      destroy();
      throw new ServletException(e);
    }
  }