cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5861] Injecting context values immediately after ResourceContext creates a bean
Date Tue, 08 Jul 2014 15:38:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 84c1a74ec -> d044e1c0e


[CXF-5861] Injecting context values immediately after ResourceContext creates a bean


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

Branch: refs/heads/master
Commit: d044e1c0e6d8c81ff38f2f3705e1ec7b02d440c1
Parents: 84c1a74
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jul 8 16:38:05 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jul 8 16:38:05 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/cxf/jaxrs/JAXRSInvoker.java | 13 +---------
 .../cxf/jaxrs/impl/ResourceContextImpl.java     |  1 +
 .../cxf/jaxrs/model/ClassResourceInfo.java      | 27 ++++++++++++++++++++
 .../org/apache/cxf/systest/jaxrs/Book2.java     |  4 +++
 .../org/apache/cxf/systest/jaxrs/BookStore.java |  4 ++-
 5 files changed, 36 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d044e1c0/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
index 67d980e..135ac8d 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
@@ -155,19 +155,8 @@ public class JAXRSInvoker extends AbstractInvoker {
         final ClassResourceInfo cri = ori.getClassResourceInfo();
         final Message inMessage = exchange.getInMessage();
         final ServerProviderFactory providerFactory = ServerProviderFactory.getInstance(inMessage);
-
-        final boolean contextsAvailable = cri.contextsAvailable();
-        final boolean paramsAvailable = cri.paramsAvailable();
-        if (contextsAvailable || paramsAvailable) {
-            Object realResourceObject = ClassHelper.getRealObject(resourceObject);
-            if (paramsAvailable) {
-                JAXRSUtils.injectParameters(ori, realResourceObject, inMessage);
-            }
-            if (contextsAvailable) {
-                InjectionUtils.injectContexts(realResourceObject, cri, inMessage);
-            }
-        }
         if (cri.isRoot()) {
+            cri.injectContexts(resourceObject, ori, inMessage);
             ProviderInfo<Application> appProvider = providerFactory.getApplicationProvider();
             if (appProvider != null) {
                 InjectionUtils.injectContexts(appProvider.getProvider(),

http://git-wip-us.apache.org/repos/asf/cxf/blob/d044e1c0/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
index c8870f5..60b70aa 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
@@ -50,6 +50,7 @@ public class ResourceContextImpl implements ResourceContext {
     private <T> T doInitResource(Class<?> cls, T resource) {
         ClassResourceInfo sub = cri.getSubResource(subClass, cls, resource, true, m);
         sub.initBeanParamInfo(ServerProviderFactory.getInstance(m));
+        sub.injectContexts(resource, m.getExchange().get(OperationResourceInfo.class), m);
         return resource;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/d044e1c0/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
index 2cbe7e6..67959d2 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
@@ -37,6 +37,7 @@ import javax.ws.rs.core.MediaType;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -322,4 +323,30 @@ public class ClassResourceInfo extends BeanResourceInfo {
             }
         }
     }
+    
+    @Override
+    public void clearThreadLocalProxies() {
+        super.clearThreadLocalProxies();
+        if (!injectedSubInstances.isEmpty()) {
+            for (ClassResourceInfo sub : subResources.values()) {
+                if (sub != this) {
+                    sub.clearThreadLocalProxies();
+                }
+            }
+        }
+    }
+    
+    public void injectContexts(Object resourceObject, OperationResourceInfo ori, Message
inMessage) {
+        final boolean contextsAvailable = contextsAvailable();
+        final boolean paramsAvailable = paramsAvailable();
+        if (contextsAvailable || paramsAvailable) {
+            Object realResourceObject = ClassHelper.getRealObject(resourceObject);
+            if (paramsAvailable) {
+                JAXRSUtils.injectParameters(ori, this, realResourceObject, inMessage);
+            }
+            if (contextsAvailable) {
+                InjectionUtils.injectContexts(realResourceObject, this, inMessage);
+            }
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/d044e1c0/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
index 3b77a5e..74e1050 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
@@ -85,6 +85,10 @@ public class Book2 {
         return this;
     }
     
+    public void checkContext() {
+        uriInfo.getQueryParameters();
+    }
+    
     @GET
     @Path("rc/bean")
     @Produces("application/xml")

http://git-wip-us.apache.org/repos/asf/cxf/blob/d044e1c0/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index af4bdc6..c724269 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -1132,7 +1132,9 @@ public class BookStore {
     
     @Path("/booksubresource/context")
     public Book2 getBookSubResourceRC() {
-        return resourceContext.getResource(Book2.class);
+        Book2 book = resourceContext.getResource(Book2.class);
+        book.checkContext();
+        return book;
     }
     
     @Path("/booksubresource/instance/context")


Mime
View raw message