コード例 #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);
    }
  }
コード例 #2
0
  @Override
  public void doFilter(
      ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
      throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
    HttpServletResponse httpServletResponse = (HttpServletResponse) servletResponse;

    // TODO test for redirect
    // no redirect; process the request

    // create Request, Response objects
    RequestResponseFactory requestResponseFactory = application.getRequestResponseFactory();
    Response response = requestResponseFactory.createResponse(httpServletResponse);
    Request request = requestResponseFactory.createRequest(httpServletRequest, response);

    // create a URI to automatically decode the path
    URI uri = URI.create(httpServletRequest.getRequestURL().toString());
    String requestUri = uri.getPath();
    String requestPath = request.getPath();

    log.trace("The relative path for '{}' is '{}'", requestUri, requestPath);

    // check for ignore path
    if (shouldIgnorePath(requestPath)) {
      log.debug("Ignoring request '{}'", requestPath);
      if (chain != null) {
        chain.doFilter(servletRequest, servletResponse);
      }

      return;
    }

    log.debug("Request {} '{}'", request.getMethod(), requestPath);

    // dispatch route(s)
    routeDispatcher.dispatch(request, response);
  }
コード例 #3
0
ファイル: Application.java プロジェクト: danjee/pippo
  public static Application get() {
    RouteContext routeContext = RouteDispatcher.getRouteContext();

    return (routeContext != null) ? routeContext.getApplication() : null;
  }