cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1563197 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Date Fri, 31 Jan 2014 18:18:17 GMT
Author: sergeyb
Date: Fri Jan 31 18:18:17 2014
New Revision: 1563197

URL: http://svn.apache.org/r1563197
Log:
[CXF-5348] Fix to get complex typed mappers correctly selected

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java

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=1563197&r1=1563196&r2=1563197&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
Fri Jan 31 18:18:17 2014
@@ -999,9 +999,13 @@ public abstract class ProviderFactory {
         }
         if (expectedClass != null) {
             Type genericSuperType = cls.getGenericSuperclass();
-            if (genericSuperType instanceof ParameterizedType       
-                && expectedClass == InjectionUtils.getActualType(genericSuperType))
{
-                return new Type[]{genericSuperType};
+            if (genericSuperType instanceof ParameterizedType) {       
+                Class<?> actualType = InjectionUtils.getActualType(genericSuperType);
+                if (expectedClass == actualType) {
+                    return new Type[]{genericSuperType};
+                } else if (expectedClass.isAssignableFrom(actualType)) {
+                    return new Type[]{};    
+                }
             }
         }
         Type[] types = cls.getGenericInterfaces();

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=1563197&r1=1563196&r2=1563197&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
Fri Jan 31 18:18:17 2014
@@ -38,6 +38,7 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -358,6 +359,17 @@ public class ProviderFactoryTest extends
                        "application/json");
     }
     
+    @Test
+    public void testComplexExceptionMapper() {
+        ServerProviderFactory pf = ServerProviderFactory.getInstance();
+        pf.registerUserProvider(new SecurityExceptionMapper());
+        ExceptionMapper<SecurityException> mapper = 
+            pf.createExceptionMapper(SecurityException.class, new MessageImpl());
+        assertTrue(mapper instanceof SecurityExceptionMapper);
+        ExceptionMapper<Throwable> mapper2 = 
+            pf.createExceptionMapper(Throwable.class, new MessageImpl());
+        assertNull(mapper2);
+    }
     
     @Test
     public void testRegisterCustomResolver() throws Exception {
@@ -758,4 +770,14 @@ public class ProviderFactoryTest extends
     public static class AClass {
     }
     
+    private static class SecurityExceptionMapper 
+        extends AbstractBadRequestExceptionMapper<SecurityException> {
+    }
+    private abstract static class AbstractBadRequestExceptionMapper<T extends Throwable>

+        implements ExceptionMapper<T> {
+        @Override
+        public Response toResponse(T exception) {
+            return Response.status(Status.BAD_REQUEST).entity(exception.getMessage()).build();
+        }
+    }
 }



Mime
View raw message