cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1396558 - in /cxf/branches/2.5.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/provider/ systes...
Date Wed, 10 Oct 2012 12:10:17 GMT
Author: sergeyb
Date: Wed Oct 10 12:10:16 2012
New Revision: 1396558

URL: http://svn.apache.org/viewvc?rev=1396558&view=rev
Log:
Merged revisions 1396553 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1396553 | sergeyb | 2012-10-10 12:57:11 +0100 (Wed, 10 Oct 2012) | 13 lines
  
  Merged revisions 1396302,1396550 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1396302 | sergeyb | 2012-10-09 21:42:29 +0100 (Tue, 09 Oct 2012) | 1 line
    
    [CXF-4552] Collections of parts annotated with @Multipart are nor processed with form
data payloads containing a single file only
  ........
    r1396550 | sergeyb | 2012-10-10 12:40:35 +0100 (Wed, 10 Oct 2012) | 1 line
    
    [CXF-4349] Reverting some of the updates, using a workaround to get xsi:type generated
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1396302,1396550
  Merged /cxf/branches/2.6.x-fixes:r1396553

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

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Wed Oct 10 12:10:16 2012
@@ -633,13 +633,9 @@ public class ClientProxyImpl extends Abs
             Object body = objs.get(0);
             try {
                 if (bodyIndex != -1) {
-                    Class<?> paramClass = method.getParameterTypes()[bodyIndex];
                     Type paramType = method.getGenericParameterTypes()[bodyIndex];
                     
-                    boolean isAssignable = paramClass.isAssignableFrom(body.getClass());
-                    writeBody(body, outMessage,
-                              isAssignable ? paramClass : body.getClass(),
-                              isAssignable ? paramType : body.getClass(),
+                    writeBody(body, outMessage, body.getClass(), paramType,
                               anns, headers, os);
                 } else {
                     writeBody(body, outMessage, body.getClass(), body.getClass(), 

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Wed Oct 10 12:10:16 2012
@@ -206,8 +206,7 @@ public class JAXRSOutInterceptor extends
             invoked = ori == null ? null : ori.getAnnotatedMethod() == null
                 ? ori.getMethodToInvoke() : ori.getAnnotatedMethod();
         }
-        
-        Class<?> targetType = getRawResponseClass(invoked, responseObj);
+        Class<?> targetType = getRawResponseClass(responseObj);
         Type genericType = getGenericResponseType(invoked, responseObj, targetType);
         if (genericType instanceof TypeVariable) {
             genericType = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),

@@ -407,14 +406,12 @@ public class JAXRSOutInterceptor extends
         
     }
     
-    private Class<?> getRawResponseClass(Method invoked, Object targetObject) {
+    private Class<?> getRawResponseClass(Object targetObject) {
         if (GenericEntity.class.isAssignableFrom(targetObject.getClass())) {
             return ((GenericEntity)targetObject).getRawType();
         } else {
             Class<?> targetClass = targetObject.getClass();
-            Class<?> responseClass = invoked == null 
-                || !invoked.getReturnType().isAssignableFrom(targetClass) ? targetClass :
invoked.getReturnType(); 
-            return ClassHelper.getRealClassFromClass(responseClass);
+            return ClassHelper.getRealClassFromClass(targetClass);
         }
     }
     

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Wed Oct 10 12:10:16 2012
@@ -113,7 +113,7 @@ public abstract class AbstractJAXBProvid
     private String catalogLocation;
     private String collectionWrapperName;
     private Map<String, String> collectionWrapperMap;
-    private List<String> jaxbElementClassNames = Collections.emptyList();
+    private List<String> jaxbElementClassNames;
     private Map<String, Object> cProperties;
     private Map<String, Object> uProperties;
     
@@ -221,19 +221,34 @@ public abstract class AbstractJAXBProvid
     protected Object convertToJaxbElementIfNeeded(Object obj, Class<?> cls, Type genericType)

         throws Exception {
         
-        boolean asJaxbElement = jaxbElementClassNames.contains(cls.getName());
+        Class<?> jaxbElementCls = jaxbElementClassNames == null ? null : getJaxbElementClass(cls);
+        boolean asJaxbElement = jaxbElementCls != null;
         if (!asJaxbElement && isXmlRoot(cls)) {
             return obj;
         }
-        
+        if (jaxbElementCls == null) {
+            jaxbElementCls = cls;
+        }
         QName name = null;
-        String expandedName = jaxbElementClassMap.get(cls.getName());
+        String expandedName = jaxbElementClassMap.get(jaxbElementCls.getName());
         if (expandedName != null) {
             name = JAXRSUtils.convertStringToQName(expandedName);
         } else if (marshalAsJaxbElement || asJaxbElement) {
-            name = getJaxbQName(cls, genericType, obj, false);
+            name = getJaxbQName(jaxbElementCls, genericType, obj, false);
         }
-        return name != null ? new JAXBElement(name, cls, null, obj) : obj;
+        return name != null ? new JAXBElement(name, jaxbElementCls, null, obj) : obj;
+    }
+    
+    protected Class<?> getJaxbElementClass(Class<?> cls) {
+        if (cls == Object.class) {
+            return null;
+        }
+        if (jaxbElementClassNames.contains(cls.getName())) {
+            return cls;    
+        } else {
+            return getJaxbElementClass(cls.getSuperclass());
+        }
+        
     }
     
     public void setCollectionWrapperName(String wName) {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Wed Oct 10 12:10:16 2012
@@ -195,25 +195,37 @@ public class MultipartProvider extends A
         } else if (Attachment.class.isAssignableFrom(c)) {
             return multipart;
         } else {
+            boolean isCollection = Collection.class.isAssignableFrom(c);
+            boolean isRecursive = false;
             if (mediaTypeSupported(multipart.getContentType())) {
                 mc.put("org.apache.cxf.multipart.embedded", true);
                 mc.put("org.apache.cxf.multipart.embedded.ctype", multipart.getContentType());
                 mc.put("org.apache.cxf.multipart.embedded.input", 
                        multipart.getDataHandler().getInputStream());
                 anns = new Annotation[]{};
+                isRecursive = true;
             }
-            MessageBodyReader<Object> r = 
-                mc.getProviders().getMessageBodyReader((Class)c, t, anns, multipart.getContentType());
-            if (r != null) {
-                InputStream is = multipart.getDataHandler().getInputStream();
-                is = decodeIfNeeded(multipart, is);
-                return r.readFrom((Class)c, t, anns, multipart.getContentType(), multipart.getHeaders(),

-                                  is);
+            if (isCollection && !isRecursive) {
+                c = convertTypeToClass(t);
+                return Collections.singletonList(fromAttachment(multipart, c, c, anns));
+            } else {
+                MessageBodyReader<Object> r = 
+                    mc.getProviders().getMessageBodyReader((Class)c, t, anns, multipart.getContentType());
+                if (r != null) {
+                    InputStream is = multipart.getDataHandler().getInputStream();
+                    is = decodeIfNeeded(multipart, is);
+                    return r.readFrom((Class)c, t, anns, multipart.getContentType(), multipart.getHeaders(),
is);
+                }
             }
         }
         return null;
     }
     
+    @SuppressWarnings("unchecked")
+    private <T> Class<T> convertTypeToClass(Type t) {
+        return (Class<T>)InjectionUtils.getActualType(t, 0);
+    }
+    
     private InputStream decodeIfNeeded(Attachment multipart, InputStream is) {
         String value = multipart.getHeader("Content-Transfer-Encoding");
         if ("base64".equals(value) || "quoted-printable".equals(value)) {

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Wed Oct 10 12:10:16 2012
@@ -126,6 +126,12 @@ public class BookStore {
     }
     
     @GET
+    @Path("object")
+    public Object getBookAsObject() {
+        return new Book("Book as Object", 125L);
+    }
+    
+    @GET
     @Path("/default")
     @Produces("application/xml")
     public Book getDefaultBook() {

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Oct 10 12:10:16 2012
@@ -76,7 +76,7 @@ public class JAXRSClientServerBookTest e
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
         createStaticBus();
     }
     
@@ -149,6 +149,16 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookAsObject() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/object"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        Book b = wc.get(Book.class);
+        assertEquals("Book as Object", b.getName());
+    }
+    
+    @Test
     public void testProcessingInstruction() throws Exception {
         String base = "http://localhost:" + PORT;
         String endpointAddress = base + "/bookstore/name-in-query"; 

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Wed Oct 10 12:10:16 2012
@@ -135,6 +135,12 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testBookJSONFormOneFileWhereManyExpected() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/filesform/singlefile";
+        doAddFormBook(address, "attachmentFormJsonFile", 200);               
+    }
+    
+    @Test
     public void testBookJSONFormTwoFilesMixUp() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/filesform/mixup";
         doAddFormBook(address, "attachmentFormJsonFiles", 200);               

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1396558&r1=1396557&r2=1396558&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Wed Oct 10 12:10:16 2012
@@ -444,6 +444,26 @@ public class MultipartStore {
     }
     
     @POST
+    @Path("/books/filesform/singlefile")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookFilesFormSingleFile(@Multipart("owner") String name, 
+                                     @Multipart("file") List<Book> books) 
+        throws Exception {
+        if (books.size() != 1) {
+            throw new WebApplicationException();
+        }
+        Book b = books.get(0);
+        if (!"CXF in Action - 1".equals(b.getName())
+            || !"Larry".equals(name)) {
+            throw new WebApplicationException();
+        }
+        b.setId(124);
+        b.setName("CXF in Action - 2");
+        return Response.ok(b).build();
+    }
+    
+    @POST
     @Path("/books/filesform/mixup")
     @Produces("text/xml")
     @Consumes("multipart/form-data")



Mime
View raw message