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-6851] Support for registering JAX-RS Feature on the server
Date Thu, 05 May 2016 21:58:12 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5e193bf8a -> b97598447


[CXF-6851] Support for registering JAX-RS Feature on the server


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

Branch: refs/heads/master
Commit: b97598447f52f1ae627ae2b06c98d2dd99abf539
Parents: 5e193bf
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu May 5 22:57:51 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu May 5 22:57:51 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/provider/ServerProviderFactory.java   | 44 +++++++++++++++-----
 .../apache/cxf/systest/jaxrs/BookServer20.java  | 12 +++++-
 2 files changed, 44 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/b9759844/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 cdcd531..3d7d966 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,7 +39,6 @@ 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;
@@ -206,13 +205,36 @@ public final class ServerProviderFactory extends ProviderFactory {
     @SuppressWarnings("unchecked")
     @Override
     protected void setProviders(boolean custom, boolean busGlobal, Object... providers) {
+        List<Object> allProviders = new LinkedList<Object>();
+        for (Object p : providers) {
+            if (p instanceof Feature) {
+                FeatureContext featureContext = createServerFeatureContext();
+                ((Feature)p).configure(featureContext);
+                Configuration cfg = featureContext.getConfiguration();
+                
+                for (Object featureProvider : cfg.getInstances()) {
+                    Map<Class<?>, Integer> contracts = cfg.getContracts(featureProvider.getClass());
+                    if (contracts != null && !contracts.isEmpty()) {
+                        allProviders.add(new FilterProviderInfo<Object>(featureProvider,

+                                                                        getBus(),
+                                                                        contracts));
+                    } else {
+                        allProviders.add(featureProvider);
+                    }
+                }
+            } else {
+                allProviders.add(p);
+            }
+        }
+        
+        
         List<ProviderInfo<ContainerRequestFilter>> postMatchRequestFilters =

             new LinkedList<ProviderInfo<ContainerRequestFilter>>();
         List<ProviderInfo<ContainerResponseFilter>> postMatchResponseFilters
= 
             new LinkedList<ProviderInfo<ContainerResponseFilter>>();
         
         List<ProviderInfo<? extends Object>> theProviders = 
-            prepareProviders(custom, busGlobal, (Object[])providers, application);
+            prepareProviders(custom, busGlobal, allProviders.toArray(), application);
         super.setCommonProviders(theProviders);
         for (ProviderInfo<? extends Object> provider : theProviders) {
             Class<?> providerCls = ClassHelper.getRealClass(getBus(), provider.getProvider());
@@ -350,11 +372,7 @@ public final class ServerProviderFactory extends ProviderFactory {
                 + "."
                 + ori.getMethodToInvoke().toString();
             for (DynamicFeature feature : dynamicFeatures) {
-                FeatureContextImpl featureContext = new FeatureContextImpl();
-                MethodFeatureContextConfigurable configImpl = new MethodFeatureContextConfigurable(featureContext);
-                setApplicationProperties(configImpl);
-                featureContext.setConfigurable(configImpl);
-                
+                FeatureContext featureContext = createServerFeatureContext();
                 feature.configure(new ResourceInfoImpl(ori), featureContext);
                 Configuration cfg = featureContext.getConfiguration();
                 for (Object provider : cfg.getInstances()) {
@@ -378,22 +396,26 @@ public final class ServerProviderFactory extends ProviderFactory {
         }
     }
     
-    private void setApplicationProperties(Configurable<?> configImpl) {
+    private FeatureContext createServerFeatureContext() {
+        FeatureContextImpl featureContext = new FeatureContextImpl();
+        ServerFeatureContextConfigurable configImpl = new ServerFeatureContextConfigurable(featureContext);
+        featureContext.setConfigurable(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());
             }
         }
-        
+        return featureContext;
     }
 
     protected static boolean isPrematching(Class<?> filterCls) {
         return AnnotationUtils.getClassAnnotation(filterCls, PreMatching.class) != null;
     }
         
-    private static class MethodFeatureContextConfigurable extends ConfigurableImpl<FeatureContext>
{
-        protected MethodFeatureContextConfigurable(FeatureContext mc) {
+    private static class ServerFeatureContextConfigurable extends ConfigurableImpl<FeatureContext>
{
+        protected ServerFeatureContextConfigurable(FeatureContext mc) {
             super(mc, RuntimeType.SERVER, SERVER_FILTER_INTERCEPTOR_CLASSES.toArray(new Class<?>[]{}));
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/b9759844/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
index 17e8f60..be58f50 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer20.java
@@ -49,6 +49,7 @@ import javax.ws.rs.container.DynamicFeature;
 import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.container.ResourceInfo;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.FeatureContext;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -96,7 +97,7 @@ public class BookServer20 extends AbstractBusTestServerBase {
         providers.add(new PostMatchContainerRequestFilter());
         providers.add(new FaultyContainerRequestFilter());
         providers.add(new PreMatchReplaceStreamOrAddress());
-        providers.add(new GenericHandlerWriter());
+        providers.add(new ServerTestFeature());
         providers.add(new JacksonJaxbJsonProvider());
         sf.setProviders(providers);
         sf.setResourceProvider(BookStore.class,
@@ -508,4 +509,13 @@ public class BookServer20 extends AbstractBusTestServerBase {
         }
         
     }
+    private static class ServerTestFeature implements Feature {
+
+        @Override
+        public boolean configure(FeatureContext context) {
+            context.register(new GenericHandlerWriter());
+            return true;
+        }
+        
+    }
 }


Mime
View raw message