cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1478348 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: impl/ResourceContextImpl.java model/ClassResourceInfo.java utils/JAXRSUtils.java
Date Thu, 02 May 2013 12:39:01 GMT
Author: sergeyb
Date: Thu May  2 12:39:01 2013
New Revision: 1478348

URL: http://svn.apache.org/r1478348
Log:
[CXF-4988] Also making sure subresources instantiated via ResourceContext can get Application
injection working

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java?rev=1478348&r1=1478347&r2=1478348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
Thu May  2 12:39:01 2013
@@ -18,30 +18,27 @@
  */
 package org.apache.cxf.jaxrs.impl;
 
-import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.container.ResourceContext;
 
+import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Message;
 
 public class ResourceContextImpl implements ResourceContext {
 
     private ClassResourceInfo cri;
     private Class<?> subClass;
-    
-    public ResourceContextImpl(OperationResourceInfo ori) {
+    private Message m;
+    public ResourceContextImpl(Message m, OperationResourceInfo ori) {
+        this.m = m;
         this.cri = ori.getClassResourceInfo();
         this.subClass = ori.getMethodToInvoke().getReturnType();
     }
     
     @Override
     public <T> T getResource(Class<T> cls) {
-        T resource = null;
-        try {
-            resource = cls.newInstance();
-        } catch (Throwable ex) {
-            throw new InternalServerErrorException(ex);
-        }
+        T resource = cls.cast(new PerRequestResourceProvider(cls).getInstance(m));
         return doInitResource(cls, resource);
     }
     
@@ -50,7 +47,7 @@ public class ResourceContextImpl impleme
     }
 
     private <T> T doInitResource(Class<?> cls, T resource) {
-        cri.getSubResource(subClass, cls, resource, true);
+        cri.getSubResource(subClass, cls, resource, true, m);
         return resource;
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1478348&r1=1478347&r2=1478348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Thu May  2 12:39:01 2013
@@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHa
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 
 import org.apache.cxf.Bus;
@@ -38,6 +39,7 @@ import org.apache.cxf.jaxrs.utils.Annota
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
+import org.apache.cxf.message.Message;
 
 public class ClassResourceInfo extends BeanResourceInfo {
     
@@ -130,18 +132,19 @@ public class ClassResourceInfo extends B
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass)
{
         instanceClass = enableStatic ? typedClass : instanceClass;
-        return getSubResource(typedClass, instanceClass, null, enableStatic);
+        return getSubResource(typedClass, instanceClass, null, enableStatic, null);
     }
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, Class<?> instanceClass,
Object instance) {
         instanceClass = enableStatic ? typedClass : instanceClass;
-        return getSubResource(typedClass, instanceClass, instance, enableStatic);
+        return getSubResource(typedClass, instanceClass, instance, enableStatic, null);
     }
     
     public ClassResourceInfo getSubResource(Class<?> typedClass, 
                                             Class<?> instanceClass,
                                             Object instance,
-                                            boolean resolveContexts) {
+                                            boolean resolveContexts,
+                                            Message message) {
         
         SubresourceKey key = new SubresourceKey(typedClass, instanceClass);
         ClassResourceInfo cri = subResources.get(key);
@@ -159,7 +162,15 @@ public class ClassResourceInfo extends B
         if (resolveContexts && cri != null && cri.isSingleton() &&
instance != null && cri.contextsAvailable()) {
             synchronized (this) {
                 if (!injectedSubInstances.contains(instance.toString())) {
-                    InjectionUtils.injectContextProxies(cri, instance);
+                    Application app = null;
+                    if (message != null) {
+                        ProviderInfo<?> appProvider = 
+                            (ProviderInfo<?>)message.getExchange().getEndpoint().get(Application.class.getName());
+                        if (appProvider != null) {
+                            app = (Application)appProvider.getProvider();
+                        }
+                    }
+                    InjectionUtils.injectContextProxiesAndApplication(cri, instance, app);
                     injectedSubInstances.add(instance.toString());
                 }
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1478348&r1=1478347&r2=1478348&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Thu
May  2 12:39:01 2013
@@ -1080,7 +1080,7 @@ public final class JAXRSUtils {
         } else if (ResourceInfo.class.isAssignableFrom(clazz)) {
             o = new ResourceInfoImpl(contextMessage);
         } else if (ResourceContext.class.isAssignableFrom(clazz)) {
-            o = new ResourceContextImpl(contextMessage.getExchange().get(OperationResourceInfo.class));
+            o = new ResourceContextImpl(contextMessage, contextMessage.getExchange().get(OperationResourceInfo.class));
         } else if (Request.class.isAssignableFrom(clazz)) {
             o = new RequestImpl(contextMessage);
         } else if (Providers.class.isAssignableFrom(clazz)) {



Mime
View raw message