cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1084970 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/s...
Date Thu, 24 Mar 2011 14:39:03 GMT
Author: sergeyb
Date: Thu Mar 24 14:39:03 2011
New Revision: 1084970

URL: http://svn.apache.org/viewvc?rev=1084970&view=rev
Log:
Merged revisions 1084966 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1084966 | sergeyb | 2011-03-24 14:27:25 +0000 (Thu, 24 Mar 2011) | 1 line
  
  [CXF-3417] Injection of contexts into Applications
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerApplication.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1084966

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Thu Mar 24 14:39:03 2011
@@ -28,6 +28,7 @@ import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -46,6 +47,7 @@ import org.apache.cxf.jaxrs.model.Operat
 import org.apache.cxf.jaxrs.model.OperationResourceInfoStack;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -121,15 +123,21 @@ public class JAXRSInvoker extends Abstra
                     
             if (cri.isRoot()) {
                 Object realResourceObject = ClassHelper.getRealObject(resourceObject);
-                JAXRSUtils.handleSetters(ori, realResourceObject,
+                JAXRSUtils.injectParameters(ori, realResourceObject,
                                          exchange.getInMessage());
     
-                InjectionUtils.injectContextFields(realResourceObject,
-                                                   ori.getClassResourceInfo(),
-                                                   exchange.getInMessage());
-                InjectionUtils.injectResourceFields(realResourceObject,
-                                                ori.getClassResourceInfo(),
-                                                exchange.getInMessage());
+                InjectionUtils.injectContexts(realResourceObject,
+                                              ori.getClassResourceInfo(),
+                                              exchange.getInMessage());
+                
+                ProviderInfo<?> appProvider = 
+                    (ProviderInfo)exchange.getEndpoint().get(Application.class.getName());
+                if (appProvider != null) {
+                    InjectionUtils.injectContexts(appProvider.getProvider(),
+                                                  appProvider,
+                                                  exchange.getInMessage());
+                }
+                
             }
         }
         

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Thu Mar 24 14:39:03 2011
@@ -39,6 +39,7 @@ import org.apache.cxf.jaxrs.impl.Request
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.service.factory.FactoryBeanListener;
@@ -66,7 +67,7 @@ public class JAXRSServerFactoryBean exte
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
     private ResourceComparator rc;
-    private Application application;
+    private ProviderInfo<Application> appProvider;
     
     public JAXRSServerFactoryBean() {
         this(new JAXRSServiceFactoryBean());
@@ -81,7 +82,7 @@ public class JAXRSServerFactoryBean exte
      * @param app
      */
     public void setApplication(Application app) {
-        application = app;    
+        appProvider = new ProviderInfo<Application>(app);    
     }
     
     /**
@@ -132,8 +133,10 @@ public class JAXRSServerFactoryBean exte
                 ep.getService().setInvoker(invoker);
             }
             
-            ep.put(Application.class.getName(), application);
             ProviderFactory factory = setupFactory(ep);
+            ep.put(Application.class.getName(), appProvider);
+            factory.setApplicationProvider(appProvider);
+            
             factory.setRequestPreprocessor(
                 new RequestPreprocessor(languageMappings, extensionMappings));
             if (rc != null) {
@@ -315,6 +318,7 @@ public class JAXRSServerFactoryBean exte
     }
 
     private void injectContexts() {
+        Application application = appProvider == null ? null : appProvider.getProvider();
         for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
             if (cri.isSingleton()) {
                 InjectionUtils.injectContextProxiesAndApplication(cri, 
@@ -322,6 +326,10 @@ public class JAXRSServerFactoryBean exte
                                                     application);
             }
         }
+        if (application != null) {
+            InjectionUtils.injectContextProxiesAndApplication(appProvider, 
+                                                              application, null);
+        }
     }
     
     private void updateClassResourceProviders() {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Mar 24 14:39:03 2011
@@ -33,6 +33,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.logging.Logger;
 
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.ExceptionMapper;
@@ -90,6 +91,8 @@ public final class ProviderFactory {
     private List<ProviderInfo<ResponseExceptionMapper>> responseExceptionMappers
= 
         new ArrayList<ProviderInfo<ResponseExceptionMapper>>(1);
     private RequestPreprocessor requestPreprocessor;
+    private ProviderInfo<Application> application;
+    
     
     private ProviderFactory() {
     }
@@ -573,6 +576,10 @@ public final class ProviderFactory {
         }
     }
     
+    public void setApplicationProvider(ProviderInfo<Application> app) {
+        application = app;
+    }
+    
     public void setRequestPreprocessor(RequestPreprocessor rp) {
         this.requestPreprocessor = rp;
     }
@@ -588,6 +595,9 @@ public final class ProviderFactory {
                      requestHandlers,
                      responseHandlers,
                      exceptionMappers);
+        if (application != null) {
+            application.clearThreadLocalProxies();
+        }
         if (this != SHARED_FACTORY) {
             SHARED_FACTORY.clearThreadLocalProxies();
         }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Mar 24 14:39:03 2011
@@ -814,6 +814,14 @@ public final class InjectionUtils {
         }
     }
     
+    public static void injectContexts(Object requestObject,
+                                 AbstractResourceInfo resource,
+                                 Message message) {
+        injectContextMethods(requestObject, resource, message);
+        injectContextFields(requestObject, resource, message);
+        injectResourceFields(requestObject, resource, message);
+    }
+    
     @SuppressWarnings("unchecked")
     public static void injectContextMethods(Object requestObject,
                                             AbstractResourceInfo cri,

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Thu Mar 24 14:39:03 2011
@@ -92,6 +92,7 @@ import org.apache.cxf.jaxrs.model.Operat
 import org.apache.cxf.jaxrs.model.OperationResourceInfoComparator;
 import org.apache.cxf.jaxrs.model.Parameter;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.AbstractConfigurableProvider;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -183,12 +184,11 @@ public final class JAXRSUtils {
     }
     
     @SuppressWarnings("unchecked")
-    public static void handleSetters(OperationResourceInfo ori,
-                                     Object requestObject,
-                                     Message message) {
+    public static void injectParameters(OperationResourceInfo ori,
+                                        Object requestObject,
+                                        Message message) {
         ClassResourceInfo cri = ori.getClassResourceInfo();
-        InjectionUtils.injectContextMethods(requestObject, cri, message);
-        
+                
         if (cri.isSingleton() 
             && (!cri.getParameterMethods().isEmpty() || !cri.getParameterFields().isEmpty()))
{
             LOG.fine("Injecting request parameters into singleton resource is not thread-safe");
@@ -814,7 +814,9 @@ public final class JAXRSUtils {
         } else if (SearchContext.class.isAssignableFrom(clazz)) {
             o = new SearchContextImpl(m);
         } else if (Application.class.isAssignableFrom(clazz)) {
-            o = contextMessage.getExchange().getEndpoint().get(Application.class.getName());
+            ProviderInfo<?> providerInfo = 
+                (ProviderInfo)contextMessage.getExchange().getEndpoint().get(Application.class.getName());
+            o = providerInfo == null ? providerInfo : providerInfo.getProvider();
         }
         if (o == null && contextMessage != null && !MessageUtils.isRequestor(contextMessage))
{
             o = createServletResourceValue(contextMessage, clazz);

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerApplication.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerApplication.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerApplication.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerApplication.java
Thu Mar 24 14:39:03 2011
@@ -19,7 +19,14 @@
 package org.apache.cxf.jaxrs;
 
 import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.UriInfo;
 
 public class CustomerApplication extends Application {
-
+    @Context
+    private UriInfo uriInfo;
+    
+    public UriInfo getUriInfo() {
+        return uriInfo;
+    }
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1084970&r1=1084969&r2=1084970&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Thu Mar 24 14:39:03 2011
@@ -119,7 +119,7 @@ public class JAXRSUtilsTest extends Asse
     
     @Test
     public void testInjectApplicationInSingleton() throws Exception {
-        Application app = new CustomerApplication();
+        CustomerApplication app = new CustomerApplication();
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         Customer customer = new Customer();
         sf.setServiceBeanObjects(customer);
@@ -128,20 +128,26 @@ public class JAXRSUtilsTest extends Asse
         Server server = sf.create();  
         assertSame(app, customer.getApplication1());
         assertSame(app, customer.getApplication2());
+        ThreadLocalProxy proxy = (ThreadLocalProxy)app.getUriInfo();
+        assertNotNull(proxy);
         invokeCustomerMethod(sf.getServiceFactory().getClassResourceInfo().get(0),
                              customer, server);
         assertSame(app, customer.getApplication2());
+        assertTrue(proxy.get() instanceof UriInfo);
     }
     
     @Test
     public void testInjectApplicationInPerRequestResource() throws Exception {
-        Application app = new CustomerApplication();
+        CustomerApplication app = new CustomerApplication();
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setServiceClass(Customer.class);
         sf.setApplication(app);
         sf.setStart(false);
         Server server = sf.create();  
         
+        ThreadLocalProxy proxy = (ThreadLocalProxy)app.getUriInfo();
+        assertNotNull(proxy);
+        
         ClassResourceInfo cri = sf.getServiceFactory().getClassResourceInfo().get(0);
         
         Customer customer = (Customer)cri.getResourceProvider().getInstance(
@@ -153,6 +159,8 @@ public class JAXRSUtilsTest extends Asse
         invokeCustomerMethod(cri, customer, server);
         assertSame(app, customer.getApplication1());
         assertSame(app, customer.getApplication2());
+        
+        assertTrue(proxy.get() instanceof UriInfo);
     }
     
     private void invokeCustomerMethod(ClassResourceInfo cri, 
@@ -1425,7 +1433,7 @@ public class JAXRSUtilsTest extends Asse
         OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
                                                               cri); 
         Message message = new MessageImpl();
-        JAXRSUtils.handleSetters(ori, c, message);
+        InjectionUtils.injectContextMethods(c, ori.getClassResourceInfo(), message);
         assertNotNull(c.getUriInfo());
         assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
         assertSame(UriInfoImpl.class, 
@@ -1446,7 +1454,7 @@ public class JAXRSUtilsTest extends Asse
         headers.add("AHeader2", "theAHeader2");
         m.put(Message.PROTOCOL_HEADERS, headers);
         m.put(Message.QUERY_STRING, "a=aValue&query2=b");
-        JAXRSUtils.handleSetters(ori, c, m);
+        JAXRSUtils.injectParameters(ori, c, m);
         assertEquals("aValue", c.getQueryParam());
         assertEquals("theAHeader2", c.getAHeader2());
     }
@@ -1464,7 +1472,7 @@ public class JAXRSUtilsTest extends Asse
         headers.add("AHeader", "theAHeader");
         m.put(Message.PROTOCOL_HEADERS, headers);
         m.put(Message.QUERY_STRING, "b=bValue");
-        JAXRSUtils.handleSetters(ori, c, m);
+        JAXRSUtils.injectParameters(ori, c, m);
         assertEquals("bValue", c.getB());
         assertEquals("theAHeader", c.getAHeader());
     }



Mime
View raw message