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-6200] Support for registering providers as Classes in all the cases
Date Tue, 20 Jan 2015 12:15:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes cd0c70d49 -> ec9df9cd4


[CXF-6200] Support for registering providers as Classes in all the cases


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

Branch: refs/heads/3.0.x-fixes
Commit: ec9df9cd410d00640d8939077f80849727ae46f0
Parents: cd0c70d
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jan 20 12:13:10 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jan 20 12:14:47 2015 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 14 +++++++-----
 .../apache/cxf/jaxrs/utils/ResourceUtils.java   | 23 +++++++++++---------
 .../jaxrs/JAXRSClientServerBookTest.java        |  2 +-
 3 files changed, 23 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ec9df9cd/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 7500eca..72cff1c 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
@@ -1225,14 +1225,18 @@ public abstract class ProviderFactory {
             if (o == null) {
                 continue;
             }
-            if (o instanceof Constructor) {
+            Object provider = o;
+            if (provider.getClass() == Class.class) {
+                provider = ResourceUtils.createProviderInstance((Class<?>)provider);
+            }
+            if (provider instanceof Constructor) {
                 Map<Class<?>, Object> values = CastUtils.cast(application ==
null ? null 
                     : Collections.singletonMap(Application.class, application.getProvider()));
-                theProviders.add(createProviderFromConstructor((Constructor<?>)o, values,
getBus(), true));
-            } else if (o instanceof ProviderInfo) {
-                theProviders.add((ProviderInfo<?>)o);
+                theProviders.add(createProviderFromConstructor((Constructor<?>)provider,
values, getBus(), true));
+            } else if (provider instanceof ProviderInfo) {
+                theProviders.add((ProviderInfo<?>)provider);
             } else {    
-                theProviders.add(new ProviderInfo<Object>(o, getBus()));
+                theProviders.add(new ProviderInfo<Object>(provider, getBus()));
             }
         }
         return theProviders;

http://git-wip-us.apache.org/repos/asf/cxf/blob/ec9df9cd/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index 0cc88a0..8555fa9 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -753,16 +753,7 @@ public final class ResourceUtils {
         for (Class<?> cls : app.getClasses()) {
             if (isValidApplicationClass(cls, singletons)) {
                 if (isValidProvider(cls)) {
-                    try {
-                        Constructor<?> c = ResourceUtils.findResourceConstructor(cls,
false);
-                        if (c.getParameterTypes().length == 0) {
-                            providers.add(c.newInstance());
-                        } else {
-                            providers.add(c);
-                        }
-                    } catch (Throwable ex) {
-                        throw new RuntimeException("Provider " + cls.getName() + " can not
be created", ex); 
-                    }
+                    providers.add(createProviderInstance(cls));
                 } else {
                     resourceClasses.add(cls);
                     map.put(cls, new PerRequestResourceProvider(cls));
@@ -806,6 +797,18 @@ public final class ResourceUtils {
         
         return bean;
     }
+    public static Object createProviderInstance(Class<?> cls) {
+        try {
+            Constructor<?> c = ResourceUtils.findResourceConstructor(cls, false);
+            if (c.getParameterTypes().length == 0) {
+                return c.newInstance();
+            } else {
+                return c;
+            }
+        } catch (Throwable ex) {
+            throw new RuntimeException("Provider " + cls.getName() + " can not be created",
ex); 
+        }
+    }
     
     private static boolean isValidProvider(Class<?> c) {
         if (c == null || c == Object.class) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/ec9df9cd/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index b3fd6c0..6bc712e 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -770,7 +770,7 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     public void testBookWithMultipleExceptions2() throws Exception {
         List<Object> providers = new LinkedList<Object>();
         providers.add(new NotReturnedExceptionMapper());
-        providers.add(new NotFoundExceptionMapper());
+        providers.add(NotFoundExceptionMapper.class);
         BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, 
                                                     BookStore.class,
                                                     providers);


Mime
View raw message