cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Refactoring the way DynamicFeature is processed
Date Thu, 05 May 2016 16:50:55 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 15262ace1 -> d35b2a596


Refactoring the way DynamicFeature is processed


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

Branch: refs/heads/3.0.x-fixes
Commit: d35b2a596faa4339dc3ee450563c7cecf746b5d9
Parents: 15262ac
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu May 5 17:40:51 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu May 5 17:50:34 2016 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/impl/FeatureContextImpl.java      |   8 ++
 .../jaxrs/provider/ServerProviderFactory.java   | 136 +++++--------------
 2 files changed, 41 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d35b2a59/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
index 47fadf0..3ee6379 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/FeatureContextImpl.java
@@ -29,6 +29,8 @@ public class FeatureContextImpl implements FeatureContext {
     public FeatureContextImpl(Configurable<?> cfg) {
         this.cfg = cfg;
     }
+    public FeatureContextImpl() {
+    }
     
     @Override
     public Configuration getConfiguration() {
@@ -87,5 +89,11 @@ public class FeatureContextImpl implements FeatureContext {
     public FeatureContext register(Object obj, Map<Class<?>, Integer> map) {
         cfg.register(obj, map);
         return this;
+    }
+    public Configurable<?> getConfigurable() {
+        return cfg;
+    }
+    public void setConfigurable(Configurable<?> configurable) {
+        this.cfg = configurable;
     } 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/d35b2a59/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 5b31810..41e784b 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
@@ -39,6 +39,7 @@ import javax.ws.rs.container.ContainerRequestFilter;
 import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.container.DynamicFeature;
 import javax.ws.rs.container.PreMatching;
+import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
 import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.FeatureContext;
@@ -52,6 +53,7 @@ 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.FeatureContextImpl;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
@@ -343,9 +345,29 @@ public final class ServerProviderFactory extends ProviderFactory {
     private void doApplyDynamicFeatures(ClassResourceInfo cri) {
         Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
         for (OperationResourceInfo ori : oris) {
+            String nameBinding = DEFAULT_FILTER_NAME_BINDING 
+                + ori.getClassResourceInfo().getServiceClass().getName()
+                + "."
+                + ori.getMethodToInvoke().toString();
             for (DynamicFeature feature : dynamicFeatures) {
-                FeatureContext featureContext = new MethodFeatureContextImpl(ori);
+                FeatureContextImpl featureContext = new FeatureContextImpl();
+                MethodFeatureContextConfigurable configImpl = new MethodFeatureContextConfigurable(featureContext);
+                setApplicationProperties(configImpl);
+                featureContext.setConfigurable(configImpl);
+                
                 feature.configure(new ResourceInfoImpl(ori), featureContext);
+                Configuration cfg = featureContext.getConfiguration();
+                for (Object provider : cfg.getInstances()) {
+                    Map<Class<?>, Integer> contracts = cfg.getContracts(provider.getClass());
+                    if (contracts != null && !contracts.isEmpty()) {
+                        registerUserProvider(new FilterProviderInfo<Object>(provider,

+                            getBus(),
+                            nameBinding,
+                            true,
+                            contracts));
+                        ori.addNameBindings(Collections.singletonList(nameBinding));
+                    }
+                }
             }
         }
         Collection<ClassResourceInfo> subs = cri.getSubResources();
@@ -356,117 +378,25 @@ public final class ServerProviderFactory extends ProviderFactory {
         }
     }
     
-    protected static boolean isPrematching(Class<?> filterCls) {
-        return AnnotationUtils.getClassAnnotation(filterCls, PreMatching.class) != null;
-    }
-    
-    
-    
-    private class MethodFeatureContextImpl implements FeatureContext {
-        private MethodFeatureContextConfigurable configImpl;    
-        private OperationResourceInfo ori;
-        private String nameBinding;
-        
-        public MethodFeatureContextImpl(OperationResourceInfo ori) {
-            this.ori = ori;
-            configImpl = new MethodFeatureContextConfigurable(this);
-            if (application != null) {
-                Map<String, Object> appProps = application.getProvider().getProperties();
-                for (Map.Entry<String, Object> entry : appProps.entrySet()) {
-                    configImpl.property(entry.getKey(), entry.getValue());
-                }
+    private void setApplicationProperties(Configurable<?> configImpl) {
+        if (application != null) {
+            Map<String, Object> appProps = application.getProvider().getProperties();
+            for (Map.Entry<String, Object> entry : appProps.entrySet()) {
+                configImpl.property(entry.getKey(), entry.getValue());
             }
-            nameBinding = DEFAULT_FILTER_NAME_BINDING 
-                + ori.getClassResourceInfo().getServiceClass().getName()
-                + "."
-                + ori.getMethodToInvoke().toString();
-        }
-        
-
-        @Override
-        public Configuration getConfiguration() {
-            return configImpl.getConfiguration();
         }
         
-        @Override
-        public FeatureContext property(String name, Object value) {
-            return configImpl.property(name, value);
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls) {
-            return configImpl.register(cls);
-        }
-
-        @Override
-        public FeatureContext register(Object object) {
-            return configImpl.register(object);
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, int index) {
-            return configImpl.register(cls, index);
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, Class<?>... contracts) {
-            return configImpl.register(cls, contracts);
-        }
-
-        @Override
-        public FeatureContext register(Class<?> cls, Map<Class<?>, Integer>
map) {
-            return configImpl.register(cls, map);
-        }
-
-        @Override
-        public FeatureContext register(Object object, int index) {
-            return configImpl.register(object, index);
-        }
+    }
 
-        @Override
-        public FeatureContext register(Object object, Class<?>... contracts) {
-            return configImpl.register(object, contracts);
-        }
+    protected static boolean isPrematching(Class<?> filterCls) {
+        return AnnotationUtils.getClassAnnotation(filterCls, PreMatching.class) != null;
+    }
 
-        @Override
-        public FeatureContext register(Object object, Map<Class<?>, Integer>
map) {
-            return configImpl.register(object, map);
-        }
-        
-        FeatureContext doRegister(Object provider, Map<Class<?>, Integer> contracts)
{
         
-            Map<Class<?>, Integer> actualContracts = new HashMap<Class<?>,
Integer>();
-            
-            for (Class<?> contract : contracts.keySet()) {
-                if (SERVER_FILTER_INTERCEPTOR_CLASSES.contains(contract)
-                    && contract.isAssignableFrom(provider.getClass())) {
-                    actualContracts.put(contract, contracts.get(contract));
-                }
-            }
-            if (!actualContracts.isEmpty()) {
-                registerUserProvider(new FilterProviderInfo<Object>(provider, 
-                    getBus(),
-                    nameBinding,
-                    true,
-                    actualContracts));
-                ori.addNameBindings(Collections.singletonList(nameBinding));
-            }
-            return this;
-        }
-        
-    }
-    
     private static class MethodFeatureContextConfigurable extends ConfigurableImpl<FeatureContext>
{
-        protected MethodFeatureContextConfigurable(MethodFeatureContextImpl mc) {
+        protected MethodFeatureContextConfigurable(FeatureContext mc) {
             super(mc, RuntimeType.SERVER, SERVER_FILTER_INTERCEPTOR_CLASSES.toArray(new Class<?>[]{}));
         }
-        @Override
-        public FeatureContext register(Object provider, Map<Class<?>, Integer>
contracts) {
-            super.register(provider, contracts);
-            return ((MethodFeatureContextImpl)super.getConfigurable())
-                .doRegister(provider, contracts);
-        }
-        
     }
     
     public static void clearThreadLocalProxies(Message message) {


Mime
View raw message