cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1509277 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rs/client/src/main/java/org/apache/cxf...
Date Thu, 01 Aug 2013 15:06:16 GMT
Author: sergeyb
Date: Thu Aug  1 15:06:15 2013
New Revision: 1509277

URL: http://svn.apache.org/r1509277
Log:
[CXF-5135] Supporting a case where an object imlpementing multiple filter contracts wants
each contract to have its own unique priority

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
    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/ClientConfigurableImpl.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/impl/ConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java?rev=1509277&r1=1509276&r2=1509277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
Thu Aug  1 15:06:15 2013
@@ -81,9 +81,13 @@ public class ConfigurableImpl<C extends 
     
     @Override
     public C register(Object provider, Map<Class<?>, Integer> contracts) {
-        for (Map.Entry<Class<?>, Integer> entry : contracts.entrySet()) {
-            doRegister(provider, entry.getValue(), entry.getKey());
+        if (provider instanceof Feature) {
+            Feature feature = (Feature)provider;
+            config.setFeature(feature);
+            feature.configure(new FeatureContextImpl(this));
+            return configurable;
         }
+        config.register(provider, contracts);
         return configurable;
     }
     
@@ -108,15 +112,8 @@ public class ConfigurableImpl<C extends 
         return register(ConfigurationImpl.createProvider(providerClass), contracts);
     }
     
-    protected C doRegister(Object provider, int bindingPriority, Class<?>... contracts)
{
-        if (provider instanceof Feature) {
-            Feature feature = (Feature)provider;
-            config.setFeature(feature);
-            feature.configure(new FeatureContextImpl(this));
-            return configurable;
-        }
-        config.register(provider, bindingPriority, contracts);
-        return configurable;
+    private C doRegister(Object provider, int bindingPriority, Class<?>... contracts)
{
+        return register(provider, ConfigurationImpl.initContractsMap(bindingPriority, contracts));
     }
 
     public static class FeatureContextImpl implements FeatureContext {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java?rev=1509277&r1=1509276&r2=1509277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
Thu Aug  1 15:06:15 2013
@@ -49,22 +49,22 @@ public class ConfigurationImpl implement
             
             Set<Class<?>> providerClasses = new HashSet<Class<?>>(parent.getClasses());
             for (Object o : parent.getInstances()) {
-                registerParentProvider(o, parent);
+                registerParentProvider(o, parent, defaultContracts);
                 providerClasses.remove(o.getClass());
             }
             for (Class<?> cls : providerClasses) {
-                registerParentProvider(createProvider(cls), parent);
+                registerParentProvider(createProvider(cls), parent, defaultContracts);
             }
             
         }
     }
     
-    private void registerParentProvider(Object o, Configuration parent) {
+    private void registerParentProvider(Object o, Configuration parent, Class<?>[]
defaultContracts) {
         Map<Class<?>, Integer> contracts = parent.getContracts(o.getClass());
         if (contracts != null) {
             providers.put(o, contracts);
         } else {
-            register(o, AnnotationUtils.getBindingPriority(o.getClass()));
+            register(o, AnnotationUtils.getBindingPriority(o.getClass()), defaultContracts);
         }
     }
     
@@ -155,19 +155,31 @@ public class ConfigurationImpl implement
     }
     
     
-    public void register(Object provider, int bindingPriority, Class<?>... contracts)
{
+    private void register(Object provider, int bindingPriority, Class<?>... contracts)
{
+        register(provider, initContractsMap(bindingPriority, contracts));
+    }
+    
+    public void register(Object provider, Map<Class<?>, Integer> contracts) {
   
         Map<Class<?>, Integer> metadata = providers.get(provider);
         if (metadata == null) {
             metadata = new HashMap<Class<?>, Integer>();
             providers.put(provider, metadata);
         }
-        for (Class<?> contract : contracts) {
+        for (Class<?> contract : contracts.keySet()) {
             if (contract.isAssignableFrom(provider.getClass())) {
-                metadata.put(contract, bindingPriority);
+                metadata.put(contract, contracts.get(contract));
             }
         }
     }
     
+    public static Map<Class<?>, Integer> initContractsMap(int bindingPriority,
Class<?>... contracts) {
+        Map<Class<?>, Integer> metadata = new HashMap<Class<?>, Integer>();
+        for (Class<?> contract : contracts) {
+            metadata.put(contract, bindingPriority);
+        }
+        return metadata;
+    }
+    
     public static Object createProvider(Class<?> cls) {
         try {
             return cls.newInstance();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java?rev=1509277&r1=1509276&r2=1509277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/FilterProviderInfo.java
Thu Aug  1 15:06:15 2013
@@ -20,7 +20,7 @@
 package org.apache.cxf.jaxrs.model;
 
 import java.util.Collections;
-import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.cxf.Bus;
@@ -28,17 +28,14 @@ import org.apache.cxf.Bus;
 public class FilterProviderInfo<T> extends ProviderInfo<T> {
 
     private Set<String> nameBinding;
-    private int priority;
-    private List<Class<?>> supportedContracts;
+    private Map<Class<?>, Integer> supportedContracts;
     
     public FilterProviderInfo(T provider,
                               Bus bus,
                               String nameBinding,
-                              int priority,
-                              List<Class<?>> supportedContracts) {
+                              Map<Class<?>, Integer> supportedContracts) {
         super(provider, bus);
         this.nameBinding = Collections.singleton(nameBinding);
-        this.priority = priority;
         this.supportedContracts = supportedContracts;        
     }
 
@@ -46,12 +43,12 @@ public class FilterProviderInfo<T> exten
         return nameBinding;
     }
 
-    public int getPriority() {
-        return priority;
+    public int getPriority(Class<?> contract) {
+        return supportedContracts.get(contract);
     }
 
-    public List<Class<?>> getSupportedContracts() {
-        return supportedContracts;
+    public Set<Class<?>> getSupportedContracts() {
+        return supportedContracts.keySet();
     }
 
 }

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=1509277&r1=1509276&r2=1509277&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
Thu Aug  1 15:06:15 2013
@@ -116,7 +116,7 @@ public abstract class ProviderFactory {
         this.bus = bus;
     }
     
-    protected Bus getBus() {
+    public Bus getBus() {
         return bus;
     }
     
@@ -532,8 +532,8 @@ public abstract class ProviderFactory {
         sortWriters();
         sortContextResolvers();
         
-        mapInterceptorFilters(readerInterceptors, readInts, true);
-        mapInterceptorFilters(writerInterceptors, writeInts, true);
+        mapInterceptorFilters(readerInterceptors, readInts, ReaderInterceptor.class, true);
+        mapInterceptorFilters(writerInterceptors, writeInts, WriterInterceptor.class, true);
         
         injectContextProxies(messageReaders, messageWriters, contextResolvers, 
             readerInterceptors.values(), writerInterceptors.values());
@@ -995,13 +995,16 @@ public abstract class ProviderFactory {
     
     protected static class BindingPriorityComparator extends AbstractPriorityComparator
         implements Comparator<ProviderInfo<?>> {
-    
-        public BindingPriorityComparator(boolean ascending) {
+        private Class<?> providerCls;
+        
+        public BindingPriorityComparator(Class<?> providerCls, boolean ascending) {
             super(ascending); 
+            this.providerCls = providerCls;
         }
         
         public int compare(ProviderInfo<?> p1, ProviderInfo<?> p2) {
-            return compare(getFilterPriority(p1), getFilterPriority(p2));
+            return compare(getFilterPriority(p1, providerCls), 
+                           getFilterPriority(p2, providerCls));
         }
         
     }
@@ -1072,12 +1075,13 @@ public abstract class ProviderFactory {
     
     protected static <T> void mapInterceptorFilters(Map<NameKey, ProviderInfo<T>>
map,
                                                     List<ProviderInfo<T>> filters,
+                                                    Class<?> providerCls,
                                                     boolean ascending) {
         
         for (ProviderInfo<T> p : filters) { 
             Set<String> names = getFilterNameBindings(p);
             
-            int priority = getFilterPriority(p);
+            int priority = getFilterPriority(p, providerCls);
             
             for (String name : names) {
                 map.put(new NameKey(name, priority), p);
@@ -1100,8 +1104,8 @@ public abstract class ProviderFactory {
         return names;
     }
     
-    protected static int getFilterPriority(ProviderInfo<?> p) {
-        return p instanceof FilterProviderInfo ? ((FilterProviderInfo<?>)p).getPriority()
+    protected static int getFilterPriority(ProviderInfo<?> p, Class<?> providerCls)
{
+        return p instanceof FilterProviderInfo ? ((FilterProviderInfo<?>)p).getPriority(providerCls)
             : AnnotationUtils.getBindingPriority(p.getProvider().getClass());
     }
     
@@ -1136,7 +1140,7 @@ public abstract class ProviderFactory {
                                                      Class<?> contract) {
         boolean result = false;
         if (contract.isAssignableFrom(providerCls)) {
-            List<Class<?>> actualContracts = null;
+            Set<Class<?>> actualContracts = null;
             if (provider instanceof FilterProviderInfo) {    
                 actualContracts = ((FilterProviderInfo<?>)provider).getSupportedContracts();
             }

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=1509277&r1=1509276&r2=1509277&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
Thu Aug  1 15:06:15 2013
@@ -37,7 +37,6 @@ import javax.ws.rs.container.PreMatching
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.FeatureContext;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.ReaderInterceptor;
@@ -239,9 +238,12 @@ public final class ServerProviderFactory
             
         }
         
-        Collections.sort(preMatchContainerRequestFilters, new BindingPriorityComparator(true));
-        mapInterceptorFilters(postMatchContainerRequestFilters, postMatchRequestFilters,
true);
-        mapInterceptorFilters(postMatchContainerResponseFilters, postMatchResponseFilters,
false);
+        Collections.sort(preMatchContainerRequestFilters, 
+            new BindingPriorityComparator(ContainerRequestFilter.class, true));
+        mapInterceptorFilters(postMatchContainerRequestFilters, postMatchRequestFilters,
+                              ContainerRequestFilter.class, true);
+        mapInterceptorFilters(postMatchContainerResponseFilters, postMatchResponseFilters,
+                              ContainerResponseFilter.class, false);
         
         injectContextProxies(exceptionMappers,
             postMatchContainerRequestFilters.values(), preMatchContainerRequestFilters,
@@ -422,26 +424,20 @@ public final class ServerProviderFactory
             return configImpl.register(object, map);
         }
         
-        FeatureContext doRegister(Object provider, int priority, Class<?>... contracts)
{
+        FeatureContext doRegister(Object provider, Map<Class<?>, Integer> contracts)
{
         
-            if (provider instanceof Feature) {
-                ((Feature)provider).configure(this);
-                return this;
-            }
-            
-            List<Class<?>> actualContracts = new LinkedList<Class<?>>();
+            Map<Class<?>, Integer> actualContracts = new HashMap<Class<?>,
Integer>();
             
-            for (Class<?> contract : contracts) {
+            for (Class<?> contract : contracts.keySet()) {
                 if (SERVER_FILTER_INTERCEPTOR_CLASSES.contains(contract)
                     && contract.isAssignableFrom(provider.getClass())) {
-                    actualContracts.add(contract);
+                    actualContracts.put(contract, contracts.get(contract));
                 }
             }
             if (!actualContracts.isEmpty()) {
                 registerUserProvider(new FilterProviderInfo<Object>(provider, 
                     getBus(),
                     nameBinding,
-                    priority,
                     actualContracts));
                 ori.addNameBindings(Collections.singletonList(nameBinding));
             }
@@ -455,10 +451,10 @@ public final class ServerProviderFactory
             super(mc, RuntimeType.SERVER, SERVER_FILTER_INTERCEPTOR_CLASSES.toArray(new Class<?>[]{}));
         }
         @Override
-        protected FeatureContext doRegister(Object provider, int bindingPriority, Class<?>...
contracts) {
-            super.doRegister(provider, bindingPriority, contracts);
+        public FeatureContext register(Object provider, Map<Class<?>, Integer>
contracts) {
+            super.register(provider, contracts);
             return ((MethodFeatureContextImpl)super.getConfigurable())
-                .doRegister(provider, bindingPriority, contracts);
+                .doRegister(provider, contracts);
         }
         
     }

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=1509277&r1=1509276&r2=1509277&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
Thu Aug  1 15:06:15 2013
@@ -92,11 +92,11 @@ public final class ClientProviderFactory
         super.setCommonProviders(theProviders);
         for (ProviderInfo<? extends Object> provider : theProviders) {
             Class<?> providerCls = ClassHelper.getRealClass(provider.getProvider());
-            if (ClientRequestFilter.class.isAssignableFrom(providerCls)) {
+            if (filterContractSupported(provider, providerCls, ClientRequestFilter.class))
{
                 clientRequestFilters.add((ProviderInfo<ClientRequestFilter>)provider);
             }
             
-            if (ClientResponseFilter.class.isAssignableFrom(providerCls)) {
+            if (filterContractSupported(provider, providerCls, ClientResponseFilter.class))
{
                 clientResponseFilters.add((ProviderInfo<ClientResponseFilter>)provider);
             }
             
@@ -104,8 +104,10 @@ public final class ClientProviderFactory
                 responseExceptionMappers.add((ProviderInfo<ResponseExceptionMapper<?>>)provider);

             }
         }
-        Collections.sort(clientRequestFilters, new BindingPriorityComparator(true));
-        Collections.sort(clientResponseFilters, new BindingPriorityComparator(false));
+        Collections.sort(clientRequestFilters, 
+                         new BindingPriorityComparator(ClientRequestFilter.class, true));
+        Collections.sort(clientResponseFilters, 
+                         new BindingPriorityComparator(ClientResponseFilter.class, false));
         
         injectContextProxies(responseExceptionMappers, clientRequestFilters, clientResponseFilters);
     }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java?rev=1509277&r1=1509276&r2=1509277&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
Thu Aug  1 15:06:15 2013
@@ -23,8 +23,6 @@ import javax.ws.rs.client.ClientRequestF
 import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
-import javax.ws.rs.ext.MessageBodyReader;
-import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.ReaderInterceptor;
 import javax.ws.rs.ext.WriterInterceptor;
 
@@ -35,8 +33,6 @@ public class ClientConfigurableImpl<C ex
     private static final Class<?>[] CLIENT_FILTER_INTERCEPTOR_CLASSES = 
         new Class<?>[] {ClientRequestFilter.class,
                         ClientResponseFilter.class,
-                        MessageBodyReader.class,
-                        MessageBodyWriter.class,
                         ReaderInterceptor.class,
                         WriterInterceptor.class};
     

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=1509277&r1=1509276&r2=1509277&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
Thu Aug  1 15:06:15 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.client.spec
 import java.net.URI;
 import java.util.HashSet;
 import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -39,6 +40,7 @@ import javax.ws.rs.core.UriBuilderExcept
 import org.apache.cxf.jaxrs.client.ClientProviderFactory;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.model.FilterProviderInfo;
 
 public class ClientImpl implements Client {
     private Configurable<Client> configImpl;
@@ -189,7 +191,19 @@ public class ClientImpl implements Clien
             // register directly on the endpoint-specific ClientFactory
             ClientProviderFactory pf = 
                 ClientProviderFactory.getInstance(WebClient.getConfig(targetClient).getEndpoint());
-            pf.setUserProviders(new LinkedList<Object>(configImpl.getConfiguration().getInstances()));
+            List<Object> providers = new LinkedList<Object>();
+            Configuration cfg = configImpl.getConfiguration();
+            for (Object p : cfg.getInstances()) {
+                Map<Class<?>, Integer> contracts = cfg.getContracts(p.getClass());
+                if (contracts == null || contracts.isEmpty()) {
+                    providers.add(p);
+                } else {
+                    providers.add(
+                        new FilterProviderInfo<Object>(p, pf.getBus(), null, contracts));
+                }
+            }
+            
+            pf.setUserProviders(providers);
             
             // Collect the properties which may have been reset the requests
             WebClient.getConfig(targetClient).getRequestContext().putAll(configImpl.getConfiguration().getProperties());



Mime
View raw message