cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1484943 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/ systests/jaxrs/s...
Date Tue, 21 May 2013 20:35:55 GMT
Author: sergeyb
Date: Tue May 21 20:35:55 2013
New Revision: 1484943

URL: http://svn.apache.org/r1484943
Log:
[Cxf-4996] Support for providers with complex hierarchy like Jackson 2.2.1, and also making
it optional to check these hierarchies

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
    cxf/trunk/systests/jaxrs/pom.xml
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
    cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue May 21 20:35:55 2013
@@ -77,6 +77,7 @@ public abstract class ProviderFactory {
     protected static final String DEFAULT_FILTER_NAME_BINDING = "org.apache.cxf.filter.binding";
     protected static final String SERVER_FACTORY_NAME = "org.apache.cxf.jaxrs.provider.ServerProviderFactory";
     protected static final String CLIENT_FACTORY_NAME = "org.apache.cxf.jaxrs.client.ClientProviderFactory";
+    protected static final String IGNORE_TYPE_VARIABLES = "org.apache.cxf.jaxrs.providers.ignore.typevars";
     
     private static final String ACTIVE_JAXRS_PROVIDER_KEY = "active.jaxrs.provider";
     private static final Logger LOG = LogUtils.getL7dLogger(ProviderFactory.class);
@@ -270,7 +271,12 @@ public abstract class ProviderFactory {
                                      boolean injectContext) {
         
         Class<?> mapperClass =  ClassHelper.getRealClass(em.getProvider());
-        Type[] types = getGenericInterfaces(mapperClass);
+        Type[] types = null;
+        if (m != null && MessageUtils.isTrue(m.getContextualProperty(IGNORE_TYPE_VARIABLES)))
{
+            types = new Type[]{mapperClass};
+        } else {
+            types = getGenericInterfaces(mapperClass, expectedType);
+        }
         for (Type t : types) {
             if (t instanceof ParameterizedType) {
                 ParameterizedType pt = (ParameterizedType)t;
@@ -309,7 +315,7 @@ public abstract class ProviderFactory {
                         return;
                     }
                 }
-            } else if (t instanceof Class && ((Class<?>)t).isAssignableFrom(providerClass))
{
+            } else if (t instanceof Class && providerClass.isAssignableFrom((Class<?>)t))
{
                 if (injectContext) {
                     injectContextValues(em, m);
                 }
@@ -901,9 +907,15 @@ public abstract class ProviderFactory {
     
     public static class ClassComparator implements 
         Comparator<Object> {
+        private Class<?> expectedCls;
+        public ClassComparator() {
+        }
+        public ClassComparator(Class<?> expectedCls) {
+            this.expectedCls = expectedCls;
+        }
     
         public int compare(Object em1, Object em2) {
-            return compareClasses(em1, em2);
+            return compareClasses(expectedCls, em1, em2);
         }
     }
     
@@ -916,13 +928,15 @@ public abstract class ProviderFactory {
         
         return (ProviderFactory)e.get(name);
     }
-    
     protected static int compareClasses(Object o1, Object o2) {
+        return compareClasses(null, o1, o2);
+    }
+    protected static int compareClasses(Class<?> expectedCls, Object o1, Object o2)
{
         Class<?> cl1 = ClassHelper.getRealClass(o1); 
         Class<?> cl2 = ClassHelper.getRealClass(o2);
         
-        Type[] types1 = getGenericInterfaces(cl1);
-        Type[] types2 = getGenericInterfaces(cl2);
+        Type[] types1 = getGenericInterfaces(cl1, expectedCls);
+        Type[] types2 = getGenericInterfaces(cl2, expectedCls);
         
         if (types1.length == 0 && types2.length > 0) {
             return 1;
@@ -942,19 +956,22 @@ public abstract class ProviderFactory {
         return -1;
     }
     
-    private static Type[] getGenericInterfaces(Class<?> cls) {
+    private static Type[] getGenericInterfaces(Class<?> cls, Class<?> expectedClass)
{
         if (Object.class == cls) {
             return new Type[]{};
         }
-        Type genericSuperCls = cls.getGenericSuperclass();
-        if (genericSuperCls instanceof ParameterizedType) {
-            return new Type[]{genericSuperCls};
+        if (expectedClass != null) {
+            Type genericSuperType = cls.getGenericSuperclass();
+            if (genericSuperType instanceof ParameterizedType       
+                && expectedClass == InjectionUtils.getActualType(genericSuperType))
{
+                return new Type[]{genericSuperType};
+            }
         }
         Type[] types = cls.getGenericInterfaces();
         if (types.length > 0) {
             return types;
         }
-        return getGenericInterfaces(cls.getSuperclass());
+        return getGenericInterfaces(cls.getSuperclass(), expectedClass);
     }
     
     protected static class BindingPriorityComparator extends AbstactBindingPriorityComparator
{

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ServerProviderFactory.java
Tue May 21 20:35:55 2013
@@ -21,7 +21,6 @@ package org.apache.cxf.jaxrs.provider;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -184,7 +183,7 @@ public final class ServerProviderFactory
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ExceptionMapperComparator());
+        Collections.sort(candidates, new ClassComparator(exceptionType));
         return (ExceptionMapper<T>) candidates.get(0);
     }
     
@@ -595,13 +594,5 @@ public final class ServerProviderFactory
         }
     }
     
-    private static class ExceptionMapperComparator implements 
-        Comparator<ExceptionMapper<? extends Throwable>> {
     
-        public int compare(ExceptionMapper<? extends Throwable> em1, 
-                           ExceptionMapper<? extends Throwable> em2) {
-            return compareClasses(em1, em2);
-        }
-        
-    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Tue May 21 20:35:55 2013
@@ -254,7 +254,8 @@ public class ProviderFactoryTest extends
         RuntimeExceptionMapper2 exMapper2 = new RuntimeExceptionMapper2(); 
         pf.registerUserProvider(exMapper2);
         assertSame(exMapper1, pf.createExceptionMapper(RuntimeException.class, new MessageImpl()));
-        assertSame(exMapper2, pf.createExceptionMapper(WebApplicationException.class, new
MessageImpl()));
+        Object webExMapper = pf.createExceptionMapper(WebApplicationException.class, new
MessageImpl());
+        assertSame(exMapper2, webExMapper);
     }
     
     @Test
@@ -337,6 +338,30 @@ public class ProviderFactoryTest extends
         assertTrue(BinaryDataProvider.class == writer.getClass());
     }
     
+    @Test
+    public void testGetComplexProvider() throws Exception {
+        ServerProviderFactory pf = ServerProviderFactory.getInstance();
+        pf.registerUserProvider(new ComplexMessageBodyReader());
+        Message m = new MessageImpl();
+        Exchange ex = new ExchangeImpl();
+        m.setExchange(ex);
+        m.put(ServerProviderFactory.IGNORE_TYPE_VARIABLES, true);
+        MessageBodyReader<Book> reader =
+            pf.createMessageBodyReader(Book.class, Book.class, null, MediaType.APPLICATION_JSON_TYPE,

+                                       m);
+        assertTrue(ComplexMessageBodyReader.class == reader.getClass());
+    }
+    
+    @Test
+    public void testGetComplexProvider2() throws Exception {
+        ServerProviderFactory pf = ServerProviderFactory.getInstance();
+        pf.registerUserProvider(new ComplexMessageBodyReader());
+        MessageBodyReader<Book> reader =
+            pf.createMessageBodyReader(Book.class, Book.class, null, MediaType.APPLICATION_JSON_TYPE,

+                                       new MessageImpl());
+        assertTrue(ComplexMessageBodyReader.class == reader.getClass());
+    }
+    
     private void verifyProvider(ProviderFactory pf, Class<?> type, Class<?> provider,
String mediaType) 
         throws Exception {
         
@@ -750,4 +775,44 @@ public class ProviderFactoryTest extends
         
     }
         
+    private static class ComplexMessageBodyReader extends ProviderBase<AClass> {
+    }
+    private abstract static class ProviderBase<A> implements
+        MessageBodyReader<Object>, MessageBodyWriter<Object> {
+        @Override
+        public boolean isReadable(Class<?> cls, Type arg1, Annotation[] arg2, MediaType
arg3) {
+            return true;
+        }
+
+        @Override
+        public Object readFrom(Class<Object> arg0, Type arg1, Annotation[] arg2, MediaType
arg3,
+                               MultivaluedMap<String, String> arg4, InputStream arg5)
throws IOException,
+            WebApplicationException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        @Override
+        public long getSize(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
MediaType arg4) {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        @Override
+        public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType
arg3) {
+            // TODO Auto-generated method stub
+            return false;
+        }
+
+        @Override
+        public void writeTo(Object arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
MediaType arg4,
+                            MultivaluedMap<String, Object> arg5, OutputStream arg6)
throws IOException,
+            WebApplicationException {
+            // TODO Auto-generated method stub
+            
+        }      
+    }
+    public static class AClass {
+    }
+    
 }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProviderFactory.java
Tue May 21 20:35:55 2013
@@ -118,7 +118,7 @@ public final class ClientProviderFactory
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ProviderFactory.ClassComparator());
+        Collections.sort(candidates, new ProviderFactory.ClassComparator(paramType));
         return (ResponseExceptionMapper<T>) candidates.get(0);
     }
     

Modified: cxf/trunk/systests/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/pom.xml?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/pom.xml (original)
+++ cxf/trunk/systests/jaxrs/pom.xml Tue May 21 20:35:55 2013
@@ -331,14 +331,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-          <groupId>org.codehaus.jackson</groupId>
-          <artifactId>jackson-jaxrs</artifactId>
-          <version>1.9.0</version>
-        </dependency>
-        <dependency>
-          <groupId>org.codehaus.jackson</groupId>
-          <artifactId>jackson-core-asl</artifactId>
-          <version>1.9.0</version>
+          <groupId>com.fasterxml.jackson.jaxrs</groupId>
+          <artifactId>jackson-jaxrs-json-provider</artifactId>
+          <version>2.2.1</version>
         </dependency>
         <dependency>
          <groupId>org.apache.httpcomponents</groupId>

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Tue May 21 20:35:55 2013
@@ -25,6 +25,8 @@ import java.net.URLConnection;
 import java.util.Collection;
 import java.util.Collections;
 
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
@@ -66,7 +68,7 @@ public class JAXRSClientServerResourceJa
         String endpointAddress =
             "http://localhost:" + PORT + "/webapp/bookstore/collections"; 
         WebClient wc = WebClient.create(endpointAddress,
-            Collections.singletonList(new org.codehaus.jackson.jaxrs.JacksonJsonProvider()));
+            Collections.singletonList(new JacksonJsonProvider()));
         wc.accept("application/json");
         Collection<? extends Book> collection = wc.getCollection(Book.class);
         assertEquals(1, collection.size());

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
Tue May 21 20:35:55 2013
@@ -25,6 +25,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
+
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.rs.security.cors.CorsHeaderConstants;
@@ -68,7 +70,7 @@ public class CrossOriginSimpleTest exten
     @Before
     public void before() {
         List<Object> providers = new ArrayList<Object>();
-        providers.add(new org.codehaus.jackson.jaxrs.JacksonJsonProvider());
+        providers.add(new JacksonJsonProvider());
         configClient = WebClient.create("http://localhost:" + PORT + "/config", providers);
     }
 

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml Tue May 21 20:35:55
2013
@@ -51,7 +51,7 @@ http://cxf.apache.org/core 
 			<ref bean="config-server" />
 		</jaxrs:serviceBeans>
 		<jaxrs:providers>
-			<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
+			<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
 		</jaxrs:providers> 
 	</jaxrs:server>
 

Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml?rev=1484943&r1=1484942&r2=1484943&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml Tue
May 21 20:35:55 2013
@@ -34,7 +34,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
             <ref bean="bookstore"/>
         </jaxrs:serviceBeans>
         <jaxrs:providers>
-            <bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
+            <bean class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
         </jaxrs:providers>
     </jaxrs:server>
     <bean id="bookstore" scope="prototype" class="org.apache.cxf.systest.jaxrs.BookStore"/>



Mime
View raw message