Anonymous avatar Anonymous committed f6588fb

Fixed WW-713: The <ww:url> tag does not correctly construct the URL when the scheme attribute is set and the scheme changes.

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@672 573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (1)

src/java/com/opensymphony/webwork/views/util/UrlHelper.java

-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
 package com.opensymphony.webwork.views.util;
 
 import com.opensymphony.webwork.ServletActionContext;
 public class UrlHelper {
     //~ Static fields/initializers /////////////////////////////////////////////
 
+    /** Default HTTP port (80). */
+    private static final int DEFAULT_HTTP_PORT = 80;
+
+    /** Default HTTPS port (443). */
+    private static final int DEFAULT_HTTPS_PORT = 443;
+
     private static final String AMP = "&";
 
     //~ Methods ////////////////////////////////////////////////////////////////
 
         boolean changedScheme = false;
 
-        int httpPort = 80;
+        int httpPort = DEFAULT_HTTP_PORT;
 
         try {
             httpPort = Integer.parseInt((String) Configuration.get("webwork.url.http.port"));
         } catch (Exception ex) {
         }
 
-        int httpsPort = 443;
+        int httpsPort = DEFAULT_HTTPS_PORT;
 
         try {
             httpsPort = Integer.parseInt((String) Configuration.get("webwork.url.https.port"));
             link.append("://");
             link.append(request.getServerName());
 
-            // do not append port for default ports
-            int port = request.getServerPort();
-
-            if (!(scheme.equals("http") && (port == httpPort)) && !(scheme.equals("https") && (port == httpsPort))) {
+            if ((scheme.equals("http") && (httpPort != DEFAULT_HTTP_PORT)) || (scheme.equals("https") && httpsPort != DEFAULT_HTTPS_PORT)) {
                 link.append(":");
-                link.append(port);
+                link.append(scheme.equals("http") ? httpPort : httpsPort);
             }
         }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.