cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r737046 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/main/java/or...
Date Fri, 23 Jan 2009 15:16:22 GMT
Author: sergeyb
Date: Fri Jan 23 07:16:21 2009
New Revision: 737046

URL: http://svn.apache.org/viewvc?rev=737046&view=rev
Log:
JAXRS : handling of multiparts by arbitrary providers 

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
  (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData2
Removed:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AttachmentUtils.java
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MultipartID.java Fri
Jan 23 07:16:21 2009
@@ -27,5 +27,6 @@
 @Target({ElementType.PARAMETER, ElementType.FIELD })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface MultipartID {
-    String value();
+    String value() default "root";
+    String type() default "*/*";
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Fri Jan 23 07:16:21 2009
@@ -19,8 +19,6 @@
 
 package org.apache.cxf.jaxrs.provider;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.List;
@@ -50,7 +48,6 @@
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
-import org.apache.cxf.jaxrs.utils.AttachmentUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 
@@ -59,8 +56,6 @@
     
     protected static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractJAXBProvider.class);
 
-    private static final MediaType MULTIPART_RELATED_TYPE = 
-        MediaType.valueOf("multipart/related");
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractJAXBProvider.class);
     private static final String CHARSET_PARAMETER = "charset"; 
         
@@ -99,17 +94,6 @@
         return mc;
     }
     
-    public InputStream getInputStream(Class<Object> type, Annotation[] anns, MediaType
mt, 
-                                      InputStream is) throws IOException {
-        if (mt.isCompatible(MULTIPART_RELATED_TYPE)) {
-            is = (InputStream)AttachmentUtils.getMultipart(type, anns, mt, getContext(),
is);
-            if (is == null) {
-                throw new WebApplicationException(404);
-            }
-        }
-        return is;
-    }
-    
     @SuppressWarnings("unchecked")
     protected JAXBContext getJAXBContext(Class<?> type, Type genericType) throws JAXBException
{
         if (mc != null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ActivationProvider.java
Fri Jan 23 07:16:21 2009
@@ -35,7 +35,8 @@
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.jaxrs.utils.AttachmentUtils;
+import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
+import org.apache.cxf.jaxrs.utils.multipart.MultipartInfo;
 
 @Provider
 @Consumes("multipart/related")
@@ -45,18 +46,30 @@
     private MessageContext mc;
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,

-                              MediaType mediaType) {
-        return DataSource.class.isAssignableFrom(type)
-               || DataHandler.class.isAssignableFrom(type);
+                              MediaType mt) {
+        if (DataHandler.class.isAssignableFrom(type) || DataSource.class.isAssignableFrom(type)
+            || (mt.getType().equals("multipart") && mt.getSubtype().equals("related")))
{
+            return true;
+        }
+        return false;
     }
 
     public Object readFrom(Class<Object> c, Type t, Annotation[] anns, MediaType mt,

                            MultivaluedMap<String, String> headers, InputStream is)

         throws IOException, WebApplicationException {
-        
-        Object multipart = AttachmentUtils.getMultipart(c, anns, mt, mc, is);
+        MultipartInfo multipart = AttachmentUtils.getMultipart(c, anns, mt, mc, is);
         if (multipart != null) {
-            return multipart;
+            if (InputStream.class.isAssignableFrom(multipart.getPart().getClass())) {
+                MessageBodyReader<Object> r = 
+                    mc.getProviders().getMessageBodyReader(c, t, anns, multipart.getType());
+                if (r != null) {
+                    return r.readFrom(c, t, anns, multipart.getType(), headers, 
+                                           (InputStream)multipart.getPart());
+                }
+            } else {
+                // it's either DataSource or DataHandler
+                return multipart.getPart();
+            }
         }
         throw new WebApplicationException(404);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Jan 23 07:16:21 2009
@@ -45,9 +45,7 @@
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 
 @Produces({"application/xml", "text/xml" })
-@Consumes({"application/xml", "text/xml", 
-           "multipart/related;type=\"text/xml\"",
-           "multipart/related;type=\"application/xml\"" })
+@Consumes({"application/xml", "text/xml" })
 @Provider
 public class JAXBElementProvider extends AbstractJAXBProvider  {
     
@@ -83,10 +81,9 @@
     }
     
     public Object readFrom(Class<Object> type, Type genericType, Annotation[] anns,
MediaType mt, 
-        MultivaluedMap<String, String> headers, InputStream stream) 
+        MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
         try {
-            InputStream is = getInputStream(type, anns, mt, stream);
             Class<?> theType = getActualType(type, genericType);
             Unmarshaller unmarshaller = createUnmarshaller(theType, genericType);
             

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Fri Jan 23 07:16:21 2009
@@ -54,8 +54,7 @@
 import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
 
 @Produces("application/json")
-@Consumes({"application/json",
-           "multipart/related;type=\"application/json\"" })
+@Consumes("application/json")
 @Provider
 public class JSONProvider extends AbstractJAXBProvider  {
     
@@ -100,11 +99,10 @@
     }
 
     public Object readFrom(Class<Object> type, Type genericType, Annotation[] anns,
MediaType mt, 
-        MultivaluedMap<String, String> headers, InputStream stream) 
+        MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
         
         try {
-            InputStream is = getInputStream(type, anns, mt, stream);
             Class<?> theType = getActualType(type, genericType);
             Unmarshaller unmarshaller = createUnmarshaller(theType, genericType);
             

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=737046&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
Fri Jan 23 07:16:21 2009
@@ -0,0 +1,118 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.utils.multipart;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.mail.util.ByteArrayDataSource;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.ext.MultipartID;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
+public final class AttachmentUtils {
+    private static final Logger LOG = LogUtils.getL7dLogger(JAXRSUtils.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSUtils.class);
+    
+    private AttachmentUtils() {
+    }
+    
+    public static Map<String, DataHandler> getAttachments(MessageContext mc) {
+        return CastUtils.cast((Map)mc.get(MessageContext.INBOUND_MESSAGE_ATTACHMENTS));
+    }
+    
+    // TODO : refactor this 'piece'
+    public static MultipartInfo getMultipart(Class<Object> c, Annotation[] anns, 
+         MediaType mt, MessageContext mc, InputStream is) throws IOException {
+        InputStream stream = null;
+        MultipartID id = AnnotationUtils.getAnnotation(anns, MultipartID.class);
+        if (id != null) {
+            String contentId = id.value();
+            String rootId = mt.getParameters().get("start");
+            if (rootId != null) {
+                rootId = rootId.replace("\"", "").replace("'", "");
+                if (rootId.equalsIgnoreCase(contentId)) {
+                    stream = is;
+                }
+            }
+            if (stream == null) {
+                // TODO: looks like the lazy attachments collection can only be accessed
this way
+                for (Map.Entry<String, DataHandler> entry : getAttachments(mc).entrySet())
{
+                    if (entry.getKey().equals(contentId)) {
+                        DataHandler dh = entry.getValue();
+                        MediaType handlerType = dh.getContentType() == null 
+                            ? MediaType.WILDCARD_TYPE : MediaType.valueOf(dh.getContentType());
+                        checkMediaTypes(handlerType, id.type());
+                        Object o =  DataHandler.class.isAssignableFrom(c) ? dh 
+                            : DataSource.class.isAssignableFrom(c) ? dh.getDataSource()
+                            : dh.getInputStream();
+                        return new MultipartInfo(o, handlerType);    
+                    }
+                }
+                org.apache.cxf.common.i18n.Message errorMsg = 
+                    new org.apache.cxf.common.i18n.Message("MULTTIPART_ID_NOT_FOUND", 
+                                                           BUNDLE, 
+                                                           contentId,
+                                                           mt.toString());
+                LOG.warning(errorMsg.toString());
+            }
+        } else {
+            stream = is;
+        }
+        if (stream != null) {
+            MediaType partType = MediaType.WILDCARD_TYPE;
+            String ct = mt.getParameters().get("type");
+            if (ct != null) {
+                partType = MediaType.valueOf(ct.replace("\"", "").replace("'", "")); 
+            }
+            if (id != null) {
+                checkMediaTypes(partType, id.type());
+            }
+            if (DataSource.class.isAssignableFrom(c)) {
+                return new MultipartInfo(new ByteArrayDataSource(stream, mt.toString()),
partType);
+            } else if (DataHandler.class.isAssignableFrom(c)) {
+                return new MultipartInfo(new DataHandler(new ByteArrayDataSource(stream,
mt.toString())),
+                                                         partType);
+            } else {
+                return new MultipartInfo(stream, partType);
+            }
+        }
+        return null;
+    }
+    
+    private static void checkMediaTypes(MediaType mt1, String mt2) {
+        if (!mt1.isCompatible(MediaType.valueOf(mt2))) {                                
           
+            throw new WebApplicationException(415);
+        }
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java?rev=737046&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
Fri Jan 23 07:16:21 2009
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.utils.multipart;
+
+import javax.ws.rs.core.MediaType;
+
+public class MultipartInfo {
+
+    private Object part;
+    private MediaType contentType;
+    
+    public MultipartInfo(Object o, MediaType type) {
+        part = o;
+        contentType = type;
+    }
+    
+    public Object getPart() {
+        return part;
+    }
+    
+    public MediaType getType() {
+        return contentType;
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/MultipartInfo.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Fri Jan 23 07:16:21 2009
@@ -37,76 +37,94 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(MultipartServer.class, true));
+                   launchServer(MultipartServer.class));
     }
     
     @Test
     public void testBookAsRootAttachmentStreamSource() throws Exception {
         String address = "http://localhost:9080/bookstore/books/stream";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testBookAsRootAttachmentInputStream() throws Exception {
         String address = "http://localhost:9080/bookstore/books/istream";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testBookAsMessageContextDataHandler() throws Exception {
         String address = "http://localhost:9080/bookstore/books/mchandlers";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testAddBookAsRootAttachmentJAXB() throws Exception {
         String address = "http://localhost:9080/bookstore/books/jaxb";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testAddBookAsDataSource() throws Exception {
         String address = "http://localhost:9080/bookstore/books/dsource";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testAddBookAsDataSource2() throws Exception {
         String address = "http://localhost:9080/bookstore/books/dsource2";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
     @Test
     public void testAddBookAsJAXB2() throws Exception {
         String address = "http://localhost:9080/bookstore/books/jaxb2";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
+    }
+    
+    @Test
+    public void testAddBookAsJAXBJSON() throws Exception {
+        String address = "http://localhost:9080/bookstore/books/jaxbjson";
+        doAddBook(address, "attachmentData2", 200);               
+    }
+    
+    @Test
+    public void testConsumesMismatch() throws Exception {
+        String address = "http://localhost:9080/bookstore/books/mismatch1";
+        doAddBook(address, "attachmentData2", 415);               
+    }
+    
+    @Test
+    public void testConsumesMismatch2() throws Exception {
+        String address = "http://localhost:9080/bookstore/books/mismatch2";
+        doAddBook(address, "attachmentData2", 415);               
     }
     
     @Test
     public void testAddBookAsDataHandler() throws Exception {
         String address = "http://localhost:9080/bookstore/books/dhandler";
-        doAddBook(address);               
+        doAddBook(address, "attachmentData", 200);               
     }
     
-    private void doAddBook(String address) throws Exception {
+    private void doAddBook(String address, String resourceName, int status) throws Exception
{
         PostMethod post = new PostMethod(address);
         
         String ct = "multipart/related; type=\"text/xml\"; " + "start=\"rootPart\"; "
             + "boundary=\"----=_Part_4_701508.1145579811786\"";
         post.setRequestHeader("Content-Type", ct);
         InputStream is = 
-            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/attachmentData");
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/" + resourceName);
         RequestEntity entity = new InputStreamRequestEntity(is);
         post.setRequestEntity(entity);
         HttpClient httpclient = new HttpClient();
         
         try {
             int result = httpclient.executeMethod(post);
-            assertEquals(200, result);
-            
-            InputStream expected = getClass().getResourceAsStream("resources/expected_add_book.txt");
-            
-            assertEquals(getStringFromInputStream(expected), post.getResponseBodyAsString());
+            assertEquals(status, result);
+            if (status == 200) {
+                InputStream expected = getClass().getResourceAsStream("resources/expected_add_book.txt");
+                assertEquals(getStringFromInputStream(expected), post.getResponseBodyAsString());
+            }
         } finally {
             // Release current connection to the connection pool once you are done
             post.releaseConnection();

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=737046&r1=737045&r2=737046&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Fri
Jan 23 07:16:21 2009
@@ -25,6 +25,7 @@
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
+import javax.ws.rs.Consumes;
 import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -37,7 +38,7 @@
 
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.MultipartID;
-import org.apache.cxf.jaxrs.utils.AttachmentUtils;
+import org.apache.cxf.jaxrs.utils.multipart.AttachmentUtils;
 
 @Path("/bookstore")
 public class MultipartStore {
@@ -75,9 +76,10 @@
     
     @POST
     @Path("/books/jaxb2")
+    @Consumes("multipart/related;type=\"text/xml\"")
     @Produces("text/xml")
-    public Response addBook2(@MultipartID("rootPart") Book b1,
-                             @MultipartID("book2") Book b2) 
+    public Response addBookParts(@MultipartID("rootPart") Book b1,
+                                 @MultipartID("book2") Book b2) 
         throws Exception {
         if (b1.equals(b2)) {
             throw new WebApplicationException();
@@ -90,6 +92,21 @@
     }
     
     @POST
+    @Path("/books/jaxbjson")
+    @Produces("text/xml")
+    public Response addBookJaxbJson(
+        @MultipartID(value = "rootPart", type = "text/xml") Book2 b1,
+        @MultipartID(value = "book2", type = "application/json") Book b2) 
+        throws Exception {
+        if (!"CXF in Action".equals(b1.getName())
+            || !"CXF in Action - 2".equals(b2.getName())) {
+            throw new WebApplicationException();
+        }
+        b2.setId(124);
+        return Response.ok(b2).build();
+    }
+    
+    @POST
     @Path("/books/dsource2")
     @Produces("text/xml")
     public Response addBookFromDataSource2(@MultipartID("rootPart") DataSource ds1,
@@ -136,6 +153,21 @@
         return Response.ok(b).build();
     }
     
+    @POST
+    @Path("/books/mismatch1")
+    @Consumes("multipart/related;type=\"bar/foo\"")
+    @Produces("text/xml")
+    public Response addBookMismatched(Book b) {
+        throw new WebApplicationException();
+    }
+    
+    @POST
+    @Path("/books/mismatch2")
+    @Produces("text/xml")
+    public Response addBookMismatched2(@MultipartID(value = "rootPart", type = "f/b") Book
b) {
+        throw new WebApplicationException();
+    }
+    
     private Response readBookFromInputStream(InputStream is) throws Exception {
         JAXBContext c = JAXBContext.newInstance(new Class[]{Book.class});
         Unmarshaller u = c.createUnmarshaller();

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData2
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData2?rev=737046&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData2 (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/attachmentData2 Fri Jan
23 07:16:21 2009
@@ -0,0 +1,18 @@
+
+------=_Part_4_701508.1145579811786
+Content-Type: text/xml
+Content-ID: <rootPart>
+
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><b:Book xmlns:b="http://www.example.org/books"><b:name>CXF
in Action</b:name><b:id>123</b:id></b:Book>
+------=_Part_4_701508.1145579811786
+Content-Type: image/jpeg
+Content-Transfer-Encoding: binary
+Content-ID: <foo>
+
+foobar
+------=_Part_4_701508.1145579811786--
+Content-Type: application/json
+Content-ID: <book2>
+
+{"Book":{"name":"CXF in Action - 2","id":123}}
+------=_Part_4_701508.1145579811786--
\ No newline at end of file



Mime
View raw message