public String normalizeServletPath()

in apm-agent-plugins/apm-servlet-plugin/src/main/java/co/elastic/apm/agent/servlet/ServletTransactionHelper.java [190:228]


    public String normalizeServletPath(String requestURI, @Nullable String contextPath, @Nullable String servletPath, @Nullable String pathInfo) {
        String path = servletPath;
        if (path != null && !path.isEmpty()) {
            return path;
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Empty servlet path fallback applied. requestURI = {}, contextPath = {}, servletPath = {}, pathInfo = {}", requestURI, contextPath, servletPath, pathInfo);
        }

        int start = 0;
        int end = requestURI.length();
        boolean hasPathInfo = false;

        if (pathInfo != null && pathInfo.length() > 0) {
            end -= pathInfo.length();
            hasPathInfo = true;
        }

        if (contextPath != null && contextPath.length() > 0) {
            if (!contextPath.equals("/")) {
                start = contextPath.length();
            }
        }

        if (hasPathInfo ||  start < end ) {
            if (start < end) {
                path = requestURI.substring(start, end);
            } else {
                path = "";
            }
        } else {
            path = requestURI;
        }

        logger.debug("servlet path normalized to {}", path);

        return path;
    }