From 082d2ec52f9d4483ab0aaac901eb00c496cf07b3 Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Sun, 8 Dec 2013 10:48:18 +0000 Subject: [PATCH] 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 --- .../base/container/ClassLoaderContainer.java | 5 ++++- .../ofbiz/webapp/control/RequestHandler.java | 12 ++++++++++- .../webapp/website/WebSiteProperties.java | 21 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/framework/base/src/org/ofbiz/base/container/ClassLoaderContainer.java b/framework/base/src/org/ofbiz/base/container/ClassLoaderContainer.java index c74964a54b..49eed80d67 100644 --- a/framework/base/src/org/ofbiz/base/container/ClassLoaderContainer.java +++ b/framework/base/src/org/ofbiz/base/container/ClassLoaderContainer.java @@ -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; } diff --git a/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java index f2097eed8f..24446703f4 100644 --- a/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java +++ b/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java @@ -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) { diff --git a/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java b/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java index 5bfa196d01..c47ea3020f 100644 --- a/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java +++ b/framework/webapp/src/org/ofbiz/webapp/website/WebSiteProperties.java @@ -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); }