cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6515] Optionally passing provider objects directly
Date Wed, 12 Aug 2015 16:18:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes c3e504710 -> 128a58093


[CXF-6515] Optionally passing provider objects directly


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

Branch: refs/heads/3.0.x-fixes
Commit: 128a58093c90990c99ffe04081dc3c919d008c39
Parents: c3e5047
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 12 17:17:34 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 12 17:18:16 2015 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 25 ++++++++++++----
 .../cxf/jaxrs/provider/ProviderFactoryTest.java | 30 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/128a5809/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 73a3234..b9075b0 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
@@ -593,16 +593,24 @@ public abstract class ProviderFactory {
                         return true;
                     }
                 }
+            } else if (type == Object.class) {
+                return true;
             }
         }
         return false;
     }
     
+    @SuppressWarnings("unchecked")
     private <T> void doCustomSort(List<?> listOfProviders) {
-        @SuppressWarnings("unchecked")
+        Comparator<?> theProviderComparator = providerComparator;
+        Type type = ((ParameterizedType)providerComparator.getClass()
+            .getGenericInterfaces()[0]).getActualTypeArguments()[0];
+        if (type == Object.class) {
+            theProviderComparator = 
+                (Comparator<?>)(new ProviderInfoClassComparator((Comparator<Object>)theProviderComparator));
+        }
         List<T> theProviders = (List<T>)listOfProviders;
-        @SuppressWarnings("unchecked")
-        Comparator<? super T> theComparator = (Comparator<? super T>)providerComparator;
+        Comparator<? super T> theComparator = (Comparator<? super T>)theProviderComparator;
         Collections.sort((List<T>)theProviders, theComparator);
     }
     
@@ -876,14 +884,20 @@ public abstract class ProviderFactory {
             return compareClasses(expectedCls, em1, em2);
         }
     }
+    
     public static class ProviderInfoClassComparator implements Comparator<ProviderInfo<?>>
{
-        private ClassComparator comp;
+        private Comparator<Object> comp;
+        private boolean defaultComp;
         public ProviderInfoClassComparator(Class<?> expectedCls) {
             this.comp = new ClassComparator(expectedCls);
+            this.defaultComp = true;
+        }
+        public ProviderInfoClassComparator(Comparator<Object> comp) {
+            this.comp = comp;
         }
         public int compare(ProviderInfo<?> p1, ProviderInfo<?> p2) {
             int result = comp.compare(p1.getProvider(), p2.getProvider());
-            if (result == 0) {
+            if (result == 0 && defaultComp) {
                 result = compareCustomStatus(p1, p2);
             }
             return result;
@@ -1210,4 +1224,5 @@ public abstract class ProviderFactory {
         sortReaders();
         sortWriters();
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/128a5809/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
index 199f227..7f6b209 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
@@ -133,6 +133,36 @@ public class ProviderFactoryTest extends Assert {
         Object lastReader = readers.get(7).getProvider();
         assertTrue(lastReader instanceof StringTextProvider);
     }
+    @Test
+    public void testCustomProviderSorting2() {
+        ProviderFactory pf = ServerProviderFactory.getInstance();
+        Comparator<Object> comp = new Comparator<Object>() {
+
+            @Override
+            public int compare(Object provider1, Object provider2) {
+                if (provider1 instanceof StringTextProvider) {
+                    return 1;
+                } else if (provider2 instanceof StringTextProvider) {
+                    return -1;
+                } else {
+                    return 0;
+                }
+            }    
+        
+        };
+        pf.setProviderComparator(comp);
+        
+        // writers
+        List<ProviderInfo<MessageBodyWriter<?>>> writers = pf.getMessageWriters();
+        assertEquals(8, writers.size());
+        Object lastWriter = writers.get(7).getProvider();
+        assertTrue(lastWriter instanceof StringTextProvider);
+        //readers
+        List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
+        assertEquals(8, readers.size());
+        Object lastReader = readers.get(7).getProvider();
+        assertTrue(lastReader instanceof StringTextProvider);
+    }
     @SuppressWarnings("rawtypes")
     @Test
     public void testCustomProviderSortingMBROnly() {


Mime
View raw message