Author: jleroux
Date: Thu Dec 11 14:37:11 2014
New Revision: 1644653
URL: http://svn.apache.org/r1644653
Log:
A patch from Shi Jinghai for "Infinite loop in SEO branch"
https://issues.apache.org/jira/browse/OFBIZ-5312
Thanks to Josip Almasi for report
Added:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
(with props)
Modified:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoControlServlet.java
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
Modified:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoControlServlet.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoControlServlet.java?rev=1644653&r1=1644652&r2=1644653&view=diff
==============================================================================
---
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoControlServlet.java
(original)
+++
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/applications/product/src/org/ofbiz/product/category/SeoControlServlet.java
Thu Dec 11 14:37:11 2014
@@ -19,6 +19,8 @@
package org.ofbiz.product.category;
import java.io.IOException;
+import java.net.URLEncoder;
+
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
@@ -27,6 +29,7 @@ import javax.servlet.http.HttpServletRes
import org.apache.catalina.servlets.DefaultServlet;
import org.apache.jasper.servlet.JspServlet;
+import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.webapp.control.ControlServlet;
@@ -70,7 +73,8 @@ public class SeoControlServlet extends C
}
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
- if (request.getAttribute(REQUEST_IN_ALLOW_LIST) != null) {
+ String uri = URLEncoder.encode(request.getRequestURI(),
"UTF-8");
+ if (request.getAttribute(REQUEST_IN_ALLOW_LIST) != null ||
request.getAttribute("_jsp_" + uri) != null) {
if (request.getRequestURI().toLowerCase().endsWith(".jsp") ||
request.getRequestURI().toLowerCase().endsWith(".jspx") ) {
JspServlet jspServlet = new JspServlet();
jspServlet.init(this.getServletConfig());
Added:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
URL:
http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java?rev=1644653&view=auto
==============================================================================
---
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
(added)
+++
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
Thu Dec 11 14:37:11 2014
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
*******************************************************************************/
+package org.ofbiz.ecommerce.webapp.view;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspException;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilValidate;
+import org.ofbiz.webapp.control.ContextFilter;
+import org.ofbiz.webapp.view.AbstractViewHandler;
+import org.ofbiz.webapp.view.ViewHandlerException;
+
+/**
+ * JspViewHandler - Java Server Pages View Handler
+ */
+public class JspViewHandler extends AbstractViewHandler {
+
+ public static final String module = JspViewHandler.class.getName();
+
+ protected ServletContext context;
+
+ public void init(ServletContext context) throws ViewHandlerException {
+ this.context = context;
+ }
+
+ public void render(String name, String page, String contentType, String
encoding, String info, HttpServletRequest request, HttpServletResponse
response) throws ViewHandlerException {
+ // some containers call filters on EVERY request, even forwarded ones,
+ // so let it know that it came from the control servlet
+
+ if (request == null) {
+ throw new ViewHandlerException("Null HttpServletRequest object");
+ }
+ if (UtilValidate.isEmpty(page)) {
+ throw new ViewHandlerException("Null or empty source");
+ }
+
+ // Debug.logInfo("Requested Page : " + page, module);
+ // Debug.logInfo("Physical Path : " + context.getRealPath(page));
+
+ // tell the ContextFilter we are forwarding
+ request.setAttribute(ContextFilter.FORWARDED_FROM_SERVLET,
Boolean.TRUE);
+ RequestDispatcher rd = request.getRequestDispatcher(page);
+
+ if (rd == null) {
+ Debug.logInfo("HttpServletRequest.getRequestDispatcher() failed;
trying ServletContext", module);
+ rd = context.getRequestDispatcher(page);
+ if (rd == null) {
+ Debug.logInfo("ServletContext.getRequestDispatcher() failed;
trying ServletContext.getNamedDispatcher(\"jsp\")", module);
+ rd = context.getNamedDispatcher("jsp");
+ if (rd == null) {
+ throw new ViewHandlerException("Source returned a null
dispatcher (" + page + ")");
+ }
+ }
+ }
+
+ try {
+ if (UtilValidate.isEmpty(request.getServletPath())) {
+ // no context or filter to service this page, so we
have to forward it directly and let SeoControlServlet to resolve it
+ String uri = URLEncoder.encode(request.getContextPath()
+ page, "UTF-8");
+ request.setAttribute("_jsp_" + uri, Boolean.TRUE);
+ rd.forward(request, response);
+ } else {
+ rd.include(request, response);
+ }
+ } catch (IOException ie) {
+ throw new ViewHandlerException("IO Error in view", ie);
+ } catch (ServletException e) {
+ Throwable throwable = e.getRootCause() != null ? e.getRootCause()
: e;
+
+ if (throwable instanceof JspException) {
+ JspException jspe = (JspException) throwable;
+
+ throwable = jspe.getCause() != null ? jspe.getCause() : jspe;
+ }
+ Debug.logError(throwable, "ServletException rendering JSP view",
module);
+ throw new ViewHandlerException(e.getMessage(), throwable);
+ }
+ }
+}
Propchange:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
------------------------------------------------------------------------------
svn:keywords = Date Rev Author URL Id
Propchange:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/src/org/ofbiz/ecommerce/webapp/view/JspViewHandler.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
URL:
http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml?rev=1644653&r1=1644652&r2=1644653&view=diff
==============================================================================
---
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
(original)
+++
ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/specialpurpose/ecommerce/webapp/ecommerce/WEB-INF/controller.xml
Thu Dec 11 14:37:11 2014
@@ -31,7 +31,7 @@ under the License.
<handler name="simple" type="request"
class="org.ofbiz.webapp.event.SimpleEventHandler"/>
<handler name="rome" type="request"
class="org.ofbiz.webapp.event.RomeEventHandler"/>
- <handler name="jsp" type="view"
class="org.ofbiz.webapp.view.JspViewHandler"/>
+ <handler name="jsp" type="view"
class="org.ofbiz.ecommerce.webapp.view.JspViewHandler"/>
<handler name="http" type="view"
class="org.ofbiz.webapp.view.HttpViewHandler"/>
<handler name="screen" type="view"
class="org.ofbiz.widget.screen.MacroScreenViewHandler"/>
<handler name="simplecontent" type="view"
class="org.ofbiz.content.view.SimpleContentViewHandler"/>
@@ -2020,7 +2020,7 @@ under the License.
<!-- End of Request Mappings -->
<!-- View Mappings -->
- <view-map name="error" page="/error/error.jsp"/>
+ <view-map name="error" type="jsp" page="/error/error.jsp"/>
<view-map name="main" type="screen"
page="component://ecommerce/widget/CommonScreens.xml#main"/>
<view-map name="policies" type="screen"
page="component://ecommerce/widget/CommonScreens.xml#policies"/>
<view-map name="login" type="screen"
page="component://ecommerce/widget/CommonScreens.xml#login"/>