"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 - 
<WebSitePathAlias aliasTo="demoPage2" fromDate="2016-06-09 13:37:30.43" 
pathAlias="demoHome2" webSiteId="CmsSite"/>
<WebSitePathAlias contentId="CMSS_DEMO_PAGE1" fromDate="2016-06-09 13:37:30.43" 
pathAlias="demoPage2" webSiteId="CmsSite"/>

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
This commit is contained in:
Jacques Le Roux
2019-05-20 10:11:23 +00:00
parent 1fb06865a1
commit 79a02bddb9
@@ -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
}