Author: nmalin
Date: Sun Dec 17 16:47:18 2017 New Revision: 1818494 URL: http://svn.apache.org/viewvc?rev=1818494&view=rev Log: Implemented: Website can manage hidden webapp (OFBIZ-10088) Improve RequestHandler.makeLink code to manage url generation with surcharge the webapp path. When a websiteId is present and it have a webappPatch define, use it on the link generation. Example of use : You have a httpd serveur that listen on *.mydomaine.com and define virtualHost myEcommerce.mydomaine.com and myCatalog.mydomaine.com myEcommerce.mydomaine.com is a reverse proxy to myEcommerce.mydomaine.com/ecommerce myCatalog.mydomaine.com is a reverse proxy to myEcommerce.mydomaine.com/catalog Natively, all works fine with some parameters on web.xml and controller.xml but each link return are setted like that myEcommerce.mydomaine.com/ecommerce, called by apache httpd to ofbiz by myEcommerce.mydomaine.com/ecommerce/ecommerce and translate by ofbiz by ERROR ecommerce request-map not found To solve the situation, I extended WebSite entity with attribute webappPath, init to / for websiteId ecommerce ofbiz instance and /ecommerce for other websiteId liked to other ofbiz instance (dev, back) without apache httpd with limited reverse-proxy. Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/entitydef/entitymodel.xml ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/website/WebSiteProperties.java Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/entitydef/entitymodel.xml?rev=1818494&r1=1818493&r2=1818494&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/entitydef/entitymodel.xml (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/entitydef/entitymodel.xml Sun Dec 17 16:47:18 2017 @@ -223,6 +223,9 @@ under the License. <field name="httpsHost" type="long-varchar"></field> <field name="httpsPort" type="very-short"></field> <field name="enableHttps" type="indicator"></field> + <field name="webappPath" type="long-varchar"> + <description>Set your dedicate webapp for this website if it's hidden by a httpd frontend, set to / if you have a reverse proxy that hidden your website webapp</description> + </field> <field name="standardContentPrefix" type="url"></field> <field name="secureContentPrefix" type="url"></field> <field name="cookieDomain" type="long-varchar"></field> Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java?rev=1818494&r1=1818493&r2=1818494&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java Sun Dec 17 16:47:18 2017 @@ -1139,6 +1139,20 @@ public class RequestHandler { } // create the path to the control servlet String controlPath = (String) request.getAttribute("_CONTROL_PATH_"); + + //If required by webSite parameter, surcharge control path + if (webSiteProps.getWebappPath() != null) { + String requestPath = request.getServletPath(); + if (requestPath == null) requestPath = ""; + if (requestPath.lastIndexOf("/") > 0) { + if (requestPath.indexOf("/") == 0) { + requestPath = "/" + requestPath.substring(1, requestPath.indexOf("/", 1)); + } else { + requestPath = requestPath.substring(1, requestPath.indexOf("/")); + } + } + controlPath = webSiteProps.getWebappPath().concat(requestPath); + } newURL.append(controlPath); Delegator delegator = (Delegator) request.getAttribute("delegator"); Modified: ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/website/WebSiteProperties.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/website/WebSiteProperties.java?rev=1818494&r1=1818493&r2=1818494&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/website/WebSiteProperties.java (original) +++ ofbiz/ofbiz-framework/trunk/framework/webapp/src/main/java/org/apache/ofbiz/webapp/website/WebSiteProperties.java Sun Dec 17 16:47:18 2017 @@ -65,6 +65,7 @@ public final class WebSiteProperties { String httpsPort = defaults.getHttpsPort(); String httpsHost = defaults.getHttpsHost(); boolean enableHttps = defaults.getEnableHttps(); + String webappPath = null; if (delegator != null) { String webSiteId = WebSiteWorker.getWebSiteId(request); if (webSiteId != null) { @@ -85,6 +86,12 @@ public final class WebSiteProperties { if (webSiteValue.get("enableHttps") != null) { enableHttps = webSiteValue.getBoolean("enableHttps"); } + if (webSiteValue.get("webappPath") != null) { + webappPath = webSiteValue.getString("webappPath"); + if (webappPath.endsWith("/")) { + webappPath = webappPath.substring(0, webappPath.length() - 1); + } + } } } } @@ -101,7 +108,7 @@ public final class WebSiteProperties { if (httpsHost.isEmpty()) { httpsHost = request.getServerName(); } - + if (Start.getInstance().getConfig().portOffset != 0) { Integer httpPortValue = Integer.valueOf(httpPort); httpPortValue += Start.getInstance().getConfig().portOffset; @@ -115,7 +122,7 @@ public final class WebSiteProperties { } } - webSiteProps = new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, enableHttps); + webSiteProps = new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, webappPath, enableHttps); request.setAttribute("_WEBSITE_PROPS_", webSiteProps); } return webSiteProps; @@ -137,6 +144,7 @@ public final class WebSiteProperties { String httpHost = (webSiteValue.get("httpHost") != null) ? webSiteValue.getString("httpHost") : defaults.getHttpHost(); String httpsPort = (webSiteValue.get("httpsPort") != null) ? webSiteValue.getString("httpsPort") : defaults.getHttpsPort(); String httpsHost = (webSiteValue.get("httpsHost") != null) ? webSiteValue.getString("httpsHost") : defaults.getHttpsHost(); + String webappPath = (webSiteValue.get("webappPath") != null) ? webSiteValue.getString("webappPath") : null; boolean enableHttps = (webSiteValue.get("enableHttps") != null) ? webSiteValue.getBoolean("enableHttps") : defaults.getEnableHttps(); if (Start.getInstance().getConfig().portOffset != 0) { @@ -148,13 +156,14 @@ public final class WebSiteProperties { httpsPort = httpsPortValue.toString(); } - return new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, enableHttps); + return new WebSiteProperties(httpPort, httpHost, httpsPort, httpsHost, webappPath, enableHttps); } private final String httpPort; private final String httpHost; private final String httpsPort; private final String httpsHost; + private final String webappPath; private final boolean enableHttps; private WebSiteProperties(Delegator delegator) { @@ -162,14 +171,16 @@ public final class WebSiteProperties { this.httpHost = EntityUtilProperties.getPropertyValue("url", "force.http.host", delegator); this.httpsPort = EntityUtilProperties.getPropertyValue("url", "port.https", delegator); this.httpsHost = EntityUtilProperties.getPropertyValue("url", "force.https.host", delegator); + this.webappPath = null; this.enableHttps = EntityUtilProperties.propertyValueEqualsIgnoreCase("url", "port.https.enabled", "Y", delegator); } - private WebSiteProperties(String httpPort, String httpHost, String httpsPort, String httpsHost, boolean enableHttps) { + private WebSiteProperties(String httpPort, String httpHost, String httpsPort, String httpsHost, String webappPath, boolean enableHttps) { this.httpPort = httpPort; this.httpHost = httpHost; this.httpsPort = httpsPort; this.httpsHost = httpsHost; + this.webappPath = webappPath; this.enableHttps = enableHttps; } @@ -208,6 +219,13 @@ public final class WebSiteProperties { return enableHttps; } + /** + * Returns the configured webapp path on website linked to webapp or null. + */ + public String getWebappPath() { + return webappPath; + } + @Override public String toString() { StringBuilder sb = new StringBuilder("{httpPort="); @@ -215,6 +233,7 @@ public final class WebSiteProperties { sb.append("httpHost=").append(httpHost).append(", "); sb.append("httpsPort=").append(httpsPort).append(", "); sb.append("httpsHost=").append(httpsHost).append(", "); + sb.append("webappPath=").append(webappPath).append(", "); sb.append("enableHttps=").append(enableHttps).append("}"); return sb.toString(); } |
Free forum by Nabble | Edit this page |