Index: kernel-util/src/main/java/org/sakaiproject/util/Web.java =================================================================== --- kernel-util/src/main/java/org/sakaiproject/util/Web.java (revision 105610) +++ kernel-util/src/main/java/org/sakaiproject/util/Web.java (working copy) @@ -356,48 +356,20 @@ } /** - * Compute the URL that would return to this server based on the current request. Note: this method is duplicated in the kernel/request RequestFilter.java + * Compute the URL that would return to this server based on the current request. * + * Note: this method is duplicated in the /sakai-kernel-api/src/main/java/org/sakaiproject/util/RequestFilter.java + * * @param req * The request. * @return The URL back to this server based on the current request. + * @deprecated use RequestFilter.serverUrl */ public static String serverUrl(HttpServletRequest req) { - String transport = null; - int port = 0; - boolean secure = false; - - // if force.url.secure is set (to a https port number), use https and this port - String forceSecure = System.getProperty("sakai.force.url.secure"); - if (forceSecure != null) - { - transport = "https"; - port = Integer.parseInt(forceSecure); - secure = true; + return RequestFilter.serverUrl(req); } - // otherwise use the request scheme and port - else - { - transport = req.getScheme(); - port = req.getServerPort(); - secure = req.isSecure(); - } - - StringBuilder url = new StringBuilder(); - url.append(transport); - url.append("://"); - url.append(req.getServerName()); - if (((port != 80) && (!secure)) || ((port != 443) && secure)) - { - url.append(":"); - url.append(port); - } - - return url.toString(); - } - public static String snoop(PrintWriter out, boolean html, ServletConfig config, HttpServletRequest req) { // if no out, send to system out Index: api/src/main/java/org/sakaiproject/util/RequestFilter.java =================================================================== --- api/src/main/java/org/sakaiproject/util/RequestFilter.java (revision 105610) +++ api/src/main/java/org/sakaiproject/util/RequestFilter.java (working copy) @@ -1430,9 +1430,10 @@ } /** - * Compute the URL that would return to this server based on the current request. Note: this method is a duplicate of one in the - * util/Web.java + * Compute the URL that would return to this server based on the current request. * + * Note: this method is used by the one in /sakai-kernel-util/src/main/java/org/sakaiproject/util/Web.java + * * @param req * The request. * @return The URL back to this server based on the current request. @@ -1445,16 +1446,21 @@ // if force.url.secure is set (to a https port number), use https and this port String forceSecure = System.getProperty("sakai.force.url.secure"); - if (forceSecure != null) - { + if (forceSecure != null && !"".equals(forceSecure)) { + // allow the value to be forced to 0 or blank to disable this + int portNum; + try { + portNum = Integer.parseInt(forceSecure); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("force.url.secure must be set to the port number which should be a numeric value > 0 (or set it to 0 to disable secure urls)", e); + } + if (portNum > 0) { transport = "https"; - port = Integer.parseInt(forceSecure); + port = portNum; secure = true; } - + } else { // otherwise use the request scheme and port - else - { transport = req.getScheme(); port = req.getServerPort(); secure = req.isSecure();