tds/src/main/java/thredds/util/TdsPathUtils.java
public static String extractPath(HttpServletRequest req, String removePrefix) {

    // may be in pathInfo (Servlet) or servletPath (Controller)
    String dataPath = req.getPathInfo();
    if (dataPath == null) {
      dataPath = req.getServletPath();
    }
    if (dataPath == null)  // not sure if this is possible
      return "";

    // removePrefix or "/"+removePrefix
    if (removePrefix != null) {
      if (dataPath.startsWith(removePrefix)) {
        dataPath = dataPath.substring(removePrefix.length());

      } else if (dataPath.startsWith("/")) {
        dataPath = dataPath.substring(1);
        if (dataPath.startsWith(removePrefix))
          dataPath = dataPath.substring(removePrefix.length());
      }

    }

    if (dataPath.startsWith("/"))
      dataPath = dataPath.substring(1);

    if (dataPath.contains(".."))  // LOOK what about escapes ??
      throw new IllegalArgumentException("path cannot contain '..'");

    return dataPath;
  }
public static String extractPath(HttpServletRequest req, String removePrefix) {

    // may be in pathInfo (Servlet) or servletPath (Controller)
    String dataPath = req.getPathInfo();
    if (dataPath == null) {
      dataPath = req.getServletPath();
    }
    if (dataPath == null)  // not sure if this is possible
      return "";

    // removePrefix or "/"+removePrefix
    if (removePrefix != null) {
      if (dataPath.startsWith(removePrefix)) {
        dataPath = dataPath.substring(removePrefix.length());

      } else if (dataPath.startsWith("/")) {
        dataPath = dataPath.substring(1);
        if (dataPath.startsWith(removePrefix))
          dataPath = dataPath.substring(removePrefix.length());
      }

    }

    if (dataPath.startsWith("/"))
      dataPath = dataPath.substring(1);

    if (dataPath.contains(".."))  // LOOK what about escapes ??
      throw new IllegalArgumentException("path cannot contain '..'");

    return dataPath;
  }
public static String extractPath ( HttpServletRequest req , String removePrefix ) { // may be in pathInfo (Servlet) or servletPath (Controller) String dataPath = req . getPathInfo ( ) ; if ( dataPath == null ) { dataPath = req . getServletPath ( ) ; } if ( dataPath == null ) // not sure if this is possible return "" ; // removePrefix or "/"+removePrefix if ( removePrefix != null ) { if ( dataPath . startsWith ( removePrefix ) ) { dataPath = dataPath . substring ( removePrefix . length ( ) ) ; } else if ( dataPath . startsWith ( "/" ) ) { dataPath = dataPath . substring ( 1 ) ; if ( dataPath . startsWith ( removePrefix ) ) dataPath = dataPath . substring ( removePrefix . length ( ) ) ; } } if ( dataPath . startsWith ( "/" ) ) dataPath = dataPath . substring ( 1 ) ; if ( dataPath . contains ( ".." ) ) // LOOK what about escapes ?? throw new IllegalArgumentException ( "path cannot contain '..'" ) ; return dataPath ; }
For "removePrefix/path" style servlet mappings.
For removePrefix / path style servlet mappings .