cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5970] Adding an option to set the custom comparators which can be used in cases where 3rd-party providers do not correctly implement JAX-RS provider contracts
Date Thu, 11 Sep 2014 17:09:23 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes e7cf4fe77 -> b435e6897


[CXF-5970] Adding an option to set the custom comparators which can be used in cases where
3rd-party providers do not correctly implement JAX-RS provider contracts


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/b435e689
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/b435e689
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/b435e689

Branch: refs/heads/3.0.x-fixes
Commit: b435e6897f224c0a7400853462a8ff6b1c66f4b8
Parents: e7cf4fe
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Sep 11 18:07:59 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Sep 11 18:09:02 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/AbstractJAXRSFactoryBean.java     |  9 ++++++
 .../cxf/jaxrs/provider/ProviderFactory.java     | 30 ++++++++++++++++++--
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b435e689/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
index 4ee0127..dbddd9b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -70,6 +71,7 @@ public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory {
     protected List<String> schemaLocations;
     protected JAXRSServiceFactoryBean serviceFactory;
     protected List<Object> entityProviders = new LinkedList<Object>();
+    private Comparator<?> providerComparator;
     
     protected AbstractJAXRSFactoryBean(JAXRSServiceFactoryBean serviceFactory) {
         this.serviceFactory = serviceFactory;
@@ -318,6 +320,9 @@ public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory
{
     }
     
     protected void setupFactory(ProviderFactory factory, Endpoint ep) { 
+        if (providerComparator != null) {
+            factory.setProviderComparator(providerComparator);
+        }
         if (entityProviders != null) {
             factory.setUserProviders(entityProviders); 
         }
@@ -421,6 +426,10 @@ public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory
{
             serviceFactory.setUserResourcesWithServiceClass(resources, sClasses);
         }
     }
+
+    public void setProviderComparator(Comparator<?> providerComparator) {
+        this.providerComparator = providerComparator;
+    }
     
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b435e689/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 040f505..43f7be3 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -116,6 +116,7 @@ public abstract class ProviderFactory {
     private Bus bus;
     
     private ProviderFactory baseFactory;
+    private Comparator<?> providerComparator;
     
     protected ProviderFactory(ProviderFactory baseFactory, Bus bus) {
         this.baseFactory = baseFactory;
@@ -595,11 +596,26 @@ public abstract class ProviderFactory {
      * x/y;q=1.0 < x/y;q=0.7.
      */    
     private void sortReaders() {
-        Collections.sort(messageReaders, new MessageBodyReaderComparator());
+        if (providerComparator == null) {
+            Collections.sort(messageReaders, new MessageBodyReaderComparator());
+        } else {
+            doCustomSort(messageReaders);
+        }
+    }
+    private <T> void sortWriters() {
+        if (providerComparator == null) {
+            Collections.sort(messageWriters, new MessageBodyWriterComparator());
+        } else {
+            doCustomSort(messageWriters);
+        }
     }
     
-    private void sortWriters() {
-        Collections.sort(messageWriters, new MessageBodyWriterComparator());
+    private <T> void doCustomSort(List<?> listOfProviders) {
+        @SuppressWarnings("unchecked")
+        List<T> theProviders = (List<T>)messageReaders;
+        @SuppressWarnings("unchecked")
+        Comparator<? super T> theComparator = (Comparator<? super T>)providerComparator;
+        Collections.sort((List<T>)theProviders, theComparator);
     }
     
     private void sortContextResolvers() {
@@ -1243,4 +1259,12 @@ public abstract class ProviderFactory {
         }
         return null;
     }
+
+    public Comparator<?> getProviderComparator() {
+        return providerComparator;
+    }
+
+    public void setProviderComparator(Comparator<?> providerComparator) {
+        this.providerComparator = providerComparator;
+    }
 }


Mime
View raw message