cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1484998 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/ja...
Date Tue, 21 May 2013 22:14:37 GMT
Author: sergeyb
Date: Tue May 21 22:14:37 2013
New Revision: 1484998

URL: http://svn.apache.org/r1484998
Log:
Merged revisions 1484958 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1484958 | sergeyb | 2013-05-21 22:08:24 +0100 (Tue, 21 May 2013) | 9 lines
  
  Merged revisions 1484943 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1484943 | sergeyb | 2013-05-21 21:35:55 +0100 (Tue, 21 May 2013) | 1 line
    
    [Cxf-4996] Support for providers with complex hierarchy like Jackson 2.2.1, and also making
it optional to check these hierarchies
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/pom.xml
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1484958
  Merged /cxf/trunk:r1484943

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue May 21 22:14:37 2013
@@ -66,6 +66,8 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
 public final class ProviderFactory {
+    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);
     private static final ProviderFactory SHARED_FACTORY = getInstance();
@@ -291,7 +293,7 @@ public final class ProviderFactory {
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ExceptionMapperComparator());
+        Collections.sort(candidates, new ClassComparator(exceptionType));
         return (ExceptionMapper<T>) candidates.get(0);
     }
     
@@ -322,7 +324,7 @@ public final class ProviderFactory {
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ClassComparator());
+        Collections.sort(candidates, new ClassComparator(paramType));
         return (ResponseExceptionMapper<T>) candidates.get(0);
     }
     
@@ -334,7 +336,12 @@ public final 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;
@@ -373,7 +380,7 @@ public final 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);
                 }
@@ -914,31 +921,26 @@ public final class ProviderFactory {
         return set;
     }
     
-    private static class ExceptionMapperComparator implements 
-        Comparator<ExceptionMapper<? extends Throwable>> {
-
-        public int compare(ExceptionMapper<? extends Throwable> em1, 
-                           ExceptionMapper<? extends Throwable> em2) {
-            return compareClasses(em1, em2);
-        }
-        
-    }
-    
     private 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);
         }
         
     }
-    
-    private static int compareClasses(Object o1, Object 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;
@@ -958,19 +960,22 @@ public final 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);
     }
     
     static class ContextResolverProxy<T> implements ContextResolver<T> {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Tue May 21 22:14:37 2013
@@ -352,7 +352,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
@@ -435,6 +436,30 @@ public class ProviderFactoryTest extends
         assertTrue(BinaryDataProvider.class == writer.getClass());
     }
     
+    @Test
+    public void testGetComplexProvider() throws Exception {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        pf.registerUserProvider(new ComplexMessageBodyReader());
+        Message m = new MessageImpl();
+        Exchange ex = new ExchangeImpl();
+        m.setExchange(ex);
+        m.put(ProviderFactory.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 {
+        ProviderFactory pf = ProviderFactory.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 {
         
@@ -878,4 +903,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/branches/2.6.x-fixes/systests/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/pom.xml?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/pom.xml (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/pom.xml Tue May 21 22:14:37 2013
@@ -323,14 +323,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/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
Tue May 21 22:14:37 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/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/cors/CrossOriginSimpleTest.java
Tue May 21 22:14:37 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/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_cors/WEB-INF/beans.xml
Tue May 21 22:14:37 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/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml?rev=1484998&r1=1484997&r2=1484998&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
Tue May 21 22:14:37 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