Пример #1
0
 @Override
 public void setContextPath(String contextPath) {
   if (StringUtils.isNullOrEmpty(contextPath) || "/".equals(contextPath.trim())) {
     this.contextPath = "";
   } else {
     this.contextPath = StringUtils.addStart(contextPath, "/");
   }
 }
Пример #2
0
 @Override
 public void setApplicationPath(String applicationPath) {
   if (StringUtils.isNullOrEmpty(applicationPath) || "/".equals(applicationPath.trim())) {
     this.applicationPath = "";
   } else {
     this.applicationPath = StringUtils.removeEnd(StringUtils.addStart(applicationPath, "/"), "/");
   }
 }
Пример #3
0
  protected void validateRoute(Route route) {
    // validate the request method
    if (StringUtils.isNullOrEmpty(route.getRequestMethod())) {
      throw new PippoRuntimeException("Unspecified request method!");
    }

    // validate the uri pattern
    String uriPattern = route.getUriPattern();
    if (StringUtils.isNullOrEmpty(uriPattern)) {
      throw new PippoRuntimeException("The uri pattern cannot be null or empty");
    }
  }
Пример #4
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);
    }
  }
Пример #5
0
 /**
  * Prefix the given path with the application path.
  *
  * @param path
  * @return an absolute path
  */
 protected String prefixApplicationPath(String path) {
   return applicationPath + StringUtils.addStart(path, "/");
 }
Пример #6
0
 private void removeBinding(Route route) {
   String nameOrUriPattern =
       StringUtils.isNullOrEmpty(route.getName()) ? route.getUriPattern() : route.getName();
   PatternBinding binding = getBinding(nameOrUriPattern);
   bindingsCache.get(route.getRequestMethod()).remove(binding);
 }
Пример #7
0
 @Override
 public void ignorePaths(String... pathPrefixes) {
   for (String pathPrefix : pathPrefixes) {
     this.ignorePaths.add(StringUtils.addStart(pathPrefix, "/"));
   }
 }