cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r990593 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/jav...
Date Sun, 29 Aug 2010 15:08:39 GMT
Author: sergeyb
Date: Sun Aug 29 15:08:38 2010
New Revision: 990593

URL: http://svn.apache.org/viewvc?rev=990593&view=rev
Log:
Addressing various JAXRS issues reported recently

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/MessageContextImpl.java
Sun Aug 29 15:08:38 2010
@@ -48,6 +48,7 @@ import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.AttachmentOutInterceptor;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.jaxrs.impl.ProvidersImpl;
 import org.apache.cxf.jaxrs.interceptor.AttachmentInputInterceptor;
 import org.apache.cxf.jaxrs.interceptor.AttachmentOutputInterceptor;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -228,7 +229,8 @@ public class MessageContextImpl implemen
         try {
             Attachment first = new Attachment(AttachmentUtil.createAttachment(
                                      inMessage.getContent(InputStream.class), 
-                                     (InternetHeaders)inMessage.get(InternetHeaders.class.getName())));
+                                     (InternetHeaders)inMessage.get(InternetHeaders.class.getName())),
+                                     new ProvidersImpl(inMessage));
             newAttachments.add(first);
         } catch (IOException ex) {
             throw new WebApplicationException(500);
@@ -241,7 +243,7 @@ public class MessageContextImpl implemen
         }
         childAttachments.size();
         for (org.apache.cxf.message.Attachment a : childAttachments) {
-            newAttachments.add(new Attachment(a));
+            newAttachments.add(new Attachment(a, new ProvidersImpl(inMessage)));
         }
         MediaType mt = embeddedAttachment 
             ? (MediaType)inMessage.get("org.apache.cxf.multipart.embedded.ctype")

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
Sun Aug 29 15:08:38 2010
@@ -19,13 +19,17 @@
 package org.apache.cxf.jaxrs.ext.multipart;
 
 import java.io.InputStream;
+import java.lang.annotation.Annotation;
 import java.util.Iterator;
 import java.util.List;
 
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.Providers;
 
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 
@@ -35,8 +39,10 @@ public class Attachment {
     private MultivaluedMap<String, String> headers = 
         new MetadataMap<String, String>(false, true);
     private Object object;
+    private Providers providers;
     
-    public Attachment(org.apache.cxf.message.Attachment a) {
+    public Attachment(org.apache.cxf.message.Attachment a,
+                      Providers providers) {
         handler = a.getDataHandler();
         for (Iterator<String> i = a.getHeaderNames(); i.hasNext();) {
             String name = i.next();
@@ -46,6 +52,7 @@ public class Attachment {
             headers.add(name, a.getHeader(name));
         }
         headers.putSingle("Content-ID", a.getId());
+        this.providers = providers;
     }
     
     public Attachment(String id, DataHandler dh, MultivaluedMap<String, String> headers)
{
@@ -100,6 +107,22 @@ public class Attachment {
         return object;
     }
     
+    public <T> T getObject(Class<T> cls) {
+        if (providers != null) {
+            MessageBodyReader<T> mbr = 
+                providers.getMessageBodyReader(cls, cls, new Annotation[]{}, getContentType());
+            if (mbr != null) {
+                try {
+                    return mbr.readFrom(cls, cls, new Annotation[]{}, getContentType(), 
+                                        headers, getDataHandler().getInputStream());
+                } catch (Exception ex) {
+                    throw new WebApplicationException(ex);
+                }
+            }
+        }
+        return null;
+    }
+    
     public String getHeader(String name) {
         List<String> header = headers.get(name);
         if (header == null || header.size() == 0) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
Sun Aug 29 15:08:38 2010
@@ -88,4 +88,12 @@ public class MultipartBody {
         }
         return null;
     }
+    
+    public <T> T getAttachmentObject(String contentId, Class<T> cls) {
+        Attachment att = getAttachment(contentId);
+        if (att != null) {
+            return att.getObject(cls);
+        }
+        return null;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Sun Aug 29 15:08:38 2010
@@ -76,19 +76,21 @@ public class UriBuilderImpl extends UriB
     }
 
     private URI doBuild(boolean fromEncoded, Object... values) {
-        try {
-            String thePath = buildPath(fromEncoded);
-            URITemplate pathTempl = new URITemplate(thePath);
-            thePath = substituteVarargs(pathTempl, values, 0);
-            
-            String theQuery = buildQuery(fromEncoded);
-            if (theQuery != null) {
-                URITemplate queryTempl = new URITemplate(theQuery);
-                int lengthDiff = values.length - pathTempl.getVariables().size(); 
-                if (lengthDiff > 0) {
-                    theQuery = substituteVarargs(queryTempl, values, values.length - lengthDiff);
-                }
+        
+        String thePath = buildPath(fromEncoded);
+        URITemplate pathTempl = new URITemplate(thePath);
+        thePath = substituteVarargs(pathTempl, values, 0);
+        
+        String theQuery = buildQuery(fromEncoded);
+        if (theQuery != null) {
+            URITemplate queryTempl = new URITemplate(theQuery);
+            int lengthDiff = values.length - pathTempl.getVariables().size(); 
+            if (lengthDiff > 0) {
+                theQuery = substituteVarargs(queryTempl, values, values.length - lengthDiff);
             }
+        }
+        
+        try {
             return buildURI(fromEncoded, thePath, theQuery);
         } catch (URISyntaxException ex) {
             throw new UriBuilderException("URI can not be built", ex);
@@ -406,7 +408,7 @@ public class UriBuilderImpl extends UriB
             }
             String rawQuery = uri.getRawQuery();
             if (rawQuery != null) {
-                query = JAXRSUtils.getStructuredParams(rawQuery, "&", false);
+                query = JAXRSUtils.getStructuredParams(rawQuery, "&", false, false);
             }
             userInfo = uri.getUserInfo();
         } else {
@@ -482,7 +484,7 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder replaceMatrix(String matrixValues) throws IllegalArgumentException
{
-        this.matrix = JAXRSUtils.getStructuredParams(matrixValues, ";", true);
+        this.matrix = JAXRSUtils.getStructuredParams(matrixValues, ";", true, false);
         return this;
     }
 
@@ -512,7 +514,7 @@ public class UriBuilderImpl extends UriB
 
     @Override
     public UriBuilder replaceQuery(String queryValue) throws IllegalArgumentException {
-        query = JAXRSUtils.getStructuredParams(queryValue, "&", false);
+        query = JAXRSUtils.getStructuredParams(queryValue, "&", true, false);
         return this;
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriInfoImpl.java Sun
Aug 29 15:08:38 2010
@@ -111,11 +111,13 @@ public class UriInfoImpl implements UriI
     public MultivaluedMap<String, String> getQueryParameters(boolean decode) {
         
         if (!caseInsensitiveQueries) {
-            return JAXRSUtils.getStructuredParams((String)message.get(Message.QUERY_STRING),
"&", decode);
+            return JAXRSUtils.getStructuredParams((String)message.get(Message.QUERY_STRING),

+                              "&", decode, decode);
         }
         
         MultivaluedMap<String, String> queries = new MetadataMap<String, String>(false,
true);
-        JAXRSUtils.getStructuredParams(queries, (String)message.get(Message.QUERY_STRING),
"&", decode);
+        JAXRSUtils.getStructuredParams(queries, (String)message.get(Message.QUERY_STRING),

+                                      "&", decode, decode);
         return queries;
         
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Sun Aug 29 15:08:38 2010
@@ -173,11 +173,11 @@ public final class URITemplate {
             String value = m.group(i++);
             templateVariableToValue.add(name, value);
         }
-
         // The right hand side value, might be used to further resolve
         // sub-resources.
-
-        String finalGroup = m.group(i);
+        int groupCount = m.groupCount();
+        
+        String finalGroup = m.group(groupCount);
         templateVariableToValue.putSingle(FINAL_MATCH_GROUP, finalGroup == null ? "/" : finalGroup);
 
         return true;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/XSLTJaxbProvider.java
Sun Aug 29 15:08:38 2010
@@ -217,7 +217,7 @@ public class XSLTJaxbProvider extends JA
         return outClassesToHandle == null || outClassesToHandle.contains(className); 
     }
     
-    private Templates createTemplates(Templates templates, 
+    protected Templates createTemplates(Templates templates, 
                                       Map<String, Object> configuredParams,
                                       Map<String, String> outProps) {
         if (templates == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sun
Aug 29 15:08:38 2010
@@ -364,17 +364,16 @@ public final class JAXRSUtils {
         
         int status;
         
+        // criteria matched the least number of times will determine the error code;
+        // priority : path, method, consumes, produces;
         if (pathMatched == 0) {
             status = 404;
         } else if (methodMatched == 0) {
             status = 405;
-        } else if (consumeMatched == 0) {
+        } else if (consumeMatched <= produceMatched) {
             status = 415;
-        } else if (produceMatched == 0) {
-            status = 406;
         } else {
-            // this branch should not even be executed 
-            status = 404;
+            status = 406;
         }
         
         String name = resource.isRoot() ? "NO_OP_EXC" : "NO_SUBRESOURCE_METHOD_FOUND";
@@ -735,7 +734,7 @@ public final class JAXRSUtils {
     public static MultivaluedMap<String, String> getMatrixParams(String path, boolean
decode) {
         int index = path.indexOf(';');
         return index == -1 ? new MetadataMap<String, String>()
-                           : JAXRSUtils.getStructuredParams(path.substring(index + 1), ";",
decode);
+                           : JAXRSUtils.getStructuredParams(path.substring(index + 1), ";",
decode, false);
     }
     
     private static Object processHeaderParam(Message m, 
@@ -917,11 +916,12 @@ public final class JAXRSUtils {
      */
     public static MultivaluedMap<String, String> getStructuredParams(String query,

                                                                     String sep, 
-                                                                    boolean decode) {
+                                                                    boolean decode,
+                                                                    boolean decodePlus) {
         MultivaluedMap<String, String> map = 
             new MetadataMap<String, String>(new LinkedHashMap<String, List<String>>());
         
-        getStructuredParams(map, query, sep, decode);
+        getStructuredParams(map, query, sep, decode, decodePlus);
         
         return map;
     }
@@ -929,7 +929,8 @@ public final class JAXRSUtils {
     public static void getStructuredParams(MultivaluedMap<String, String> queries,
                                            String query, 
                                            String sep, 
-                                           boolean decode) {
+                                           boolean decode,
+                                           boolean decodePlus) {
         if (!StringUtils.isEmpty(query)) {            
             List<String> parts = Arrays.asList(query.split(sep));
             for (String part : parts) {
@@ -938,8 +939,8 @@ public final class JAXRSUtils {
                 if (values.length == 1) {
                     value = "";
                 } else if (decode) {
-                    value = "&".equals(sep) ? HttpUtils.urlDecode(values[1]) 
-                                            : HttpUtils.pathDecode(values[1]); 
+                    value = (";".equals(sep) || !decodePlus)
+                        ? HttpUtils.pathDecode(values[1]) : HttpUtils.urlDecode(values[1]);

                 } else {
                     value = values[1];
                 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/UriBuilderImplTest.java
Sun Aug 29 15:08:38 2010
@@ -726,9 +726,9 @@ public class UriBuilderImplTest extends 
         assertEquals("Unexpected fragment", uri1.getFragment(), uri2.getFragment());
         
         MultivaluedMap<String, String> queries1 = 
-            JAXRSUtils.getStructuredParams(uri1.getRawQuery(), "&", false);
+            JAXRSUtils.getStructuredParams(uri1.getRawQuery(), "&", false, false);
         MultivaluedMap<String, String> queries2 = 
-            JAXRSUtils.getStructuredParams(uri2.getRawQuery(), "&", false);
+            JAXRSUtils.getStructuredParams(uri2.getRawQuery(), "&", false, false);
         assertEquals("Unexpected queries", queries1, queries2);
     }
     
@@ -906,7 +906,6 @@ public class UriBuilderImplTest extends 
     }
     
     @Test
-    @Ignore("This may need to be challenged, '23' overrides '=' for the 2nd occurence of
x")
     public void testFromEncodedDuplicateVar() {
         String expected = "http://localhost:8080/a/%25/=/%25G0/%25/=";
 
@@ -917,7 +916,6 @@ public class UriBuilderImplTest extends 
     }
     
     @Test
-    @Ignore("name2=%20 is double encoded after the replacement -> name2=%2520")
     public void testReplaceQuery5() {
         String expected = "http://localhost:8080?name1=x&name2=%20&name3=x+y&name4=23&name5=x%20y";
 
@@ -928,7 +926,7 @@ public class UriBuilderImplTest extends 
     }
     
     @Test
-    @Ignore("query parameters are not encoded due to build() being called")
+    @Ignore
     public void testQueryParam() {
         String expected = "http://localhost:8080?name=x%3D&name=y?&name=x+y&name=%26";
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Sun Aug 29 15:08:38 2010
@@ -249,7 +249,50 @@ public class URITemplateTest extends Ass
         assertFalse(uriTemplate.match("/books/abcd", values));
         assertFalse(uriTemplate.match("/books/abc", values));
     }
+    
+    @Test
+    public void testExpressionWithNestedGroup() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/{resource:.+\\.(js|css|gif|png)}");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/script.js", values));
+        assertEquals("script.js", values.getFirst("resource"));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+        values.clear();
+        
+        assertTrue(uriTemplate.match("/script.js/bar", values));
+        assertEquals("script.js", values.getFirst("resource"));
+        finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/bar", finalPath);
+        values.clear();
+        
+        assertFalse(uriTemplate.match("/script.pdf", values));
+    }
+
+    @Test
+    public void testExpressionWithNestedGroup2() throws Exception {
+        URITemplate uriTemplate = 
+            new URITemplate("/{resource:.+\\.(js|css|gif|png)}/bar");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
 
+        assertTrue(uriTemplate.match("/script.js/bar/baz", values));
+        assertEquals("script.js", values.getFirst("resource"));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/baz", finalPath);
+    }
+    
+    @Test
+    public void testLiteralExpression() throws Exception {
+        URITemplate uriTemplate = 
+            new URITemplate("/bar");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/bar/baz", values));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/baz", finalPath);
+    }
+    
     @Test
     public void testMultipleExpression2() throws Exception {
         URITemplate uriTemplate = new URITemplate("/books/{bookId:123}/chapter/{id}");

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Sun Aug 29 15:08:38 2010
@@ -194,6 +194,12 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testAddBookAsJAXBBody() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/jaxb-body";
+        doAddBook(address, "attachmentData", 200);               
+    }
+    
+    @Test
     public void testAddBookAsListOfAttachments() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/listattachments";
         doAddBook(address, "attachmentData", 200);               

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=990593&r1=990592&r2=990593&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Sun Aug 29 15:08:38 2010
@@ -268,6 +268,24 @@ public class MultipartStore {
     }
     
     @POST
+    @Path("/books/jaxb-body")
+    @Consumes("multipart/related;type=\"text/xml\"")
+    @Produces("text/xml")
+    public Response addBookParts2(MultipartBody body) 
+        throws Exception {
+        Book b1 = body.getAttachmentObject("rootPart", Book.class);
+        Book b2 = body.getAttachmentObject("book2", Book.class);
+        if (b1.equals(b2)) {
+            throw new WebApplicationException();
+        }
+        if (!b1.getName().equals(b2.getName())) {
+            throw new WebApplicationException();
+        }
+        b1.setId(124);
+        return Response.ok(b1).build();
+    }
+    
+    @POST
     @Path("/books/jaxbonly")
     @Consumes("multipart/mixed")
     @Produces("multipart/mixed;type=text/xml")



Mime
View raw message