コード例 #1
0
 private void reloadRoutes() {
   if (loading || routesIsNotFile()) {
     return;
   }
   if (lastLoaded < 0
       || checkInterval >= 0 && System.currentTimeMillis() > lastLoaded + checkInterval * 1000) {
     synchronized (this) {
       if (!loading) loading = true;
       else return;
     }
     if (loading) {
       try {
         logger.debug("check update for routes.");
         if (routes.lastModified() > lastLoaded) {
           long t1 = System.currentTimeMillis();
           Routes.load(routes);
           long t2 = System.currentTimeMillis();
           logger.debug(String.format("reload routes(%dms).", (t2 - t1)));
         }
         lastLoaded = System.currentTimeMillis();
       } finally {
         loading = false;
       }
     }
   }
 }
コード例 #2
0
  public void init(FilterConfig config) throws ServletException {
    String access = config.getInitParameter("jspDirectAccess");
    if (StringUtil.isNotBlank(access)) {
      jspDirectAccess = Boolean.valueOf(access);
    }

    String routesPath = config.getInitParameter("routes");
    if (StringUtil.isNotEmpty(routesPath)) {
      String realRoutesPath = config.getServletContext().getRealPath(routesPath);
      if (realRoutesPath != null) {
        routes = new File(realRoutesPath);
      }
      InputStream routesStream = config.getServletContext().getResourceAsStream(routesPath);
      try {
        Routes.load(routesStream);
      } finally {
        InputStreamUtil.close(routesStream);
      }
      lastLoaded = System.currentTimeMillis();
    }

    String interval = config.getInitParameter("checkInterval");
    if (StringUtil.isNotEmpty(interval)) {
      checkInterval = LongConversionUtil.toLong(interval);
    }
    if (checkInterval == null || checkInterval < 0) {
      checkInterval = -1L;
    }

    String contextSensitiveParam = config.getInitParameter("contextSensitive");
    if (StringUtil.isNotBlank(contextSensitiveParam)) {
      contextSensitive = Boolean.valueOf(contextSensitiveParam);
    }
    if (contextSensitive) {
      try {
        Method getContextPath = ReflectionUtil.getMethod(ServletContext.class, "getContextPath");
        UrlRewriter.contextPath =
            (String) MethodUtil.invoke(getContextPath, config.getServletContext(), null);
      } catch (NoSuchMethodRuntimeException e) {
        UrlRewriter.contextPath = config.getServletContext().getServletContextName();
      }
    }
    requestUriHeader = config.getInitParameter("requestUriHeader");

    String fallThroughParam = config.getInitParameter("fallThrough");
    if (StringUtil.isNotBlank(fallThroughParam)) {
      fallThrough = Boolean.valueOf(fallThroughParam);
    }
  }