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] Preferring custom endpoint-specific providers over custom bus(global) providers which are otherwise equal candidates
Date Wed, 12 Aug 2015 12:04:29 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f7b77f3a5 -> 507b390c5


[CXF-6515] Preferring custom endpoint-specific providers over custom bus(global) providers
which are otherwise equal candidates


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

Branch: refs/heads/master
Commit: 507b390c5bf82824c433896e7dbf762cf48effb0
Parents: f7b77f3
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 12 13:04:12 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 12 13:04:12 2015 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/model/ProviderInfo.java    |  9 ++++++
 .../cxf/jaxrs/provider/ProviderFactory.java     | 22 +++++++++++----
 .../jaxrs/provider/ServerProviderFactory.java   |  6 ++--
 .../cxf/jaxrs/provider/ProviderFactoryTest.java | 29 ++++++++++++++++++++
 .../cxf/jaxrs/client/ClientProviderFactory.java |  4 +--
 5 files changed, 59 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/507b390c/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
index 89d2bcd..fa755ff 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
@@ -28,6 +28,7 @@ public class ProviderInfo<T> extends AbstractResourceInfo {
 
     private T provider;
     private boolean custom;
+    private boolean busGlobal;
     
     public ProviderInfo(T provider, Bus bus, boolean custom) {
         this(provider, bus, true, custom);
@@ -78,4 +79,12 @@ public class ProviderInfo<T> extends AbstractResourceInfo {
         return custom;
     }
 
+    public boolean isBusGlobal() {
+        return busGlobal;
+    }
+
+    public void setBusGlobal(boolean busGlobal) {
+        this.busGlobal = busGlobal;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/507b390c/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 830036b..70333b7 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
@@ -127,6 +127,7 @@ public abstract class ProviderFactory {
     
     protected static void initFactory(ProviderFactory factory) {
         factory.setProviders(false,
+                             false,
                      new BinaryDataProvider<Object>(),
                      new SourceProvider<Object>(),
                      new DataSourceProvider<Object>(),
@@ -137,7 +138,7 @@ public abstract class ProviderFactory {
                      new MultipartProvider());
         Object prop = factory.getBus().getProperty("skip.default.json.provider.registration");
         if (!PropertyUtils.isTrue(prop)) {
-            factory.setProviders(false, createProvider(JSON_PROVIDER_NAME));
+            factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME));
         }
             
     }
@@ -442,7 +443,7 @@ public abstract class ProviderFactory {
                             MessageBodyWriter.class,
                             ExceptionMapper.class);
             if (!extensions.isEmpty()) {
-                setProviders(true, extensions.toArray());
+                setProviders(true, true, extensions.toArray());
                 bus.setProperty(alreadySetProp, "");
             }
         }
@@ -464,7 +465,7 @@ public abstract class ProviderFactory {
         }
     }
     
-    protected abstract void setProviders(boolean custom, Object... providers);
+    protected abstract void setProviders(boolean custom, boolean busGlobal, Object... providers);
     
     @SuppressWarnings("unchecked")
     protected void setCommonProviders(List<ProviderInfo<? extends Object>> theProviders)
{
@@ -657,7 +658,7 @@ public abstract class ProviderFactory {
      * @param entityProviders the entityProviders to set
      */
     public void setUserProviders(List<?> userProviders) {
-        setProviders(true, userProviders.toArray());
+        setProviders(true, false, userProviders.toArray());
     }
 
     private static class MessageBodyReaderComparator 
@@ -713,7 +714,13 @@ public abstract class ProviderFactory {
     private static int compareCustomStatus(ProviderInfo<?> p1, ProviderInfo<?>
p2) {
         Boolean custom1 = p1.isCustom();
         Boolean custom2 = p2.isCustom();
-        return custom1.compareTo(custom2) * -1;
+        int result = custom1.compareTo(custom2) * -1;
+        if (result == 0 && custom1) {
+            Boolean busGlobal1 = p1.isBusGlobal();
+            Boolean busGlobal2 = p2.isBusGlobal();
+            result = busGlobal1.compareTo(busGlobal2);
+        }
+        return result;
     }
     
     private static class ContextResolverComparator 
@@ -1138,6 +1145,7 @@ public abstract class ProviderFactory {
     }
     
     protected List<ProviderInfo<? extends Object>> prepareProviders(boolean custom,
+                                                                    boolean busGlobal,
                                                                     Object[] providers,
                                                                     ProviderInfo<Application>
application) {
         List<ProviderInfo<? extends Object>> theProviders = 
@@ -1158,7 +1166,9 @@ public abstract class ProviderFactory {
             } else if (provider instanceof ProviderInfo) {
                 theProviders.add((ProviderInfo<?>)provider);
             } else {    
-                theProviders.add(new ProviderInfo<Object>(provider, getBus(), custom));
+                ProviderInfo<Object> theProvider = new ProviderInfo<Object>(provider,
getBus(), custom);
+                theProvider.setBusGlobal(busGlobal);
+                theProviders.add(theProvider);
             }
         }
         return theProviders;

http://git-wip-us.apache.org/repos/asf/cxf/blob/507b390c/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
index 325e7e7..f904ecb 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
@@ -112,7 +112,7 @@ public final class ServerProviderFactory extends ProviderFactory {
         }
         ServerProviderFactory factory = new ServerProviderFactory(bus);
         ProviderFactory.initFactory(factory);
-        factory.setProviders(false, new WebApplicationExceptionMapper());
+        factory.setProviders(false, false, new WebApplicationExceptionMapper());
         factory.setBusProviders();
         return factory;
     }
@@ -183,14 +183,14 @@ public final class ServerProviderFactory extends ProviderFactory {
     
     @SuppressWarnings("unchecked")
     @Override
-    protected void setProviders(boolean custom, Object... providers) {
+    protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
         List<ProviderInfo<ContainerRequestFilter>> postMatchRequestFilters =

             new LinkedList<ProviderInfo<ContainerRequestFilter>>();
         List<ProviderInfo<ContainerResponseFilter>> postMatchResponseFilters
= 
             new LinkedList<ProviderInfo<ContainerResponseFilter>>();
         
         List<ProviderInfo<? extends Object>> theProviders = 
-            prepareProviders(custom, (Object[])providers, application);
+            prepareProviders(custom, busGlobal, (Object[])providers, application);
         super.setCommonProviders(theProviders);
         for (ProviderInfo<? extends Object> provider : theProviders) {
             Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());

http://git-wip-us.apache.org/repos/asf/cxf/blob/507b390c/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 f33d49d..ddedbc1 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
@@ -50,6 +50,8 @@ import javax.xml.bind.JAXBContext;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.validation.Schema;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.Customer;
@@ -133,6 +135,33 @@ public class ProviderFactoryTest extends Assert {
     }
     
     @Test
+    public void testCustomProviderSortingWithBus() {
+        WildcardReader wc1 = new WildcardReader();
+        WildcardReader2 wc2 = new WildcardReader2();
+        Bus bus = BusFactory.newInstance().createBus();
+        bus.setProperty(MessageBodyReader.class.getName(), wc1);
+        ProviderFactory pf = ServerProviderFactory.createInstance(bus);
+        pf.registerUserProvider(wc2);
+        List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
+        assertEquals(10, readers.size());
+        assertSame(wc2, readers.get(6).getProvider());
+        assertSame(wc1, readers.get(7).getProvider());
+    }
+    @Test
+    public void testCustomProviderSortingWithBus2() {
+        WildcardReader wc1 = new WildcardReader();
+        WildcardReader2 wc2 = new WildcardReader2();
+        Bus bus = BusFactory.newInstance().createBus();
+        bus.setProperty(MessageBodyReader.class.getName(), wc2);
+        ProviderFactory pf = ServerProviderFactory.createInstance(bus);
+        pf.registerUserProvider(wc1);
+        List<ProviderInfo<MessageBodyReader<?>>> readers = pf.getMessageReaders();
+        assertEquals(10, readers.size());
+        assertSame(wc1, readers.get(6).getProvider());
+        assertSame(wc2, readers.get(7).getProvider());
+    }
+    
+    @Test
     public void testCustomJaxbProvider() {
         ProviderFactory pf = ServerProviderFactory.getInstance();
         JAXBElementProvider<Book> provider = new JAXBElementProvider<Book>();

http://git-wip-us.apache.org/repos/asf/cxf/blob/507b390c/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
index b094a9a..dd2522e 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
@@ -68,9 +68,9 @@ public final class ClientProviderFactory extends ProviderFactory {
        
     
     @Override
-    protected void setProviders(boolean custom, Object... providers) {
+    protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
         List<ProviderInfo<? extends Object>> theProviders = 
-            prepareProviders(custom, (Object[])providers, null);
+            prepareProviders(custom, busGlobal, (Object[])providers, null);
         super.setCommonProviders(theProviders);
         for (ProviderInfo<? extends Object> provider : theProviders) {
             Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());


Mime
View raw message