In r1533839 (related to https://issues.apache.org/jira/browse/OFBIZ-4794 "Set different ports for testing in a CI environment (e.g. Jenkins)"

Which will mostly be used to simultaneously run official demos without having to create patches, I forgot the portOffset for websites and url.properties ports values.
This fixes this point. I also did in it RequestHandler class though the getDefaultServerRootUrl() method is now deprecated.
To be consistent with r1547186 I will backport in R13.07

People should be aware that this will change the ports values of websites and url.properties ports values which in some cases could be an unwanted side effect. 
Anyway the portOffset feature is not destined to be used in production environments where websites and url.properties ports values are often changed purposely

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1549015 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2013-12-08 10:48:18 +00:00
parent 6983020dc5
commit 082d2ec52f
3 changed files with 36 additions and 2 deletions
@@ -68,7 +68,7 @@ public class ClassLoaderContainer implements Container {
try {
ClassLoaderContainer.portOffset = Integer.valueOf(argumentVal);
} catch (NumberFormatException e) {
e.printStackTrace();
Debug.logError(e, module);
}
}
}
@@ -82,6 +82,7 @@ public class ClassLoaderContainer implements Container {
/**
* @see org.ofbiz.base.container.Container#start()
*/
@Override
public boolean start() throws ContainerException {
return true;
}
@@ -89,9 +90,11 @@ public class ClassLoaderContainer implements Container {
/**
* @see org.ofbiz.base.container.Container#stop()
*/
@Override
public void stop() throws ContainerException {
}
@Override
public String getName() {
return name;
}
@@ -37,6 +37,7 @@ import javax.servlet.http.HttpSession;
import javolution.util.FastMap;
import org.ofbiz.base.container.ClassLoaderContainer;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.SSLUtil;
import org.ofbiz.base.util.StringUtil;
@@ -58,8 +59,8 @@ import org.ofbiz.webapp.stats.ServerHitBin;
import org.ofbiz.webapp.view.ViewFactory;
import org.ofbiz.webapp.view.ViewHandler;
import org.ofbiz.webapp.view.ViewHandlerException;
import org.ofbiz.webapp.website.WebSiteWorker;
import org.ofbiz.webapp.website.WebSiteProperties;
import org.ofbiz.webapp.website.WebSiteWorker;
import org.owasp.esapi.errors.EncodingException;
/**
@@ -1028,6 +1029,15 @@ public class RequestHandler {
String httpServer = UtilProperties.getPropertyValue("url.properties", "force.http.host");
boolean useHttps = UtilProperties.propertyValueEqualsIgnoreCase("url.properties", "port.https.enabled", "Y");
if (ClassLoaderContainer.portOffset != 0) {
Integer httpPortValue = Integer.valueOf(httpPort);
httpPortValue += ClassLoaderContainer.portOffset;
httpPort = httpPortValue.toString();
Integer httpsPortValue = Integer.valueOf(httpsPort);
httpsPortValue += ClassLoaderContainer.portOffset;
httpsPort = httpsPortValue.toString();
}
StringBuilder newURL = new StringBuilder();
if (secure && useHttps) {
@@ -20,6 +20,7 @@ package org.ofbiz.webapp.website;
import javax.servlet.http.HttpServletRequest;
import org.ofbiz.base.container.ClassLoaderContainer;
import org.ofbiz.base.lang.ThreadSafe;
import org.ofbiz.base.util.Assert;
import org.ofbiz.base.util.UtilMisc;
@@ -98,6 +99,16 @@ public final class WebSiteProperties {
if (httpsHost.isEmpty()) {
httpsHost = request.getServerName();
}
if (ClassLoaderContainer.portOffset != 0) {
Integer httpPortValue = Integer.valueOf(httpPort);
httpPortValue += ClassLoaderContainer.portOffset;
httpPort = httpPortValue.toString();
Integer httpsPortValue = Integer.valueOf(httpsPort);
httpsPortValue += ClassLoaderContainer.portOffset;
httpsPort = httpsPortValue.toString();
}
webSiteProps = new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, enableHttps);
request.setAttribute("_WEBSITE_PROPS_", webSiteProps);
}
@@ -121,6 +132,16 @@ public final class WebSiteProperties {
String httpsPort = (webSiteValue.get("httpsPort") != null) ? webSiteValue.getString("httpsPort") : defaults.getHttpsPort();
String httpsHost = (webSiteValue.get("httpsHost") != null) ? webSiteValue.getString("httpsHost") : defaults.getHttpsHost();
boolean enableHttps = (webSiteValue.get("enableHttps") != null) ? webSiteValue.getBoolean("enableHttps") : defaults.getEnableHttps();
if (ClassLoaderContainer.portOffset != 0) {
Integer httpPortValue = Integer.valueOf(httpPort);
httpPortValue += ClassLoaderContainer.portOffset;
httpPort = httpPortValue.toString();
Integer httpsPortValue = Integer.valueOf(httpsPort);
httpsPortValue += ClassLoaderContainer.portOffset;
httpsPort = httpsPortValue.toString();
}
return new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, enableHttps);
}