Uploaded image for project: 'Apache Roller'
  1. Apache Roller
  2. ROL-2075

InitFilter#getAbsoluteUrl() returns wrong URL which got last character removed

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 5.1.2
    • 5.2.0
    • None
    • Tomcat/7.0.54

    Description

      Roller produces wrong URLs that based on InitFilter#getAbsoluteUrl() in following situation:

      • site.absoluteurl is not set
      • Roller is deployed on "/" (as ROOT.war)
      • The first request after deployment comes as a HTTPS request to GET "/"

      Problematic code:

      String fullUrl = null;
      
      if (!request.isSecure()) {
          fullUrl = request.getRequestURL().toString();
      } else {
          fullUrl = "http://" + request.getServerName()
                  + request.getContextPath();
      }
      

      In the preceding block,

      • request.isSecure() returns true
      • request.getServerName() returns "localhost"
      • request.getContextPath() returns ""

      So now fullUrl is http://localhost. then here comes following block:

      // if the uri is only "/" then we are basically done
      if ("/".equals(request.getRequestURI())) {
          if (log.isDebugEnabled()) {
              log.debug(fullUrl.substring(0, fullUrl.length() - 1));
          }
          return fullUrl.substring(0, fullUrl.length() - 1);
      }
      

      request.getRequestURI() returns "/". then following fullUrl.substring() truncates the last character, and now URL is http://localhos.

      DEBUG log (actual URLs are masked by ***):

      INFO  2015-04-29 00:11:28,357 PreviewServlet:init - Initializing PreviewServlet
      DEBUG 2015-04-29 00:11:38,512 CharEncodingFilter:doFilter - Processing CharEncodingFilter
      DEBUG 2015-04-29 00:11:38,514 CharEncodingFilter:doFilter - Set request character encoding to UTF-8
      DEBUG 2015-04-29 00:11:38,568 BootstrapFilter:doFilter - Entered /
      DEBUG 2015-04-29 00:11:38,569 WebloggerConfig:getProperty - Fetching property [installation.type=auto]
      DEBUG 2015-04-29 00:11:38,569 PersistenceSessionFilter:doFilter - Entered /
      DEBUG 2015-04-29 00:11:38,569 InitFilter:getAbsoluteUrl - http://***.rhcloud.co
      DEBUG 2015-04-29 00:11:38,569 InitFilter:doFilter - relPath = 
      DEBUG 2015-04-29 00:11:38,570 InitFilter:doFilter - absPath = http://***.rhcloud.co
      DEBUG 2015-04-29 00:11:38,570 RequestMappingFilter:doFilter - entering
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            roller_unassigned Roller Unassigned
            xkylex Kohei Nozaki
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment