cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1513105 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rs/client/src/main/java/org/apache/cxf/jaxrs/client/ rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/
Date Mon, 12 Aug 2013 11:21:52 GMT
Author: sergeyb
Date: Mon Aug 12 11:21:52 2013
New Revision: 1513105

URL: http://svn.apache.org/r1513105
Log:
[CXF-5135] Some work to avoid the duplicate registration of various providers due to Client
2.0 API making the duplication possible

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1513105&r1=1513104&r2=1513105&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Mon Aug 12 11:21:52 2013
@@ -31,6 +31,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -101,7 +102,7 @@ public abstract class ProviderFactory {
     private List<ProviderInfo<ContextProvider<?>>> contextProviders = 
         new ArrayList<ProviderInfo<ContextProvider<?>>>(1);
     
-    private List<ParamConverterProvider> newParamConverters;
+    private Set<ParamConverterProvider> newParamConverters;
     
     // List of injected providers
     private Collection<ProviderInfo<?>> injectedProviders = 
@@ -496,19 +497,19 @@ public abstract class ProviderFactory {
             Class<?> providerCls = ClassHelper.getRealClass(provider.getProvider());
             
             if (MessageBodyReader.class.isAssignableFrom(providerCls)) {
-                messageReaders.add((ProviderInfo<MessageBodyReader<?>>)provider);

+                addProviderToList(messageReaders, provider);
             }
             
             if (MessageBodyWriter.class.isAssignableFrom(providerCls)) {
-                messageWriters.add((ProviderInfo<MessageBodyWriter<?>>)provider);

+                addProviderToList(messageWriters, provider);
             }
             
             if (ContextResolver.class.isAssignableFrom(providerCls)) {
-                contextResolvers.add((ProviderInfo<ContextResolver<?>>)provider);

+                addProviderToList(contextResolvers, provider);
             }
             
             if (ContextProvider.class.isAssignableFrom(providerCls)) {
-                contextProviders.add((ProviderInfo<ContextProvider<?>>)provider);

+                addProviderToList(contextProviders, provider);
             }
             
             if (filterContractSupported(provider, providerCls, ReaderInterceptor.class))
{
@@ -523,7 +524,7 @@ public abstract class ProviderFactory {
                 //TODO: review the possibility of ParamConverterProvider needing to have
Contexts injected
                 Object converter = provider.getProvider();
                 if (newParamConverters == null) {
-                    newParamConverters = new LinkedList<ParamConverterProvider>();
+                    newParamConverters = new LinkedHashSet<ParamConverterProvider>();
                 }
                 newParamConverters.add((ParamConverterProvider)converter);
             }
@@ -545,6 +546,16 @@ public abstract class ProviderFactory {
         }
     }
     
+    protected void addProviderToList(List<?> list, ProviderInfo<?> provider)
{
+        List<ProviderInfo<?>> list2 = CastUtils.cast(list);
+        for (ProviderInfo<?> pi : list2) {
+            if (pi.getProvider().getClass() == provider.getProvider().getClass()) {
+                return;
+            }
+        }
+        list2.add(provider);
+    }
+    
     protected void injectContextProxies(Collection<?> ... providerLists) {
         for (Collection<?> list : providerLists) {
             Collection<ProviderInfo<?>> l2 = CastUtils.cast(list);
@@ -1054,10 +1065,14 @@ public abstract class ProviderFactory {
     
     protected static class NameKey { 
         private String name;
-        private Integer bindingPriority;
-        public NameKey(String name, int priority) {
+        private Integer priority;
+        private Class<?> providerCls;
+        public NameKey(String name, 
+                       int priority,
+                       Class<?> providerCls) {
             this.name = name;
-            this.bindingPriority = priority;
+            this.priority = priority;
+            this.providerCls = providerCls;
         }
         
         public String getName() {
@@ -1065,11 +1080,24 @@ public abstract class ProviderFactory {
         }
         
         public Integer getPriority() {
-            return bindingPriority;
+            return priority;
         }
-                
+        
+        public boolean equals(Object o) {
+            if (!(o instanceof NameKey)) {
+                return false;
+            }
+            NameKey other = (NameKey)o;
+            return name.equals(other.name) && priority.equals(other.priority)
+                && providerCls == other.providerCls;  
+        }
+        
+        public int hashCode() {
+            return super.hashCode();
+        }
+        
         public String toString() {
-            return name + ":" + bindingPriority;
+            return name + ":" + priority;
         }
     }
     
@@ -1084,7 +1112,7 @@ public abstract class ProviderFactory {
             int priority = getFilterPriority(p, providerCls);
             
             for (String name : names) {
-                map.put(new NameKey(name, priority), p);
+                map.put(new NameKey(name, priority, p.getClass()), p);
             }
         }
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java?rev=1513105&r1=1513104&r2=1513105&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
Mon Aug 12 11:21:52 2013
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -79,7 +80,7 @@ public final class ServerProviderFactory
         new NameKeyMap<ProviderInfo<ContainerResponseFilter>>(false);
     private RequestPreprocessor requestPreprocessor;
     private ProviderInfo<Application> application;
-    private List<DynamicFeature> dynamicFeatures = new LinkedList<DynamicFeature>();
+    private Set<DynamicFeature> dynamicFeatures = new LinkedHashSet<DynamicFeature>();
     
     private Map<Class<?>, BeanParamInfo> beanParams = new HashMap<Class<?>,
BeanParamInfo>();
     private ProviderInfo<ContainerRequestFilter> wadlGenerator;
@@ -233,7 +234,7 @@ public final class ServerProviderFactory
             
             
             if (ExceptionMapper.class.isAssignableFrom(providerCls)) {
-                exceptionMappers.add((ProviderInfo<ExceptionMapper<?>>)provider);

+                addProviderToList(exceptionMappers, provider); 
             }
             
         }
@@ -273,7 +274,7 @@ public final class ServerProviderFactory
             wadlGenerator = p; 
         } else {
             if (isPrematching(filter.getClass())) {
-                preMatchContainerRequestFilters.add(p);
+                addProviderToList(preMatchContainerRequestFilters, p);
             } else {
                 postMatchFilters.add(p);
             }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java?rev=1513105&r1=1513104&r2=1513105&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
Mon Aug 12 11:21:52 2013
@@ -84,7 +84,6 @@ public final class ClientProviderFactory
     }
     
     
-    @SuppressWarnings("unchecked")
     @Override
     protected void setProviders(Object... providers) {
         List<ProviderInfo<? extends Object>> theProviders = 
@@ -93,15 +92,15 @@ public final class ClientProviderFactory
         for (ProviderInfo<? extends Object> provider : theProviders) {
             Class<?> providerCls = ClassHelper.getRealClass(provider.getProvider());
             if (filterContractSupported(provider, providerCls, ClientRequestFilter.class))
{
-                clientRequestFilters.add((ProviderInfo<ClientRequestFilter>)provider);
+                addProviderToList(clientRequestFilters, provider);
             }
             
             if (filterContractSupported(provider, providerCls, ClientResponseFilter.class))
{
-                clientResponseFilters.add((ProviderInfo<ClientResponseFilter>)provider);
+                addProviderToList(clientResponseFilters, provider);
             }
             
             if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) {
-                responseExceptionMappers.add((ProviderInfo<ResponseExceptionMapper<?>>)provider);

+                addProviderToList(responseExceptionMappers, provider);
             }
         }
         Collections.sort(clientRequestFilters, 

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java?rev=1513105&r1=1513104&r2=1513105&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
Mon Aug 12 11:21:52 2013
@@ -186,9 +186,7 @@ public class ClientImpl implements Clien
             ClientImpl.this.checkClosed();
             
             initTargetClientIfNeeded(); 
-            // API gives options to register new providers between 
-            // individual requests (sigh) or on per-WebTarget basis so we have to
-            // register directly on the endpoint-specific ClientFactory
+            
             ClientProviderFactory pf = 
                 ClientProviderFactory.getInstance(WebClient.getConfig(targetClient).getEndpoint());
             List<Object> providers = new LinkedList<Object>();
@@ -205,7 +203,6 @@ public class ClientImpl implements Clien
             
             pf.setUserProviders(providers);
             
-            // Collect the properties which may have been reset the requests
             WebClient.getConfig(targetClient).getRequestContext().putAll(configImpl.getConfiguration().getProperties());
             
             // start building the invocation



Mime
View raw message