cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r947077 - in /cxf/branches/2.2.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/attachment/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 21 May 2010 17:16:39 GMT
Author: sergeyb
Date: Fri May 21 17:16:38 2010
New Revision: 947077

URL: http://svn.apache.org/viewvc?rev=947077&view=rev
Log:
Merged revisions 947071 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r947071 | sergeyb | 2010-05-21 17:58:35 +0100 (Fri, 21 May 2010) | 2 lines
  
  Updating rt Attachment to save headers without converting them to lower case
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
    cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:947071

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

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java?rev=947077&r1=947076&r2=947077&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentImpl.java
Fri May 21 17:16:38 2010
@@ -58,11 +58,12 @@ public class AttachmentImpl implements A
     }
 
     public void setHeader(String name, String value) {
-        headers.put(name.toLowerCase(), value);
+        headers.put(name, value);
     }
 
     public String getHeader(String name) {
-        return headers.get(name.toLowerCase());
+        String value = headers.get(name);
+        return value == null ? headers.get(name.toLowerCase()) : value;
     }
     
     public Iterator<String> getHeaderNames() {

Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java?rev=947077&r1=947076&r2=947077&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
Fri May 21 17:16:38 2010
@@ -106,7 +106,7 @@ public class AttachmentSerializer {
             .append(bodyBoundary)
             .append("\"; ")
             .append("start=\"<")
-            .append(rootContentId)
+            .append(checkAngleBrackets(rootContentId))
             .append(">\"; ")
             .append("start-info=\"")
             .append(bodyCt)
@@ -167,11 +167,8 @@ public class AttachmentSerializer {
         writer.write("Content-Transfer-Encoding: binary\r\n");
 
         if (attachmentId != null) {
+            attachmentId = checkAngleBrackets(attachmentId);
             writer.write("Content-ID: <");
-            if (attachmentId.charAt(0) == '<'
-                && attachmentId.charAt(attachmentId.length() - 1) == '>') {
-                attachmentId = attachmentId.substring(1, attachmentId.length() - 1);
-            }
             writer.write(URLDecoder.decode(attachmentId, "UTF-8"));
             writer.write(">\r\n");
         }
@@ -196,6 +193,13 @@ public class AttachmentSerializer {
         writer.write("\r\n");
     }
 
+    private static String checkAngleBrackets(String value) { 
+        if (value.charAt(0) == '<' && value.charAt(value.length() - 1) == '>')
{
+            return value.substring(1, value.length() - 1);
+        }    
+        return value;
+    }
+    
     /**
      * Write the end of the body boundary and any attachments included.
      * @throws IOException

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java?rev=947077&r1=947076&r2=947077&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
Fri May 21 17:16:38 2010
@@ -120,7 +120,7 @@ public class Attachment {
     }
 
     public MultivaluedMap<String, String> getHeaders() {
-        return new MetadataMap<String, String>(headers);
+        return new MetadataMap<String, String>(headers, false, true);
     }
     
     @Override

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=947077&r1=947076&r2=947077&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Fri May 21 17:16:38 2010
@@ -35,6 +35,7 @@ import javax.activation.DataHandler;
 import javax.imageio.ImageIO;
 import javax.mail.util.ByteArrayDataSource;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Unmarshaller;
 
@@ -49,6 +50,7 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.provider.JSONProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
@@ -323,7 +325,7 @@ public class JAXRSMultipartTest extends 
         InputStream is1 = 
             getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
         List<Attachment> objects = new ArrayList<Attachment>();
-        objects.add(new Attachment("theroot", MediaType.APPLICATION_XML, jaxb));
+        objects.add(new Attachment("<theroot>", MediaType.APPLICATION_XML, jaxb));
         objects.add(new Attachment("thejson", MediaType.APPLICATION_JSON, json));
         objects.add(new Attachment("theimage", MediaType.APPLICATION_OCTET_STREAM, is1));
         Collection<? extends Attachment> coll = client.postAndGetCollection(objects,
Attachment.class);
@@ -393,7 +395,12 @@ public class JAXRSMultipartTest extends 
         client.type("multipart/form-data").accept("multipart/form-data");
         
         ContentDisposition cd = new ContentDisposition("attachment;filename=java.jpg");
-        Attachment att = new Attachment("image", is1, cd);
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-ID", "image");
+        headers.putSingle("Content-Disposition", cd.toString());
+        headers.putSingle("Content-Location", "http://host/bar");
+        headers.putSingle("custom-header", "custom");
+        Attachment att = new Attachment(is1, headers);
         
         MultipartBody body = new MultipartBody(att);
         MultipartBody body2 = client.post(body, MultipartBody.class);
@@ -405,13 +412,14 @@ public class JAXRSMultipartTest extends 
         ContentDisposition cd2 = body2.getRootAttachment().getContentDisposition();
         assertEquals("attachment;filename=java.jpg", cd2.toString());
         assertEquals("java.jpg", cd2.getParameter("filename"));
+        assertEquals("http://host/location", body2.getRootAttachment().getHeader("Content-Location"));
     }
     
     @Test
     public void testUploadImageFromForm2() throws Exception {
         File file = 
             new File(getClass().getResource("/org/apache/cxf/systest/jaxrs/resources/java.jpg").getFile());
-        String address = "http://localhost:9085/bookstore/books/formimage";
+        String address = "http://localhost:9085/bookstore/books/formimage2";
         WebClient client = WebClient.create(address);
         HTTPConduit conduit = WebClient.getConfig(client).getHttpConduit();
         conduit.getClient().setReceiveTimeout(1000000);

Modified: cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=947077&r1=947076&r2=947077&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Fri May 21 17:16:38 2010
@@ -89,11 +89,36 @@ public class MultipartStore {
     
     
     @POST
+    @Path("/books/formimage2")
+    @Consumes("multipart/form-data")
+    @Produces("multipart/form-data")
+    public MultipartBody addBookFormImage2(MultipartBody image) throws Exception {
+        image.getAllAttachments();
+        return image;
+    }
+    
+    @POST
     @Path("/books/formimage")
     @Consumes("multipart/form-data")
     @Produces("multipart/form-data")
     public MultipartBody addBookFormImage(MultipartBody image) throws Exception {
-        return image;
+        List<Attachment> atts = image.getAllAttachments();
+        if (atts.size() != 1) {
+            throw new WebApplicationException();
+        }
+        List<Attachment> newAtts = new ArrayList<Attachment>();
+        Attachment at = atts.get(0);
+        MultivaluedMap<String, String> headers = at.getHeaders();
+        if (!"http://host/bar".equals(headers.getFirst("Content-Location"))) {
+            throw new WebApplicationException();
+        }
+        if (!"custom".equals(headers.getFirst("Custom-Header"))) {
+            throw new WebApplicationException();
+        }
+        headers.putSingle("Content-Location", "http://host/location");
+        newAtts.add(new Attachment(at.getContentId(), at.getDataHandler(), headers));
+        
+        return new MultipartBody(newAtts);
     }
     
     @POST



Mime
View raw message