From 79a02bddb9bee71e307d89c2cc9ef2ec2a85822e Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Mon, 20 May 2019 10:11:23 +0000 Subject: [PATCH] "Applied fix from trunk for revision: 1859543" ------------------------------------------------------------------------ r1859543 | jleroux | 2019-05-20 12:10:34 +0200 (lun. 20 mai 2019) | 24 lignes Fixed: Redirection of pathAlias to aliasTo does not work properly (OFBIZ-11018) Link of discussion: https://markmail.org/message/s37whdteejqdzkha In CMS, we can redirect the user to different path alias using 'aliasTo' field of WebSitePathAlias entity. As per my observation, the content for "newDemoHome" is rendered properly (as expected) but the URL of the page (in browser) doesn't change. We should also update the URL also, i.e. change browser URL from Example - Based on the above data, if the user hit the URL https://localhost:8443/cmssite/cms/demoHome2 the CMS should internally render the content for 'DemoHome2' at https://localhost:8443/cmssite/cms/demoPage2 Thanks: Pawan Verma ------------------------------------------------------------------------ git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release18.12@1859544 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/ofbiz/content/cms/CmsEvents.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java b/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java index 18c0272112..a949263eb1 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.GeneralRuntimeException; @@ -167,7 +168,7 @@ public class CmsEvents { GenericValue pathAlias = null; try { - pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).orderBy("-fromDate").cache().filterByDate().queryOne(); + pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).orderBy("-fromDate").cache().filterByDate().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -179,16 +180,20 @@ public class CmsEvents { if (!alias.startsWith("/")) { alias = "/" + alias; } - RequestDispatcher rd = request.getRequestDispatcher(request.getServletPath() + alias); - try { - rd.forward(request, response); - } catch (ServletException e) { - Debug.logError(e, module); - return "error"; - } catch (IOException e) { - Debug.logError(e, module); - return "error"; - } + + String context = request.getContextPath(); + String location = context + request.getServletPath(); + GenericValue webSite = WebSiteWorker.getWebSite(request); + if (webSite != null && webSite.getString("hostedPathAlias") != null && !"ROOT".equals(pathInfo)) + location += "/" + webSite.getString("hostedPathAlias"); + + String uriWithContext = request.getRequestURI(); + String uri = uriWithContext.substring(context.length()); + uri = uri.substring(0, uri.lastIndexOf('/')); + + response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + response.setHeader("Location", location + uri + alias); + response.setHeader("Connection", "close"); return null; // null to not process any views }