code: private String extractPathFromPattern(final HttpServletRequest request) {
          String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
          String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
          AntPathMatcher apm = new AntPathMatcher();
          String finalPath = apm.extractPathWithinPattern(bestMatchPattern, path);
          return finalPath;
      }
docs: Due to some Spring MVC oddities with pattern matching, the following
  method was put in place to correctly extract the path from the URL path
  (remember, the URL path contains more information than just the image
  path).
  
  @param request
  Request
  @return The public image path.