This is an automated email from the ASF dual-hosted git repository.
sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
new 24be709 [CXF-7549] Feature from feature registration support, initial
tests provided by Carlos Sierra
24be709 is described below
commit 24be70913e6202a39d5e5ed588dfeacc50a73aca
Author: Sergey Beryozkin <[email protected]>
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 | 37 ++++++++++++++++++++++
3 files changed, 56 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 489aae9..0bc33e3 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
@@ -92,15 +92,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 doRegisterProvider(provider, contracts);
}
@Override
@@ -128,6 +120,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 doRegisterProvider(provider,
ConfigurationImpl.initContractsMap(bindingPriority, contracts));
+ }
+
+ private C doRegisterProvider(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 c412dde..aed4198 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 8da87d5..f0fef24 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
@@ -36,6 +36,8 @@ import javax.activation.DataSource;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -89,6 +91,41 @@ public class ProviderFactoryTest extends Assert {
}
@Test
+ public void testRegisterInFeature() {
+ ServerProviderFactory pf = ServerProviderFactory.getInstance();
+ final Object provider = new WebApplicationExceptionMapper();
+ pf.registerUserProvider(new Feature() {
+ public boolean configure(FeatureContext 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(new Feature() {
+ public boolean configure(FeatureContext context) {
+ context.register(new Feature() {
+ public boolean configure(FeatureContext 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
['"[email protected]" <[email protected]>'].