[ofbiz-framework] branch trunk updated: Fixed: "entity/list" request is not handled well

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[ofbiz-framework] branch trunk updated: Fixed: "entity/list" request is not handled well

jleroux@apache.org
This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 61e5435  Fixed: "entity/list" request is not handled well
61e5435 is described below

commit 61e5435b301bfe8825ce2c0abb10ee15fb872964
Author: Jacques Le Roux <[hidden email]>
AuthorDate: Wed Apr 29 06:57:52 2020 +0200

    Fixed: "entity/list" request is not handled well
   
    (OFBIZ-11593)
   
    The "entity/list" request has been put in with OFBIZ-11007. It's used to call
    the entitymaint view and so is a demo/didactic duplicate of entitymaint request.
    It's only used in FindGeneric screen (look for WebtoolsBackToEntityList label).
    It's problematic because since the CSRF token defense was put in you can no
    longer filter the entities from the entities list screen, even when the default
    NoCsrfDefenseStrategy is used. It works if you use the entitymaint request
    instead.
   
    2020-01-19 I proposed in OFBIZ-11306 a solution for such cases.
    It was not used because 2020-02-14 I thought it was no longer needed.
    It was necessary for this case and implemented with commit e487122.
   
    But as, Rohit Koushal reported, it breaks some functionalities like adding
    address/update address during Quick Finalize Order. The issue can also be
    reproduced in ecommerce when trying the same while checking out, or quick
    checking out, an order.
   
    More generally the error is of this kind:
    |27.0.0.1-8009-exec-3 |ControlServlet                |E| Error in request handler:
    java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
      at java.util.LinkedList.checkElementIndex(LinkedList.java:555) ~[?:1.8.0_252]
      at java.util.LinkedList.get(LinkedList.java:476) ~[?:1.8.0_252]
      at org.apache.ofbiz.webapp.control.RequestHandler.getRequestUri(RequestHandler.java:837) ~[main/:?]
   
    and happens with URLs like
    updateCheckoutOptions/editcontactmech?DONE_PAGE=checkoutoptions&contactMechId=9015
    or
    updateCheckoutOptions/editcontactmech?preContactMechTypeId=POSTAL_ADDRESS&
    contactMechPurposeTypeId=SHIPPING_LOCATION&DONE_PAGE=checkoutoptions
   
    So I decided to revert the concerned part of commit e487122 and to rather use
    entitymaint instead of "entity/list" request.
---
 .../org/apache/ofbiz/webapp/control/RequestHandler.java    |  7 +------
 .../apache/ofbiz/webapp/control/RequestHandlerTests.java   | 14 ++++++++------
 framework/webtools/widget/EntityScreens.xml                |  3 ++-
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
index 166a5d7..84f91e4 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/RequestHandler.java
@@ -43,7 +43,6 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 import javax.ws.rs.core.MultivaluedHashMap;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.ofbiz.base.location.FlexibleLocation;
 import org.apache.ofbiz.base.util.Debug;
@@ -833,11 +832,7 @@ public class RequestHandler {
         if (pathInfo.get(0).indexOf('?') > -1) {
             return pathInfo.get(0).substring(0, pathInfo.get(0).indexOf('?'));
         } else {
-            if (1 < StringUtils.countMatches(path, "/")) {
-                return pathInfo.get(0) + "/" + pathInfo.get(1);
-            } else {
-                return pathInfo.get(0);
-            }
+            return pathInfo.get(0);
         }
     }
 
diff --git a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/RequestHandlerTests.java b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/RequestHandlerTests.java
index 183f0b0..53d760d 100644
--- a/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/RequestHandlerTests.java
+++ b/framework/webapp/src/test/java/org/apache/ofbiz/webapp/control/RequestHandlerTests.java
@@ -27,9 +27,9 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.times;
 
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
@@ -185,14 +185,16 @@ public class RequestHandlerTests {
 
         @Test
         public void resolveURIBasicOverrideView() throws Exception {
-            RequestMap foobar = new RequestMap(dummyElement);
-            reqMaps.putSingle("foo/bar", foobar);
+            RequestMap foo = new RequestMap(dummyElement);
+            RequestMap bar = new RequestMap(dummyElement);
+            reqMaps.putSingle("foo", foo);
+            reqMaps.putSingle("bar", bar);
 
             viewMaps.put("baz", new ViewMap(dummyElement));
 
             when(req.getPathInfo()).thenReturn("/foo/baz");
-            when(ccfg.getDefaultRequest()).thenReturn("foo/bar");
-            assertThat(RequestHandler.resolveURI(ccfg, req), hasItem(foobar));
+            when(ccfg.getDefaultRequest()).thenReturn("bar");
+            assertThat(RequestHandler.resolveURI(ccfg, req), hasItem(foo));
         }
 
         @Test
diff --git a/framework/webtools/widget/EntityScreens.xml b/framework/webtools/widget/EntityScreens.xml
index 0994a43..d5f39e5 100644
--- a/framework/webtools/widget/EntityScreens.xml
+++ b/framework/webtools/widget/EntityScreens.xml
@@ -212,7 +212,8 @@ under the License.
                         <decorator-screen name="FindScreenDecorator" location="component://common/widget/CommonScreens.xml">
                             <decorator-section name="menu-bar">
                                 <container style="button-bar button-style-1">
-                                    <link target="entity/list" text="${uiLabelMap.WebtoolsBackToEntityList}"/>
+                                    <!-- <link target="entity/list" text="${uiLabelMap.WebtoolsBackToEntityList}"/> FIXME see OFBIZ-11593-->
+                                    <link target="entitymaint" text="${uiLabelMap.WebtoolsBackToEntityList}"/>
                                     <link target="entity/relations/${entityName}" text="${uiLabelMap.WebtoolsViewRelations}"/>
                                     <link target="entity/create/${entityName}" text="${uiLabelMap.CommonCreate}" style="create"/>
                                 </container>