cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5899] More work to do with supporting the injection of Configuration
Date Thu, 28 Aug 2014 13:03:27 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 4d2dbb0f3 -> c56913cd0


[CXF-5899] More work to do with supporting the injection of Configuration


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

Branch: refs/heads/master
Commit: c56913cd0ed9a0c6f0a7780d00b3c6ac06409c75
Parents: 4d2dbb0
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Thu Aug 28 14:03:04 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Thu Aug 28 14:03:04 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     |  14 +--
 .../jaxrs/provider/ServerProviderFactory.java   | 123 ++++++++++++++-----
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |   2 +-
 .../cxf/jaxrs/client/ClientProviderFactory.java |  10 +-
 .../cxf/jaxrs/client/spec/ClientImpl.java       |   3 +-
 .../client/spec/ClientRequestContextImpl.java   |   2 +-
 .../jaxrs/JAXRS20ClientServerBookTest.java      |   7 +-
 7 files changed, 111 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/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 f95a829..040f505 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
@@ -97,8 +97,6 @@ public abstract class ProviderFactory {
         new NameKeyMap<ProviderInfo<ReaderInterceptor>>(true);
     protected Map<NameKey, ProviderInfo<WriterInterceptor>> writerInterceptors
= 
         new NameKeyMap<ProviderInfo<WriterInterceptor>>(true);
-    private Configuration dynamicConfiguration;
-    
     
     private List<ProviderInfo<MessageBodyReader<?>>> messageReaders = 
         new ArrayList<ProviderInfo<MessageBodyReader<?>>>();
@@ -163,15 +161,7 @@ public abstract class ProviderFactory {
         return null;
     }
     
-    public void setConfiguration(Configuration config) {
-        // Whatever is set inside Configuration is also set in this ProviderFactory
-        // We use it only to support Configuration injection at a basic level
-        this.dynamicConfiguration = config;
-    }
-    
-    public Configuration getConfiguration() {
-        return dynamicConfiguration;
-    }
+    public abstract Configuration getConfiguration(Message message);
     
     public <T> ContextResolver<T> createContextResolver(Type contextType, 
                                                         Message m) {
@@ -570,7 +560,7 @@ 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()) {
+            if (pi.getProvider() == provider.getProvider()) {
                 return;
             }
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/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 9f93528..9418224 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
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.ws.rs.Priorities;
 import javax.ws.rs.RuntimeType;
 import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.ContainerResponseFilter;
@@ -46,6 +47,7 @@ import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.impl.ConfigurableImpl;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
@@ -132,6 +134,8 @@ public final class ServerProviderFactory extends ProviderFactory {
         factory.setProviders(new WebApplicationExceptionMapper());
         
         bus.setProperty(SHARED_SERVER_FACTORY, factory);
+
+
         return factory;
     }
     
@@ -339,9 +343,8 @@ public final class ServerProviderFactory extends ProviderFactory {
         }
     }
     
-    @Override
-    public Configuration getConfiguration() {
-        return new ServerConfigurationImpl(super.getConfiguration());
+    public Configuration getConfiguration(Message m) {
+        return new ServerConfigurationImpl();
     }
     
     private void doApplyDynamicFeatures(ClassResourceInfo cri) {
@@ -350,7 +353,6 @@ public final class ServerProviderFactory extends ProviderFactory {
             for (DynamicFeature feature : dynamicFeatures) {
                 FeatureContext featureContext = new MethodFeatureContextImpl(ori);
                 feature.configure(new ResourceInfoImpl(ori), featureContext);
-                super.setConfiguration(featureContext.getConfiguration());
             }
         }
         Collection<ClassResourceInfo> subs = cri.getSubResources();
@@ -506,68 +508,129 @@ public final class ServerProviderFactory extends ProviderFactory {
     
     
     private class ServerConfigurationImpl implements Configuration {
-        private Configuration superConfig;
-        public ServerConfigurationImpl(Configuration superConfig) {
-            this.superConfig = superConfig;
+        public ServerConfigurationImpl() {
+            
         }
         
         @Override
         public Set<Class<?>> getClasses() {
-            return superConfig != null ? superConfig.getClasses() : Collections.<Class<?>>emptySet();
+            return application != null ? application.getProvider().getClasses() 
+                : Collections.<Class<?>>emptySet();
         }
 
         @Override
         public Set<Object> getInstances() {
-            return superConfig != null ? superConfig.getInstances() : Collections.emptySet();
+            return application != null ? application.getProvider().getSingletons() 
+                : Collections.emptySet();
         }
 
         @Override
-        public Map<String, Object> getProperties() {
-            return application != null ? application.getProperties() 
-                : Collections.<String, Object>emptyMap();
+        public boolean isEnabled(Feature f) {
+            return dynamicFeatures.contains(f);
         }
 
         @Override
-        public Object getProperty(String name) {
-            return getProperties().get(name);
+        public boolean isEnabled(Class<? extends Feature> featureCls) {
+            for (DynamicFeature f : dynamicFeatures) {
+                if (featureCls.isAssignableFrom(f.getClass())) { 
+                    return true;
+                }
+            }
+            return false;
         }
 
         @Override
-        public Collection<String> getPropertyNames() {
-            return getProperties().keySet();
+        public boolean isRegistered(Object o) {
+            return isRegistered(preMatchContainerRequestFilters, o)
+                || isRegistered(postMatchContainerRequestFilters.values(), o)
+                || isRegistered(containerResponseFilters.values(), o)
+                || isRegistered(readerInterceptors.values(), o)
+                || isRegistered(writerInterceptors.values(), o);
         }
 
         @Override
-        public RuntimeType getRuntimeType() {
-            return RuntimeType.SERVER;
+        public boolean isRegistered(Class<?> cls) {
+            return isRegistered(preMatchContainerRequestFilters, cls)
+                || isRegistered(postMatchContainerRequestFilters.values(), cls)
+                || isRegistered(containerResponseFilters.values(), cls)
+                || isRegistered(readerInterceptors.values(), cls)
+                || isRegistered(writerInterceptors.values(), cls);
         }
 
         @Override
-        public boolean isEnabled(Feature f) {
-            return superConfig != null ? superConfig.isEnabled(f) : false;
+        public Map<Class<?>, Integer> getContracts(Class<?> cls) {
+            Map<Class<?>, Integer> map = new HashMap<Class<?>, Integer>();
+            if (isRegistered(cls)) {
+                if (ContainerRequestFilter.class.isAssignableFrom(cls)) {
+                    boolean isPreMatch = cls.getAnnotation(PreMatching.class) != null;
+                    map.put(ContainerRequestFilter.class, 
+                            getPriority(isPreMatch ? preMatchContainerRequestFilters
+                                : postMatchContainerRequestFilters.values(), cls, ContainerRequestFilter.class));
   
+                }
+                if (ContainerResponseFilter.class.isAssignableFrom(cls)) {
+                    map.put(ContainerResponseFilter.class, 
+                            getPriority(containerResponseFilters.values(), cls, ContainerResponseFilter.class));
   
+                }
+                if (WriterInterceptor.class.isAssignableFrom(cls)) {
+                    map.put(WriterInterceptor.class, 
+                            getPriority(writerInterceptors.values(), cls, WriterInterceptor.class));
   
+                }
+                if (ReaderInterceptor.class.isAssignableFrom(cls)) {
+                    map.put(ReaderInterceptor.class, 
+                            getPriority(readerInterceptors.values(), cls, ReaderInterceptor.class));
   
+                }
+            }
+            return map;
         }
-
+        
         @Override
-        public boolean isEnabled(Class<? extends Feature> featureCls) {
-            return superConfig != null ? superConfig.isEnabled(featureCls) : false;
+        public Map<String, Object> getProperties() {
+            return application != null ? application.getProperties() 
+                : Collections.<String, Object>emptyMap();
         }
 
         @Override
-        public boolean isRegistered(Object o) {
-            return superConfig != null ? superConfig.isRegistered(o) : false;
+        public Object getProperty(String name) {
+            return getProperties().get(name);
         }
 
         @Override
-        public boolean isRegistered(Class<?> cls) {
-            return superConfig != null ? superConfig.isRegistered(cls) : false;
+        public Collection<String> getPropertyNames() {
+            return getProperties().keySet();
         }
 
         @Override
-        public Map<Class<?>, Integer> getContracts(Class<?> cls) {
-            return superConfig != null ? superConfig.getContracts(cls)
-                : Collections.<Class<?>, Integer>emptyMap();
+        public RuntimeType getRuntimeType() {
+            return RuntimeType.SERVER;
         }
         
+        private boolean isRegistered(Collection<?> list, Object o) {
+            Collection<ProviderInfo<?>> list2 = CastUtils.cast(list);
+            for (ProviderInfo<?> pi : list2) {
+                if (pi.getProvider() == o) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        private boolean isRegistered(Collection<?> list, Class<?> cls) {
+            Collection<ProviderInfo<?>> list2 = CastUtils.cast(list);
+            for (ProviderInfo<?> pi : list2) {
+                if (cls.isAssignableFrom(pi.getProvider().getClass())) {
+                    return true;
+                }
+            }
+            return false;
+        }
+        private Integer getPriority(Collection<?> list, Class<?> cls, Class<?>
filterClass) {
+            Collection<ProviderInfo<?>> list2 = CastUtils.cast(list);
+            for (ProviderInfo<?> pi : list2) {
+                if (pi instanceof FilterProviderInfo && pi.getProvider().getClass().isAssignableFrom(cls))
{
+                    return ((FilterProviderInfo<?>)pi).getPriority(filterClass);
+                }
+            }
+            return Priorities.USER;
+        }
     }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index a655c9b..d85a26b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -1078,7 +1078,7 @@ public final class JAXRSUtils {
         } else if (ContextResolver.class.isAssignableFrom(clazz)) {
             o = createContextResolver(genericType, contextMessage);
         } else if (Configuration.class.isAssignableFrom(clazz)) {
-            o = ProviderFactory.getInstance(contextMessage).getConfiguration();
+            o = ProviderFactory.getInstance(contextMessage).getConfiguration(contextMessage);
         } else if (Application.class.isAssignableFrom(clazz)) {
             ProviderInfo<?> providerInfo = 
                 (ProviderInfo<?>)contextMessage.getExchange().getEndpoint().get(Application.class.getName());

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/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 e68465f..0c2b20b 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
@@ -25,6 +25,7 @@ import java.util.List;
 
 import javax.ws.rs.client.ClientRequestFilter;
 import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.Configuration;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -43,7 +44,6 @@ public final class ClientProviderFactory extends ProviderFactory {
         new ArrayList<ProviderInfo<ClientResponseFilter>>(1);
     private List<ProviderInfo<ResponseExceptionMapper<?>>> responseExceptionMappers
= 
         new ArrayList<ProviderInfo<ResponseExceptionMapper<?>>>(1);
-   
     
     private ClientProviderFactory(ProviderFactory baseFactory, Bus bus) {
         super(baseFactory, bus);
@@ -82,8 +82,6 @@ public final class ClientProviderFactory extends ProviderFactory {
         bus.setProperty(SHARED_CLIENT_FACTORY, factory);
         return factory;
     }
-    
-    
     @Override
     protected void setProviders(Object... providers) {
         List<ProviderInfo<? extends Object>> theProviders = 
@@ -142,5 +140,11 @@ public final class ClientProviderFactory extends ProviderFactory {
     public List<ProviderInfo<ClientResponseFilter>> getClientResponseFilters()
{
         return Collections.unmodifiableList(clientResponseFilters);
     }
+
+    @Override
+    public Configuration getConfiguration(Message m) {
+        return (Configuration)m.getExchange().getOutMessage()
+            .getContextualProperty(Configuration.class.getName());
+    }
     
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
index bdcffa0..88d7317 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
@@ -252,9 +252,10 @@ public class ClientImpl implements Client {
             }
             
             pf.setUserProviders(providers);
-            pf.setConfiguration(getConfiguration());
             WebClient.getConfig(targetClient).getRequestContext().putAll(getConfiguration().getProperties());
             WebClient.getConfig(targetClient).getRequestContext().put(Client.class.getName(),
ClientImpl.this);
+            WebClient.getConfig(targetClient).getRequestContext().put(Configuration.class.getName(),

+                                                                      getConfiguration());
             // TLS
             TLSClientParameters tlsParams = secConfig.getTlsClientParams();
             if (tlsParams.getSSLSocketFactory() != null 

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
index 24963fb..7a3d27d 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientRequestContextImpl.java
@@ -66,7 +66,7 @@ public class ClientRequestContextImpl extends AbstractRequestContextImpl
     @Override
     public Configuration getConfiguration() {
         ClientProviderFactory cpf = ClientProviderFactory.getInstance(m);
-        return cpf.getConfiguration();
+        return cpf.getConfiguration(m);
     }
     
     private Object getMessageContent() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c56913cd/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index 948922a..a70bea6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -39,6 +39,7 @@ import javax.ws.rs.client.ClientResponseContext;
 import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
+import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.GenericType;
 import javax.ws.rs.core.HttpHeaders;
@@ -153,8 +154,10 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
         Client client = ClientBuilder.newClient();
         client.register(new BookInfoReader());
-        BookInfo book = client.target(address)
-            .request("application/xml").get(BookInfo.class);
+        WebTarget target = client.target(address);
+        BookInfo book = target.request("application/xml").get(BookInfo.class);
+        assertEquals(124L, book.getId());
+        book = target.request("application/xml").get(BookInfo.class);
         assertEquals(124L, book.getId());
     }
     


Mime
View raw message