You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/01/04 18:52:54 UTC

[cxf] branch 3.2.x-fixes updated (7271e9b -> 8cf7fe5)

This is an automated email from the ASF dual-hosted git repository.

reta pushed a change to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from 7271e9b  Recording .gitmergeinfo Changes
     new 87b73c3  CXF-8097: Equal candidates for handling the current request (HEAD / GET). Extracting base comparator and updating documentation.
     new 41c8d90  Recording .gitmergeinfo Changes
     new 8cf7fe5  CXF-8097: Equal candidates for handling the current request (HEAD / GET). Minor refactorings.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |  1 +
 .../model/OperationResourceInfoComparator.java     | 78 ++--------------------
 ...va => OperationResourceInfoComparatorBase.java} | 55 ++++-----------
 3 files changed, 21 insertions(+), 113 deletions(-)
 copy rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/{OperationResourceInfoComparator.java => OperationResourceInfoComparatorBase.java} (71%)


[cxf] 01/03: CXF-8097: Equal candidates for handling the current request (HEAD / GET). Extracting base comparator and updating documentation.

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 87b73c3524fc4d63abb2a2da2a2bb0e4497c354e
Author: reta <dr...@gmail.com>
AuthorDate: Sat Jan 4 13:31:56 2020 -0500

    CXF-8097: Equal candidates for handling the current request (HEAD / GET). Extracting base comparator and updating documentation.
    
    (cherry picked from commit 5f2317c66d33d4f083f9175c19d7d724754693ff)
    (cherry picked from commit 23f9204b9d0e01738e8100f0152baf53320d98f8)
    
    # Conflicts:
    #	rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
---
 .../model/OperationResourceInfoComparator.java     | 15 +++---
 ...va => OperationResourceInfoComparatorBase.java} | 54 ++++++----------------
 2 files changed, 21 insertions(+), 48 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
index ce31f8f..e19c8df 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
@@ -20,21 +20,14 @@
 package org.apache.cxf.jaxrs.model;
 
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
-import java.util.logging.Logger;
 
-import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.MediaType;
 
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.jaxrs.ext.DefaultMethod;
 import org.apache.cxf.jaxrs.ext.ResourceComparator;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
-public class OperationResourceInfoComparator implements Comparator<OperationResourceInfo> {
-    private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
+public class OperationResourceInfoComparator extends OperationResourceInfoComparatorBase {
     private String httpMethod;
     private boolean getMethod;
     private Message message;
@@ -64,6 +57,7 @@ public class OperationResourceInfoComparator implements Comparator<OperationReso
         this.getMethod = getMethod;
     }
 
+    @Override
     public int compare(OperationResourceInfo e1, OperationResourceInfo e2) {
         if (e1 == e2) {
             return 0;
@@ -74,6 +68,7 @@ public class OperationResourceInfoComparator implements Comparator<OperationReso
                 return result;
             }
         }
+<<<<<<< HEAD
         String e1HttpMethod = e1.getHttpMethod();
         String e2HttpMethod = e2.getHttpMethod();
 
@@ -139,5 +134,9 @@ public class OperationResourceInfoComparator implements Comparator<OperationReso
             return 1;
         }
         return 0;
+=======
+        
+        return compare(e1, e2, getMethod, httpMethod, contentType, acceptTypes);
+>>>>>>> 23f9204... CXF-8097: Equal candidates for handling the current request (HEAD / GET). Extracting base comparator and updating documentation.
     }
 }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
similarity index 71%
copy from rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
copy to rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
index ce31f8f..321be2e 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
@@ -29,51 +29,25 @@ import javax.ws.rs.core.MediaType;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.ext.DefaultMethod;
-import org.apache.cxf.jaxrs.ext.ResourceComparator;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
 
-public class OperationResourceInfoComparator implements Comparator<OperationResourceInfo> {
+public abstract class OperationResourceInfoComparatorBase implements Comparator<OperationResourceInfo> {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
-    private String httpMethod;
-    private boolean getMethod;
-    private Message message;
-    private ResourceComparator rc;
-    private MediaType contentType = MediaType.WILDCARD_TYPE;
-    private List<MediaType> acceptTypes = Collections.singletonList(MediaType.WILDCARD_TYPE);
-
-    public OperationResourceInfoComparator(Message m, String method) {
-        this.message = m;
-        if (message != null) {
-            Object o = m.getExchange().getEndpoint().get("org.apache.cxf.jaxrs.comparator");
-            if (o != null) {
-                rc = (ResourceComparator)o;
-            }
-        }
-        this.httpMethod = method;
+    
+    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod) {
+        return compare(e1, e2, httpMethod, MediaType.WILDCARD_TYPE, 
+            Collections.singletonList(MediaType.WILDCARD_TYPE));
     }
 
-    public OperationResourceInfoComparator(Message m,
-                                           String httpMethod,
-                                           boolean getMethod,
-                                           MediaType contentType,
-                                           List<MediaType> acceptTypes) {
-        this(m, httpMethod);
-        this.contentType = contentType;
-        this.acceptTypes = acceptTypes;
-        this.getMethod = getMethod;
+    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod, 
+            final MediaType contentType, final List<MediaType> acceptTypes) {
+        return compare(e1, e2, HttpMethod.GET.equals(httpMethod), 
+            httpMethod, contentType, acceptTypes);
     }
 
-    public int compare(OperationResourceInfo e1, OperationResourceInfo e2) {
-        if (e1 == e2) {
-            return 0;
-        }
-        if (rc != null) {
-            int result = rc.compare(e1, e2, message);
-            if (result != 0) {
-                return result;
-            }
-        }
+    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, boolean getMethod, 
+            String httpMethod, final MediaType contentType, final List<MediaType> acceptTypes) {
+
         String e1HttpMethod = e1.getHttpMethod();
         String e2HttpMethod = e2.getHttpMethod();
 
@@ -131,7 +105,7 @@ public class OperationResourceInfoComparator implements Comparator<OperationReso
         }
         return result;
     }
-
+    
     private static int compareWithHead(String e1HttpMethod, String e2HttpMethod) {
         if (HttpMethod.HEAD.equals(e1HttpMethod)) {
             return -1;
@@ -140,4 +114,4 @@ public class OperationResourceInfoComparator implements Comparator<OperationReso
         }
         return 0;
     }
-}
+}
\ No newline at end of file


[cxf] 02/03: Recording .gitmergeinfo Changes

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 41c8d90ef55cb222b2171aa8d94f3d0bebb9a168
Author: reta <dr...@gmail.com>
AuthorDate: Sat Jan 4 13:45:16 2020 -0500

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 751722c..13eb49f 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -768,6 +768,7 @@ M 1a4505c09fa403262a54e0fa745edf78a8c3ba0c
 M 1cc03b9b70bc509d8f8c631563c3964e56e30621
 M 1cdf673a8ce2fc5c57318d1a102ca0923cb1d945
 M 1f0468398ddb21ecaf6b6eda370e3464e402ef8a
+M 23f9204b9d0e01738e8100f0152baf53320d98f8
 M 26f3e944a56b79ac2e30286c61b3fab6d4bab638
 M 28924caee27ef6601398725ebcb198fe363157d5
 M 29cd11664c3c1a9a49ac0d5dc1d929b1e68ea6f2


[cxf] 03/03: CXF-8097: Equal candidates for handling the current request (HEAD / GET). Minor refactorings.

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

reta pushed a commit to branch 3.2.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 8cf7fe50614f1c6f08530ecbfc8710322288d070
Author: reta <dr...@gmail.com>
AuthorDate: Sat Jan 4 13:52:33 2020 -0500

    CXF-8097: Equal candidates for handling the current request (HEAD / GET). Minor refactorings.
---
 .../model/OperationResourceInfoComparator.java     | 73 ++--------------------
 .../model/OperationResourceInfoComparatorBase.java |  9 ++-
 2 files changed, 8 insertions(+), 74 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
index e19c8df..0f83ce8 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparator.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.model;
 
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import javax.ws.rs.core.MediaType;
@@ -27,7 +28,9 @@ import javax.ws.rs.core.MediaType;
 import org.apache.cxf.jaxrs.ext.ResourceComparator;
 import org.apache.cxf.message.Message;
 
-public class OperationResourceInfoComparator extends OperationResourceInfoComparatorBase {
+public class OperationResourceInfoComparator extends OperationResourceInfoComparatorBase 
+        implements Comparator<OperationResourceInfo> {
+    
     private String httpMethod;
     private boolean getMethod;
     private Message message;
@@ -68,75 +71,7 @@ public class OperationResourceInfoComparator extends OperationResourceInfoCompar
                 return result;
             }
         }
-<<<<<<< HEAD
-        String e1HttpMethod = e1.getHttpMethod();
-        String e2HttpMethod = e2.getHttpMethod();
-
-        int result = 0;
-        if (!getMethod && HttpMethod.HEAD.equals(httpMethod)) {
-            result = compareWithHead(e1HttpMethod, e2HttpMethod);
-            if (result != 0) {
-                return result;
-            }
-        }
-
-        result = URITemplate.compareTemplates(
-                          e1.getURITemplate(),
-                          e2.getURITemplate());
-
-        if (result == 0 && (e1HttpMethod != null && e2HttpMethod == null
-                || e1HttpMethod == null && e2HttpMethod != null)) {
-            // resource method takes precedence over a subresource locator
-            return e1.getHttpMethod() != null ? -1 : 1;
-        }
-
-        if (result == 0 && !getMethod) {
-            result = JAXRSUtils.compareSortedConsumesMediaTypes(
-                          e1.getConsumeTypes(),
-                          e2.getConsumeTypes(),
-                          contentType);
-        }
-
-        if (result == 0) {
-            //use the media type of output data as the secondary key.
-            result = JAXRSUtils.compareSortedAcceptMediaTypes(e1.getProduceTypes(),
-                                                              e2.getProduceTypes(),
-                                                              acceptTypes);
-        }
-
-        if (result == 0 && e1HttpMethod != null && e2HttpMethod != null) {
-            boolean e1IsDefault = DefaultMethod.class.getSimpleName().equals(e1HttpMethod);
-            boolean e2IsDefault = DefaultMethod.class.getSimpleName().equals(e2HttpMethod);
-            if (e1IsDefault && !e2IsDefault) {
-                result = 1;
-            } else if (!e1IsDefault && e2IsDefault) {
-                result = -1;
-            }
-        } 
-        if (result == 0) {
-            result = JAXRSUtils.compareMethodParameters(e1.getInParameterTypes(), e2.getInParameterTypes());
-        }
-        if (result == 0) {
-            String m1Name =
-                e1.getClassResourceInfo().getServiceClass().getName() + "#" + e1.getMethodToInvoke().getName();
-            String m2Name =
-                e2.getClassResourceInfo().getServiceClass().getName() + "#" + e2.getMethodToInvoke().getName();
-            LOG.warning("Both " + m1Name + " and " + m2Name + " are equal candidates for handling the current request"
-                        + " which can lead to unpredictable results");
-        }
-        return result;
-    }
-
-    private static int compareWithHead(String e1HttpMethod, String e2HttpMethod) {
-        if (HttpMethod.HEAD.equals(e1HttpMethod)) {
-            return -1;
-        } else if (HttpMethod.HEAD.equals(e2HttpMethod)) {
-            return 1;
-        }
-        return 0;
-=======
         
         return compare(e1, e2, getMethod, httpMethod, contentType, acceptTypes);
->>>>>>> 23f9204... CXF-8097: Equal candidates for handling the current request (HEAD / GET). Extracting base comparator and updating documentation.
     }
 }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
index 321be2e..9f3b768 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/OperationResourceInfoComparatorBase.java
@@ -20,7 +20,6 @@
 package org.apache.cxf.jaxrs.model;
 
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 import java.util.logging.Logger;
 
@@ -31,21 +30,21 @@ import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxrs.ext.DefaultMethod;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
-public abstract class OperationResourceInfoComparatorBase implements Comparator<OperationResourceInfo> {
+public abstract class OperationResourceInfoComparatorBase {
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
     
-    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod) {
+    protected int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod) {
         return compare(e1, e2, httpMethod, MediaType.WILDCARD_TYPE, 
             Collections.singletonList(MediaType.WILDCARD_TYPE));
     }
 
-    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod, 
+    protected int compare(OperationResourceInfo e1, OperationResourceInfo e2, String httpMethod, 
             final MediaType contentType, final List<MediaType> acceptTypes) {
         return compare(e1, e2, HttpMethod.GET.equals(httpMethod), 
             httpMethod, contentType, acceptTypes);
     }
 
-    protected static int compare(OperationResourceInfo e1, OperationResourceInfo e2, boolean getMethod, 
+    protected int compare(OperationResourceInfo e1, OperationResourceInfo e2, boolean getMethod, 
             String httpMethod, final MediaType contentType, final List<MediaType> acceptTypes) {
 
         String e1HttpMethod = e1.getHttpMethod();