You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/12/03 18:03:06 UTC

cxf git commit: [CXF-6121] Optimizing a bit SpringResourceFactory

Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes ea800588a -> 1cdac9254


[CXF-6121] Optimizing a bit SpringResourceFactory


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

Branch: refs/heads/3.0.x-fixes
Commit: 1cdac92540d5df49edf92876150fcb5bf873f49a
Parents: ea80058
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Dec 3 17:01:00 2014 +0000
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Dec 3 17:02:41 2014 +0000

----------------------------------------------------------------------
 .../cxf/jaxrs/spring/SpringResourceFactory.java | 28 ++++++++++++++------
 1 file changed, 20 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/1cdac925/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
index 99f496c..826f619 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/SpringResourceFactory.java
@@ -54,6 +54,7 @@ public class SpringResourceFactory implements ResourceProvider, ApplicationConte
     private boolean callPreDestroy = true;
     private String postConstructMethodName;
     private String preDestroyMethodName;
+    private Object singletonInstance; 
     
     public SpringResourceFactory() {
         
@@ -78,21 +79,32 @@ public class SpringResourceFactory implements ResourceProvider, ApplicationConte
         isSingleton = ac.isSingleton(beanId);
         if (!isSingleton) {
             isPrototype = ac.isPrototype(beanId);
+        } else {
+            try {
+                singletonInstance = ac.getBean(beanId);
+            } catch (BeansException ex) {
+                // ignore for now, can be to do with no default constructor available
+            }
         }
+        
     }
     
     /**
      * {@inheritDoc}
      */
     public Object getInstance(Message m) {
-        ProviderInfo<?> application = m == null ? null
-            : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName());
-        Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null 
-            : Collections.singletonMap(Application.class, application.getProvider()));
-        Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues);
-        Object instance = values.length > 0 ? ac.getBean(beanId, values) : ac.getBean(beanId);
-        initInstance(m, instance);
-        return instance;
+        if (singletonInstance != null) {
+            return singletonInstance;
+        } else {
+            ProviderInfo<?> application = m == null ? null
+                : (ProviderInfo<?>)m.getExchange().getEndpoint().get(Application.class.getName());
+            Map<Class<?>, Object> mapValues = CastUtils.cast(application == null ? null 
+                : Collections.singletonMap(Application.class, application.getProvider()));
+            Object[] values = ResourceUtils.createConstructorArguments(c, m, !isSingleton(), mapValues);
+            Object instance = values.length > 0 ? ac.getBean(beanId, values) : ac.getBean(beanId);
+            initInstance(m, instance);
+            return instance;
+        }
     }
 
     protected void initInstance(Message m, Object instance) {