cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1564750 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: model/AbstractResourceInfo.java model/ProviderInfo.java utils/InjectionUtils.java
Date Wed, 05 Feb 2014 12:46:53 GMT
Author: sergeyb
Date: Wed Feb  5 12:46:53 2014
New Revision: 1564750

URL: http://svn.apache.org/r1564750
Log:
[CXF-5542] Adding the changes to the JAXRS frontend

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=1564750&r1=1564749&r2=1564750&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Wed Feb  5 12:46:53 2014
@@ -58,7 +58,7 @@ public abstract class AbstractResourceIn
 
     protected AbstractResourceInfo(Class<?> resourceClass, Class<?> serviceClass,

                                    boolean isRoot, boolean checkContexts, Bus bus) {
-        this(resourceClass, serviceClass, isRoot, checkContexts, null, bus);
+        this(resourceClass, serviceClass, isRoot, checkContexts, null, bus, null);
     }
     
     protected AbstractResourceInfo(Class<?> resourceClass, 
@@ -66,18 +66,20 @@ public abstract class AbstractResourceIn
                                    boolean isRoot, 
                                    boolean checkContexts,
                                    Map<Class<?>, ThreadLocalProxy<?>> constructorProxies,
-                                   Bus bus) {
+                                   Bus bus,
+                                   Object provider) {
         this.bus = bus;
         this.serviceClass = serviceClass;
         this.resourceClass = resourceClass;
         root = isRoot;
         if (checkContexts && resourceClass != null) {
-            findContexts(serviceClass, constructorProxies);
+            findContexts(serviceClass, provider, constructorProxies);
         }
     }
     
-    private void findContexts(Class<?> cls, Map<Class<?>, ThreadLocalProxy<?>>
constructorProxies) {
-        findContextFields(cls);
+    private void findContexts(Class<?> cls, Object provider, 
+                              Map<Class<?>, ThreadLocalProxy<?>> constructorProxies)
{
+        findContextFields(cls, provider);
         findContextSetterMethods(cls);
         if (constructorProxies != null) {
             Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>>
proxies = getConstructorProxyMap(true);
@@ -102,7 +104,7 @@ public abstract class AbstractResourceIn
     public void setResourceClass(Class<?> rClass) {
         resourceClass = rClass;
         if (serviceClass.isInterface() && resourceClass != null && !resourceClass.isInterface())
{
-            findContexts(resourceClass, null);
+            findContexts(resourceClass, null, null);
         }
     }
     
@@ -110,7 +112,7 @@ public abstract class AbstractResourceIn
         return serviceClass;
     }
     
-    private void findContextFields(Class<?> cls) {
+    private void findContextFields(Class<?> cls, Object provider) {
         if (cls == Object.class || cls == null) {
             return;
         }
@@ -119,12 +121,28 @@ public abstract class AbstractResourceIn
                 if (a.annotationType() == Context.class) {
                     contextFields = addContextField(contextFields, f);
                     if (f.getType() != Application.class) {
-                        addToMap(getFieldProxyMap(true), f, InjectionUtils.createThreadLocalProxy(f.getType()));
+                        addToMap(getFieldProxyMap(true), f, getFieldThreadLocalProxy(f, provider));
                     }
                 }
             }
         }
-        findContextFields(cls.getSuperclass());
+        findContextFields(cls.getSuperclass(), provider);
+    }
+    
+    private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider)
{
+        if (provider != null) {
+            synchronized (provider) {
+                try {
+                    Object proxy = InjectionUtils.extractFieldValue(f, provider);
+                    if (proxy instanceof ThreadLocalProxy) {
+                        return (ThreadLocalProxy<?>)proxy;
+                    }
+                } catch (Throwable t) {
+                    // continue
+                }
+            }
+        }
+        return InjectionUtils.createThreadLocalProxy(f.getType());
     }
     
     @SuppressWarnings("unchecked")

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java?rev=1564750&r1=1564749&r2=1564750&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ProviderInfo.java
Wed Feb  5 12:46:53 2014
@@ -35,7 +35,7 @@ public class ProviderInfo<T> extends Abs
     public ProviderInfo(T provider, 
                         Map<Class<?>, ThreadLocalProxy<?>> constructorProxies,

                         Bus bus) {
-        super(provider.getClass(), provider.getClass(), true, true, constructorProxies, bus);
+        super(provider.getClass(), provider.getClass(), true, true, constructorProxies, bus,
provider);
         this.provider = provider;
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1564750&r1=1564749&r2=1564750&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Feb  5 12:46:53 2014
@@ -987,6 +987,15 @@ public final class InjectionUtils {
         
         for (Field f : cri.getContextFields()) {
             Object value = f.getType() == Application.class ? app : cri.getContextFieldProxy(f);
+            try {
+                synchronized (instance) {
+                    if (value == InjectionUtils.extractFieldValue(f, instance)) {
+                        continue;
+                    }
+                }
+            } catch (Throwable t) {
+                // continue
+            }
             InjectionUtils.injectFieldValue(f, instance, value);
         }
     }



Mime
View raw message