Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4843

DefaultUrlHelper().buildUrl() not outputting port when used as parameter

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.33
    • Fix Version/s: 2.5.14
    • Component/s: Core
    • Labels:
      None

      Description

      This is related to WW-1950.

      If you use the method DefaultUrlHelper().buildUrl() and set forceAddSchemeHostAndPort to true Struts2 does not always add the port. This is a problem if you intend to use the output as a parameter.

      Example code:

      Map<String, Object> parameters = new HashMap<String, Object>();
      String backUrlParameters = new DefaultUrlHelper().buildUrl("someurl.html", getServletRequest(), getServletResponse(), null, null, true, false, true, true);
      parameters.put("backUrl", backUrlParameters);
      String backUrl = new DefaultUrlHelper().buildUrl("someurl2.html", getServletRequest(), getServletResponse(), parameters, null, false, false, false, false);
      

      The resulting parameter appended to backUrl does not have the port, even with setting forceAddSchemeHostAndPort to true.
      Resulting URL:
      http://localhost:8080/someurl2.html?backUrl=http%3A%2F%2Flocalhost%2Fsomeurl.html

      My current workaround is to use:

      String backUrlParameters = new DefaultUrlHelper().buildUrl("someurl.html", getServletRequest(), getServletResponse(), null, getServletRequest().getScheme(), true, false, true, true);
      

      This gives Struts2 the same scheme that is currently used but makes it think that there could be a change. Result is that the port in the parameter URL is appended.

      My environment is Struts2 2.3.33 but I didn't see a code change in that area between 2.3 and 2.5, nonetheless I only selected the version I actually tested this on.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                lukaszlenart Lukasz Lenart
                Reporter:
                k918912 k918912
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: