cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [cxf] branch master updated: [CXF-7549] Feature from feature registration support, initial tests provided by Carlos Sierra
Date Tue, 07 Nov 2017 16:08:36 GMT
This is an automated email from the ASF dual-hosted git repository.

sergeyb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 9235cc5  [CXF-7549] Feature from feature registration support, initial tests provided
by Carlos Sierra
9235cc5 is described below

commit 9235cc51eccf1048dc80358dca6b9ea6dcd00ce9
Author: Sergey Beryozkin <sberyozkin@gmail.com>
AuthorDate: Tue Nov 7 16:08:24 2017 +0000

    [CXF-7549] Feature from feature registration support, initial tests provided by Carlos
Sierra
---
 .../apache/cxf/jaxrs/impl/ConfigurableImpl.java    | 24 +++++++++--------
 .../apache/cxf/jaxrs/impl/ConfigurationImpl.java   |  6 ++++-
 .../cxf/jaxrs/provider/ProviderFactoryTest.java    | 30 ++++++++++++++++++++++
 3 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
index 5454027..200a597 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
@@ -85,15 +85,7 @@ public class ConfigurableImpl<C extends Configurable<C>> implements
Configurable
 
     @Override
     public C register(Object provider, Map<Class<?>, Integer> contracts) {
-        if (provider instanceof Feature) {
-            Feature feature = (Feature)provider;
-            boolean enabled = feature.configure(new FeatureContextImpl(this));
-            config.setFeature(feature, enabled);
-
-            return configurable;
-        }
-        config.register(provider, contracts);
-        return configurable;
+        return doRegister(provider, contracts);
     }
 
     @Override
@@ -121,6 +113,18 @@ public class ConfigurableImpl<C extends Configurable<C>>
implements Configurable
     }
 
     private C doRegister(Object provider, int bindingPriority, Class<?>... contracts)
{
-        return register(provider, ConfigurationImpl.initContractsMap(bindingPriority, contracts));
+        return doRegister(provider, ConfigurationImpl.initContractsMap(bindingPriority, contracts));
+    }
+    
+    private C doRegister(Object provider, Map<Class<?>, Integer> contracts) {
+        if (provider instanceof Feature) {
+            Feature feature = (Feature)provider;
+            boolean enabled = feature.configure(new FeatureContextImpl(this));
+            config.setFeature(feature, enabled);
+
+            return configurable;
+        }
+        config.register(provider, contracts);
+        return configurable;    
     }
 }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
index d27e136..271fdec 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
@@ -91,7 +91,11 @@ public class ConfigurationImpl implements Configuration {
     public Map<Class<?>, Integer> getContracts(Class<?> cls) {
         for (Object o : getInstances()) {
             if (cls.isAssignableFrom(o.getClass())) {
-                return Collections.unmodifiableMap(providers.get(o));
+                if (o instanceof Feature) {
+                    return Collections.emptyMap();
+                } else {
+                    return providers.get(o);
+                }
             }
         }
         return Collections.emptyMap();
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
index 8f9a89f..de657c0 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
@@ -38,6 +38,7 @@ import javax.ws.rs.Consumes;
 import javax.ws.rs.Priorities;
 import javax.ws.rs.Produces;
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -91,6 +92,35 @@ public class ProviderFactoryTest extends Assert {
     }
 
     @Test
+    public void testRegisterInFeature() {
+        ServerProviderFactory pf = ServerProviderFactory.getInstance();
+        final Object provider = new WebApplicationExceptionMapper();
+        pf.registerUserProvider((Feature)(context) -> {
+            context.register(provider);
+            return true;
+        });
+        ExceptionMapper<WebApplicationException> em =
+            pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
+        assertSame(provider, em);
+    }
+    
+    @Test
+    public void testRegisterFeatureInFeature() {
+        ServerProviderFactory pf = ServerProviderFactory.getInstance();
+        final Object provider = new WebApplicationExceptionMapper();
+        pf.registerUserProvider((Feature)(context) -> {
+            context.register((Feature) context2-> {
+                context2.register(provider);
+                return true;
+            });
+            return true;
+        });
+        ExceptionMapper<WebApplicationException> em =
+            pf.createExceptionMapper(WebApplicationException.class, new MessageImpl());
+        assertSame(provider, em);
+    }
+    
+    @Test
     public void testOrderOfProvidersWithSameProperties() {
         ProviderFactory pf = ServerProviderFactory.getInstance();
         WildcardReader reader1 = new WildcardReader();

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <commits@cxf.apache.org>'].

Mime
View raw message