cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1564860 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Date Wed, 05 Feb 2014 18:18:56 GMT
Author: sergeyb
Date: Wed Feb  5 18:18:55 2014
New Revision: 1564860

URL: http://svn.apache.org/r1564860
Log:
Merged revisions 1564840 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1564840 | sergeyb | 2014-02-05 17:21:57 +0000 (Wed, 05 Feb 2014) | 1 line
  
  [CXF-5542] Injecting TL contexts immediately, with the optimizations to follow
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1564840

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=1564860&r1=1564859&r2=1564860&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Wed Feb  5 18:18:55 2014
@@ -79,7 +79,7 @@ public abstract class AbstractResourceIn
     }
     private void findContexts(Class<?> cls, Object provider) {
         findContextFields(cls, provider);
-        findContextSetterMethods(cls);
+        findContextSetterMethods(cls, provider);
         contextsAvailable = contextFields != null && !contextFields.isEmpty() 
             || contextMethods != null && !contextMethods.isEmpty();
     }
@@ -122,19 +122,46 @@ public abstract class AbstractResourceIn
     }
     
     private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider)
{
+        ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(f.getType());

         if (provider != null) {
+            Object proxy = null;
             synchronized (provider) {
                 try {
-                    Object proxy = InjectionUtils.extractFieldValue(f, provider);
-                    if (proxy instanceof ThreadLocalProxy) {
-                        return (ThreadLocalProxy<?>)proxy;
-                    }
+                    proxy = InjectionUtils.extractFieldValue(f, provider);
                 } catch (Throwable t) {
                     // continue
                 }
+                if (!(proxy instanceof ThreadLocalProxy)) {
+                    proxy = defaultValue;
+                    InjectionUtils.injectFieldValue(f, provider, proxy);
+                }
             }
+            return (ThreadLocalProxy<?>)proxy;
+        } else {
+            return defaultValue;
+        }
+    }
+    
+    private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider)
{
+        ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);

+        if (provider != null) {
+            Object proxy = null;
+            synchronized (provider) {
+                try {
+                    Method getter = m.getClass().getMethod("get" + m.getName().substring(3),
new Class[]{});
+                    proxy = InjectionUtils.extractFromMethod(provider, getter);
+                } catch (Throwable t) {
+                    // continue
+                }
+                if (!(proxy instanceof ThreadLocalProxy)) {
+                    proxy = defaultValue;
+                    InjectionUtils.injectThroughMethod(provider, m, proxy);
+                }
+            }
+            return (ThreadLocalProxy<?>)proxy;
+        } else {
+            return defaultValue;
         }
-        return InjectionUtils.createThreadLocalProxy(f.getType());
     }
     
     @SuppressWarnings("unchecked")
@@ -157,7 +184,7 @@ public abstract class AbstractResourceIn
         return getProxyMap(Method.class, SETTER_PROXY_MAP);
     }
     
-    private void findContextSetterMethods(Class<?> cls) {
+    private void findContextSetterMethods(Class<?> cls, Object provider) {
         
         for (Method m : cls.getMethods()) {
         
@@ -166,25 +193,25 @@ public abstract class AbstractResourceIn
             }
             for (Annotation a : m.getAnnotations()) {
                 if (a.annotationType() == Context.class) {
-                    checkContextMethod(m);
+                    checkContextMethod(m, provider);
                     break;
                 }
             }
         }
         Class<?>[] interfaces = cls.getInterfaces();
         for (Class<?> i : interfaces) {
-            findContextSetterMethods(i);
+            findContextSetterMethods(i, provider);
         }
         Class<?> superCls = cls.getSuperclass();
         if (superCls != null && superCls != Object.class) {
-            findContextSetterMethods(superCls);
+            findContextSetterMethods(superCls, provider);
         }
     }
     
-    private void checkContextMethod(Method m) {
+    private void checkContextMethod(Method m, Object provider) {
         Class<?> type = m.getParameterTypes()[0];
         if (m.getName().equals("set" + type.getSimpleName())) {        
-            addContextMethod(type, m);
+            addContextMethod(type, m, provider);
         }
     }
     
@@ -195,14 +222,13 @@ public abstract class AbstractResourceIn
                                       : Collections.unmodifiableMap(methods);
     }
     
-    private void addContextMethod(Class<?> contextClass, Method m) {
+    private void addContextMethod(Class<?> contextClass, Method m, Object provider)
{
         if (contextMethods == null) {
             contextMethods = new HashMap<Class<?>, Map<Class<?>, Method>>();
         }
         addToMap(contextMethods, contextClass, m);
         if (m.getParameterTypes()[0] != Application.class) {
-            addToMap(getSetterProxyMap(), m, 
-                     InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]));
+            addToMap(getSetterProxyMap(), m, getMethodThreadLocalProxy(m, provider));
         }
     }
     

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1564860&r1=1564859&r2=1564860&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Feb  5 18:18:55 2014
@@ -991,6 +991,15 @@ public final class InjectionUtils {
             Method method = entry.getValue();
             Object value = method.getParameterTypes()[0] == Application.class 
                 ? app : cri.getContextSetterProxy(method);
+            try {
+                synchronized (instance) {
+                    if (value == InjectionUtils.extractFromMethod(instance, method)) {
+                        continue;
+                    }
+                }
+            } catch (Throwable t) {
+                // continue
+            }
             InjectionUtils.injectThroughMethod(instance, method, value);
         }
         



Mime
View raw message