cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1513900 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/fronte...
Date Wed, 14 Aug 2013 14:40:15 GMT
Author: sergeyb
Date: Wed Aug 14 14:40:15 2013
New Revision: 1513900

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

................
  r1513886 | sergeyb | 2013-08-14 16:59:16 +0300 (Wed, 14 Aug 2013) | 9 lines
  
  Merged revisions 1513867 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1513867 | sergeyb | 2013-08-14 16:16:58 +0300 (Wed, 14 Aug 2013) | 1 line
    
    [CXF-5204] Better support for TypeVariable in JAX-RS frontend
  ........
................

Added:
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AbstractRestController.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/AbstractRestController.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/ConcreteRestController.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/ConcreteRestController.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/ConcreteRestResource.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/ConcreteRestResource.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/RestResource.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/RestResource.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractGenericBookStoreSpring.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/AbstractGenericBookStoreSpring.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/GenericBookStoreSpring.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBookInterface.java
      - copied unchanged from r1513886, cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBookInterface.java
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/client/ClientProxyImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    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/JAXRSClientServerSpringBookTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook.java
    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:r1513886
  Merged /cxf/trunk:r1513867

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/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Aug 14 14:40:15 2013
@@ -538,7 +538,7 @@ public class ClientProxyImpl extends Abs
         
         Object response = null;
         try {
-            response = handleResponse(outMessage);
+            response = handleResponse(outMessage, ori.getClassResourceInfo().getServiceClass());
             return response;
         } catch (Exception ex) {
             response = ex;
@@ -564,7 +564,7 @@ public class ClientProxyImpl extends Abs
                                    body, bodyIndex, exchange, invContext);
     }
     
-    protected Object handleResponse(Message outMessage) 
+    protected Object handleResponse(Message outMessage, Class<?> serviceCls) 
         throws Throwable {
         try {
             Response r = setResponseBuilder(outMessage, outMessage.getExchange()).build();
@@ -578,14 +578,15 @@ public class ClientProxyImpl extends Abs
                     && ((InputStream)r.getEntity()).available() == 0)) {
                 return r;
             }
-
+            Class<?> returnType = method.getReturnType(); 
             Type genericType = 
-                InjectionUtils.processGenericTypeIfNeeded(method.getDeclaringClass(), 
+                InjectionUtils.processGenericTypeIfNeeded(serviceCls,
+                                                          returnType,   
                                                           method.getGenericReturnType());
-            
+            returnType = InjectionUtils.updateParamClassToTypeIfNeeded(returnType, genericType);
             return readBody(r, 
                             outMessage, 
-                            method.getReturnType(), 
+                            returnType, 
                             genericType, 
                             method.getDeclaredAnnotations());
         } finally {
@@ -641,11 +642,10 @@ public class ClientProxyImpl extends Abs
             Object body = objs.get(0);
             try {
                 if (bodyIndex != -1) {
-                    Type paramType = method.getGenericParameterTypes()[bodyIndex];
-                    paramType = InjectionUtils.processGenericTypeIfNeeded(method.getDeclaringClass(),
-                                                                          paramType);   
                  
-                    writeBody(body, outMessage, body.getClass(), paramType,
-                              anns, headers, os);
+                    Type genericType = method.getGenericParameterTypes()[bodyIndex];
+                    genericType = InjectionUtils.processGenericTypeIfNeeded(
+                        ori.getClassResourceInfo().getServiceClass(), body.getClass(), genericType);
+                    writeBody(body, outMessage, body.getClass(), genericType, anns, headers,
os);
                 } else {
                     writeBody(body, outMessage, body.getClass(), body.getClass(), 
                               anns, headers, os);

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Wed Aug 14 14:40:15 2013
@@ -201,6 +201,7 @@ public class JAXRSOutInterceptor extends
         
         List<MediaType> availableContentTypes = computeAvailableContentTypes(message,
response);  
         
+
         Method invoked = null;
         if (firstTry) {
             invoked = ori == null ? null : ori.getAnnotatedMethod() == null
@@ -210,7 +211,7 @@ public class JAXRSOutInterceptor extends
         Type genericType = getGenericResponseType(invoked, responseObj, targetType);
         if (ori != null) {
             genericType = InjectionUtils.processGenericTypeIfNeeded(
-                ori.getClassResourceInfo().getServiceClass(), genericType);
+                ori.getClassResourceInfo().getServiceClass(), targetType, genericType);
         }
                
         Annotation[] annotations = invoked != null ? invoked.getAnnotations() : new Annotation[]{};

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Aug 14 14:40:15 2013
@@ -122,12 +122,6 @@ public final class InjectionUtils {
             }
         }
         
-        Type[] bounds = var.getBounds();
-        int boundPos = bounds.length > pos ? pos : 0; 
-        if (bounds.length > boundPos && bounds[boundPos] != Object.class) {
-            return bounds[boundPos];
-        }
-                
         Type genericSubtype = serviceClass.getGenericSuperclass();
         if (genericSubtype == Object.class) {
             Type[] genInterfaces = serviceClass.getGenericInterfaces();
@@ -138,7 +132,14 @@ public final class InjectionUtils {
         }
         Type result = genericSubtype != Object.class ? InjectionUtils.getActualType(genericSubtype,
pos)
                                               : genericSubtype;
-        return result == null ? Object.class : result;
+        if (result == null || result == Object.class) {
+            Type[] bounds = var.getBounds();
+            int boundPos = bounds.length > pos ? pos : 0; 
+            if (bounds.length > boundPos && bounds[boundPos] != Object.class)
{
+                result = bounds[boundPos];
+            }
+        }
+        return result;
     }
     
     public static Method checkProxy(Method methodToInvoke, Object resourceObject) {
@@ -215,13 +216,18 @@ public final class InjectionUtils {
             } else if (genericType instanceof GenericArrayType) {
                 genericType = ((GenericArrayType)genericType).getGenericComponentType();
             }
-
-            Class<?> cls = (Class<?>)genericType;
+            Class<?> cls = null;
+            if (!(genericType instanceof ParameterizedType)) {
+                cls = (Class<?>)genericType;
+            } else {
+                cls = (Class<?>)((ParameterizedType)genericType).getRawType();
+            }
             return cls.isArray() ? cls.getComponentType() : cls;
+            
         }
         ParameterizedType paramType = (ParameterizedType)genericType;
         Type t = getType(paramType.getActualTypeArguments(), pos);
-        return t instanceof Class ? (Class<?>)t : getActualType(t, pos);
+        return t instanceof Class ? (Class<?>)t : getActualType(t, 0);
     }
     
     public static Type getType(Type[] types, int pos) {
@@ -1175,16 +1181,33 @@ public final class InjectionUtils {
         }
     }
     
-    public static Type processGenericTypeIfNeeded(Class<?> cls, Type type) {
+
+    public static Class<?> updateParamClassToTypeIfNeeded(Class<?> paramCls,
Type type) {
+        if (type instanceof Class && paramCls.isAssignableFrom((Class<?>)type))
{
+            paramCls = (Class<?>)type; 
+        }
+        return paramCls;
+    }
+    
+
+    public static Type processGenericTypeIfNeeded(Class<?> serviceCls, Class<?>
paramCls, Type type) {
+       
         if (type instanceof TypeVariable) {
-            return InjectionUtils.getSuperType(cls, (TypeVariable<?>)type);
+            type = InjectionUtils.getSuperType(serviceCls, (TypeVariable<?>)type);
         } else if (type instanceof ParameterizedType
             && ((ParameterizedType)type).getActualTypeArguments()[0] instanceof TypeVariable
             && isSupportedCollectionOrArray(getRawType(type))) {
-            return new ParameterizedCollectionType(InjectionUtils.getActualType(type, 0));
-        } else {
-            return type;
+            TypeVariable<?> typeVar = (TypeVariable<?>)((ParameterizedType)type).getActualTypeArguments()[0];
+            Type theType = InjectionUtils.getSuperType(serviceCls, typeVar);
+            Class<?> cls = theType instanceof Class 
+                ? (Class<?>)theType : InjectionUtils.getActualType(theType, 0);
+            type = new ParameterizedCollectionType(cls);
+        } 
+        if (type == null || type == Object.class) {
+            type = paramCls;
         }
+        return type;
+        
     }
     
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Wed Aug 14 14:40:15 2013
@@ -568,13 +568,8 @@ public final class JAXRSUtils {
         for (int i = 0; i < parameterTypes.length; i++) {
             Class<?> param = parameterTypes[i]; 
             Type genericParam = InjectionUtils.processGenericTypeIfNeeded(
-                ori.getClassResourceInfo().getServiceClass(), genericParameterTypes[i]);
-            if (param == Object.class) {
-                param = (Class<?>)genericParam; 
-            } else if (genericParam == Object.class) {
-                genericParam = param;
-            }
-            
+                ori.getClassResourceInfo().getServiceClass(), param, genericParameterTypes[i]);
+            param = InjectionUtils.updateParamClassToTypeIfNeeded(param, genericParam);
             
             Object paramValue = processParameter(param, 
                                                  genericParam,

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
Wed Aug 14 14:40:15 2013
@@ -29,6 +29,8 @@ import javax.ws.rs.core.MediaType;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.fortest.BookEntity;
 import org.apache.cxf.jaxrs.fortest.BookEntity2;
+import org.apache.cxf.jaxrs.fortest.ConcreteRestController;
+import org.apache.cxf.jaxrs.fortest.ConcreteRestResource;
 import org.apache.cxf.jaxrs.fortest.GenericEntityImpl;
 import org.apache.cxf.jaxrs.fortest.GenericEntityImpl2;
 import org.apache.cxf.jaxrs.fortest.GenericEntityImpl3;
@@ -127,6 +129,51 @@ public class SelectMethodCandidatesTest 
         assertEquals(2L, book.getId());
         assertEquals("The Book", book.getName());
     }
+    @Test
+    public void testFindFromAbstractGenericImpl5() throws Exception {
+        JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+        sf.setResourceClasses(ConcreteRestController.class);
+        sf.create();
+        List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
+        Message m = new MessageImpl();
+        m.put(Message.CONTENT_TYPE, "text/xml");
+        Exchange ex = new ExchangeImpl();
+        ex.setInMessage(m);
+        m.setExchange(ex);
+        Endpoint e = EasyMock.createMock(Endpoint.class);
+        e.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        e.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        e.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        e.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(ProviderFactory.getInstance()).times(3);
+        e.get("org.apache.cxf.jaxrs.comparator");
+        EasyMock.expectLastCall().andReturn(null);
+        EasyMock.replay(e);
+        ex.put(Endpoint.class, e);
+        
+        MetadataMap<String, String> values = new MetadataMap<String, String>();
+        ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/", values,
+                                                                    m);
+        OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource, 
+                                                                m, 
+                                    "POST", values, "text/xml", 
+                                    JAXRSUtils.sortMediaTypes("*/*"),
+                                    true);
+        assertNotNull(ori);
+        assertEquals("resourceMethod needs to be selected", "add",
+                     ori.getMethodToInvoke().getName());
+        
+        String value = "<concreteRestResource><name>The Book</name></concreteRestResource>";
+        m.setContent(InputStream.class, new ByteArrayInputStream(value.getBytes()));
+        List<Object> params = JAXRSUtils.processParameters(ori, values, m);
+        assertEquals(1, params.size());
+        ConcreteRestResource book = (ConcreteRestResource)params.get(0);
+        assertNotNull(book);
+        assertEquals("The Book", book.getName());
+    }
     
     @Test
     public void testFindFromAbstractGenericClass3() throws Exception {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/ResourceUtilsTest.java
Wed Aug 14 14:40:15 2013
@@ -30,6 +30,7 @@ import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.core.UriInfo;
+import javax.xml.bind.annotation.XmlRootElement;
 
 import org.apache.cxf.jaxrs.Customer;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -132,6 +133,19 @@ public class ResourceUtilsTest extends A
         assertTrue(types.containsKey(Chapter.class));
     }
     
+    @Test
+    public void testGetAllJaxbClassesComplexGenericType() {
+        ClassResourceInfo cri1 = 
+            ResourceUtils.createClassResourceInfo(OrderResource.class, 
+                                                  OrderResource.class, true, true);
+        Map<Class<?>, Type> types = 
+            ResourceUtils.getAllRequestResponseTypes(Collections.singletonList(cri1), true)
+                .getAllTypes();
+        assertEquals(2, types.size());
+        assertTrue(types.containsKey(OrderItemsDTO.class));
+        assertTrue(types.containsKey(OrderItemDTO.class));
+    }
+    
     public interface IProductResource {
         @Path("/parts")
         IPartsResource getParts();
@@ -156,4 +170,24 @@ public class ResourceUtilsTest extends A
         @GET
         Book get();
     }
+    
+    @XmlRootElement
+    public static class OrderItem {
+        
+    }
+    @XmlRootElement
+    public static class OrderItemDTO<T> {
+        
+    }
+    @XmlRootElement
+    public static class OrderItemsDTO<E> {
+        
+    }
+    
+    public static class OrderResource {
+        @GET
+        public OrderItemsDTO<? extends OrderItemDTO<? extends OrderItem>> getOrders()
{
+            return null;
+        }
+    }
 }

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
Wed Aug 14 14:40:15 2013
@@ -86,7 +86,7 @@ public class BookStoreSpring {
     @Path("/books/xsitype")
     @Produces("application/xml")
     public Book getBookXsiType() {
-        return new SuperBook("SuperBook", 999L);
+        return new SuperBook("SuperBook", 999L, true);
     }
     
     @SuppressWarnings("unchecked")
@@ -94,7 +94,7 @@ public class BookStoreSpring {
     @Path("/books/superbook")
     @Produces("application/json")
     public <T extends Book> T getSuperBookJson() {
-        SuperBook book = new SuperBook("SuperBook", 999L);
+        SuperBook book = new SuperBook("SuperBook", 999L, true);
         
         return (T)book;
     }
@@ -104,18 +104,20 @@ public class BookStoreSpring {
     @Path("/books/superbooks")
     @Produces("application/json")
     public <T extends Book> List<T> getSuperBookCollectionJson() {
-        SuperBook book = new SuperBook("SuperBook", 999L);
+        SuperBook book = new SuperBook("SuperBook", 999L, true);
         
         return Collections.singletonList((T)book);
     }
     
-    @SuppressWarnings("unchecked")
     @POST
     @Path("/books/superbook")
     @Consumes("application/json")
     @Produces("application/json")
     public <T extends Book> T echoSuperBookJson(T book) {
-        return (T)(SuperBook)book;
+        if (((SuperBook)book).isSuperBook()) {
+            return book;
+        }
+        throw new WebApplicationException(400);
     }
     
     @SuppressWarnings("unchecked")
@@ -124,7 +126,7 @@ public class BookStoreSpring {
     @Consumes("application/json")
     @Produces("application/json")
     public <T extends Book> List<T> echoSuperBookCollectionJson(List<T>
book) {
-        if (book.get(0) instanceof SuperBook) {
+        if (((SuperBook)book.get(0)).isSuperBook()) {
             return book;
         }
         throw new WebApplicationException(400);

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=1513900&r1=1513899&r2=1513900&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
Wed Aug 14 14:40:15 2013
@@ -26,6 +26,8 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import javax.ws.rs.core.MediaType;
+
 import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
 import org.apache.cxf.helpers.IOUtils;
@@ -94,8 +96,9 @@ public class JAXRSClientServerResourceJa
         BookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, BookStoreSpring.class,

             Collections.singletonList(new JacksonJsonProvider()));
         List<SuperBook> books = 
-            proxy.echoSuperBookCollectionJson(Collections.singletonList(new SuperBook("Super",
124L)));
+            proxy.echoSuperBookCollectionJson(Collections.singletonList(new SuperBook("Super",
124L, true)));
         assertEquals(124L, books.get(0).getId());
+        assertTrue(books.get(0).isSuperBook());
     }
     
     @Test
@@ -105,8 +108,93 @@ public class JAXRSClientServerResourceJa
             "http://localhost:" + PORT + "/webapp/store2";
         BookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, BookStoreSpring.class,

             Collections.singletonList(new JacksonJsonProvider()));
-        SuperBook book = proxy.echoSuperBookJson(new SuperBook("Super", 124L));
+        SuperBook book = proxy.echoSuperBookJson(new SuperBook("Super", 124L, true));
+        assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookCollectionProxy() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/webapp/genericstore";
+        GenericBookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, 
+            GenericBookStoreSpring.class, Collections.singletonList(new JacksonJsonProvider()));
+        List<SuperBook> books = 
+            proxy.echoSuperBookCollectionJson(Collections.singletonList(new SuperBook("Super",
124L, true)));
+        assertEquals(124L, books.get(0).getId());
+        assertTrue(books.get(0).isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookProxy() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/webapp/genericstore";
+        GenericBookStoreSpring proxy = JAXRSClientFactory.create(endpointAddress, 
+            GenericBookStoreSpring.class, Collections.singletonList(new JacksonJsonProvider()));
+        SuperBook book = proxy.echoSuperBookJson(new SuperBook("Super", 124L, true));
+        assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookWebClient() throws Exception {
+        
+        String endpointAddress = 
+            "http://localhost:" + PORT + "/webapp/genericstore/books/superbook";
+        WebClient wc = WebClient.create(endpointAddress, 
+                                        Collections.singletonList(new JacksonJsonProvider()));
+        wc.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);
+        SuperBook book = wc.post(new SuperBook("Super", 124L, true), SuperBook.class);
+        assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookWebClientXml() throws Exception {
+        
+        String endpointAddress = 
+            "http://localhost:" + PORT + "/webapp/genericstore/books/superbook";
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);
+        SuperBook book = wc.post(new SuperBook("Super", 124L, true), SuperBook.class);
+        assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookCollectionWebClient() throws Exception {
+        
+        String endpointAddress = 
+            "http://localhost:" + PORT + "/webapp/genericstore/books/superbooks";
+        WebClient wc = WebClient.create(endpointAddress, 
+                                        Collections.singletonList(new JacksonJsonProvider()));
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(100000000L);
+        wc.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);
+        Collection<? extends SuperBook> books = 
+            wc.postAndGetCollection(Collections.singletonList(new SuperBook("Super", 124L,
true)),
+                                    SuperBook.class,
+                                    SuperBook.class);
+        SuperBook book = books.iterator().next();
+        assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
+    }
+    
+    @Test
+    public void testEchoGenericSuperBookCollectionWebClientXml() throws Exception {
+        
+        String endpointAddress = 
+            "http://localhost:" + PORT + "/webapp/genericstore/books/superbooks";
+        WebClient wc = WebClient.create(endpointAddress);
+        wc.accept(MediaType.APPLICATION_XML).type(MediaType.APPLICATION_XML);
+        Collection<? extends SuperBook> books = 
+            wc.postAndGetCollection(Collections.singletonList(new SuperBook("Super", 124L,
true)),
+                                    SuperBook.class,
+                                    SuperBook.class);
+        SuperBook book = books.iterator().next();
         assertEquals(124L, book.getId());
+        assertTrue(book.isSuperBook());
     }
     
     @Test

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
Wed Aug 14 14:40:15 2013
@@ -367,7 +367,7 @@ public class JAXRSClientServerSpringBook
         WebClient wc = WebClient.create(address, Collections.singletonList(provider));
         wc.accept("application/xml");
         wc.type("application/xml");
-        SuperBook book = new SuperBook("SuperBook2", 999L);
+        SuperBook book = new SuperBook("SuperBook2", 999L, true);
         Book book2 = wc.invoke("POST", book, Book.class, Book.class);
         assertEquals("SuperBook2", book2.getName());
         
@@ -381,7 +381,7 @@ public class JAXRSClientServerSpringBook
         provider.setJaxbElementClassNames(Collections.singletonList(Book.class.getName()));
         BookStoreSpring bookStore = JAXRSClientFactory.create(address, BookStoreSpring.class,

                                                               Collections.singletonList(provider));
-        SuperBook book = new SuperBook("SuperBook2", 999L);
+        SuperBook book = new SuperBook("SuperBook2", 999L, true);
         Book book2 = bookStore.postGetBookXsiType(book);
         assertEquals("SuperBook2", book2.getName());
         

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook.java?rev=1513900&r1=1513899&r2=1513900&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/SuperBook.java
Wed Aug 14 14:40:15 2013
@@ -23,13 +23,23 @@ import javax.xml.bind.annotation.XmlRoot
 
 
 @XmlRootElement(name = "SuperBook")
-public class SuperBook extends Book {
+public class SuperBook extends Book implements SuperBookInterface {
+    private boolean superBook;
     
     public SuperBook() {
         
     }
     
-    public SuperBook(String name, long id) {
+    public SuperBook(String name, long id, boolean superStatus) {
         super(name, id);
+        this.superBook = superStatus;
+    }
+
+    public boolean isSuperBook() {
+        return superBook;
+    }
+
+    public void setSuperBook(boolean superBook) {
+        this.superBook = superBook;
     }
 }

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=1513900&r1=1513899&r2=1513900&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
Wed Aug 14 14:40:15 2013
@@ -47,7 +47,18 @@ http://cxf.apache.org/schemas/jaxrs.xsd"
         </jaxrs:providers>
     </jaxrs:server>
     
+    <jaxrs:server id="genericBookStore"
+                  address="/genericstore">
+        <jaxrs:serviceBeans>
+            <ref bean="gBookStore"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="jackson"/>
+        </jaxrs:providers>
+    </jaxrs:server>
+    
     <bean id="jackson" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
     <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
     <bean id="bookstore2" class="org.apache.cxf.systest.jaxrs.BookStoreSpring"/>
+    <bean id="gBookStore" class="org.apache.cxf.systest.jaxrs.GenericBookStoreSpring"/>
 </beans>



Mime
View raw message