protected ModelAndView doHandle()

in teamcity-symbol-server/src/main/java/jetbrains/buildServer/symbols/DownloadSourcesController.java [44:69]


  protected ModelAndView doHandle(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws Exception {
    final String requestURI = request.getRequestURI();
    if(!requestURI.matches(VALID_URL_PATTERN)){
      WebUtil.notFound(request, response, "Url is invalid", null);
      return null;
    }

    final SUser user = myAuthHelper.getAuthenticatedUser(request, response, new Predicate<SUser>() {
      public boolean apply(SUser user) {
        return true;
      }
    });
    if (user == null) return null;

    String restMethodUrl = requestURI.replace("/builds/id-", "/builds/id:").replace("/app/sources/", "/app/rest/");
    final String contextPath = request.getContextPath();
    if(restMethodUrl.startsWith(contextPath)){
      restMethodUrl = restMethodUrl.substring(contextPath.length());
    }
    RequestDispatcher dispatcher = request.getRequestDispatcher(restMethodUrl);
    if (dispatcher != null) {
      LOG.debug(String.format("Forwarding request. From %s To %s", requestURI, restMethodUrl));
      dispatcher.forward(request, response);
    }
    return null;
  }