Author: sergeyb Date: Thu Jan 27 12:07:44 2011 New Revision: 1064099 URL: http://svn.apache.org/viewvc?rev=1064099&view=rev Log: Merged revisions 1064095 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk
........ r1064095 | sergeyb | 2011-01-27 12:02:00 +0000 (Thu, 27 Jan 2011) | 1 line [CXF-3292] Fixing MultipartProvider to read maps ........ Modified: cxf/branches/2.3.x-fixes/ (props changed) cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Thu Jan 27 12:07:44 2011 @@ -1 +1 @@ -/cxf/trunk:1063042,1063205,1063267,1063340 +/cxf/trunk:1063042,1063205,1063267,1063340,1064095 Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1064099&r1=1064098&r2=1064099&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java (original) +++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java Thu Jan 27 12:07:44 2011 @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -126,8 +127,7 @@ public class MultipartProvider extends A if (Collection.class.isAssignableFrom(c) && AnnotationUtils.getAnnotation(anns, Multipart.class) == null) { - Class<?> actual = InjectionUtils.getActualType(t); - actual = actual != null ? actual : Object.class; + Class<?> actual = getActualType(t, 0); if (Attachment.class.isAssignableFrom(actual)) { return infos; } @@ -137,6 +137,14 @@ public class MultipartProvider extends A } return objects; } + if (Map.class.isAssignableFrom(c)) { + Map<String, Object> map = new LinkedHashMap<String, Object>(infos.size()); + Class<?> actual = getActualType(t, 1); + for (Attachment a : infos) { + map.put(a.getContentType().toString(), fromAttachment(a, actual, actual, anns)); + } + return map; + } if (MultipartBody.class.isAssignableFrom(c)) { return new MultipartBody(infos); } @@ -148,6 +156,16 @@ public class MultipartProvider extends A throw new WebApplicationException(404); } + private Class<?> getActualType(Type type, int pos) { + Class<?> actual = null; + try { + actual = InjectionUtils.getActualType(type, pos); + } catch (Exception ex) { + // ignore; + } + return actual != null && actual != Object.class ? actual : Attachment.class; + } + @SuppressWarnings("unchecked") private Object fromAttachment(Attachment multipart, Class<?> c, Type t, Annotation anns[]) throws IOException { Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1064099&r1=1064098&r2=1064099&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java (original) +++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Thu Jan 27 12:07:44 2011 @@ -353,6 +353,34 @@ public class JAXRSMultipartTest extends } @Test + public void testGetBookJaxbJsonProxy() throws Exception { + String address = "http://localhost:" + PORT; + MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); + + + Map<String, Book> map = client.getBookJaxbJson(); + List<Book> result = new ArrayList<Book>(map.values()); + Book jaxb = result.get(0); + assertEquals("jaxb", jaxb.getName()); + assertEquals(1L, jaxb.getId()); + Book json = result.get(1); + assertEquals("json", json.getName()); + assertEquals(2L, json.getId()); + } + + @Test + public void testGetBookJaxbJsonProxy2() throws Exception { + String address = "http://localhost:" + PORT; + MultipartStore client = JAXRSClientFactory.create(address, MultipartStore.class); + + Map<String, Object> map = client.getBookJaxbJsonObject(); + List<Object> result = new ArrayList<Object>(map.values()); + assertEquals(2, result.size()); + assertTrue(((Attachment)result.get(0)).getContentType().toString().contains("application/xml")); + assertTrue(((Attachment)result.get(1)).getContentType().toString().contains("application/json")); + } + + @Test public void testAddBookJaxbJsonImageAttachments() throws Exception { String address = "http://localhost:" + PORT + "/bookstore/books/jaxbimagejson"; WebClient client = WebClient.create(address); Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1064099&r1=1064098&r2=1064099&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original) +++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Thu Jan 27 12:07:44 2011 @@ -34,11 +34,13 @@ import javax.imageio.ImageIO; import javax.mail.util.ByteArrayDataSource; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; +import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.xml.bind.JAXBContext; @@ -171,6 +173,32 @@ public class MultipartStore { } + @GET + @Path("/books/jaxbjsonimage/read") + @Produces("multipart/mixed") + public Map<String, Book> getBookJaxbJson() throws Exception { + Book jaxb = new Book("jaxb", 1L); + Book json = new Book("json", 2L); + Map<String, Book> objects = new LinkedHashMap<String, Book>(); + objects.put(MediaType.APPLICATION_XML, jaxb); + objects.put(MediaType.APPLICATION_JSON, json); + return objects; + + } + + @GET + @Path("/books/jaxbjsonimage/read-object") + @Produces("multipart/mixed") + public Map<String, Object> getBookJaxbJsonObject() throws Exception { + Book jaxb = new Book("jaxb", 1L); + Book json = new Book("json", 2L); + Map<String, Object> objects = new LinkedHashMap<String, Object>(); + objects.put(MediaType.APPLICATION_XML, jaxb); + objects.put(MediaType.APPLICATION_JSON, json); + return objects; + + } + @POST @Path("/books/stream") @Produces("text/xml")