cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r766101 - in /cxf/trunk: rt/core/src/main/java/org/apache/cxf/attachment/ rt/core/src/test/java/org/apache/cxf/attachment/ systests/src/test/java/org/apache/cxf/systest/provider/
Date Fri, 17 Apr 2009 17:56:29 GMT
Author: dkulp
Date: Fri Apr 17 17:56:29 2009
New Revision: 766101

URL: http://svn.apache.org/viewvc?rev=766101&view=rev
Log:
CHange boundary to be a uuid

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java?rev=766101&r1=766100&r2=766101&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDeserializer.java
Fri Apr 17 17:56:29 2009
@@ -52,7 +52,7 @@
     // TODO: Is there a better way to detect boundaries in the message content?
     // It seems constricting to assume the boundary will start with ----=_Part_
     private static final Pattern INPUT_STREAM_BOUNDARY_PATTERN =
-            Pattern.compile("^--(----=_Part_\\S*)", Pattern.MULTILINE);
+            Pattern.compile("^--(\\S*)");
 
     private boolean lazyLoading = true;
 

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java?rev=766101&r1=766100&r2=766101&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java Fri
Apr 17 17:56:29 2009
@@ -48,8 +48,8 @@
      */
     public void writeProlog() throws IOException {
         // Create boundary for body
-        bodyBoundary = AttachmentUtil.getUniqueBoundaryValue(0);
-        
+        bodyBoundary = AttachmentUtil.getUniqueBoundaryValue();
+
         String bodyCt = (String) message.get(Message.CONTENT_TYPE);
         bodyCt = bodyCt.replaceAll("\"", "\\\"");
         

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=766101&r1=766100&r2=766101&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Fri Apr
17 17:56:29 2009
@@ -32,6 +32,7 @@
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 import java.util.UUID;
 
 import javax.activation.DataHandler;
@@ -46,6 +47,8 @@
     private static volatile int counter;
     private static final String ATT_UUID = UUID.randomUUID().toString();
     
+    private static final Random BOUND_RANDOM = new Random();
+    
     private AttachmentUtil() {
 
     }
@@ -73,12 +76,27 @@
         return URLEncoder.encode(name, "UTF-8") + "@" + URLEncoder.encode(cid, "UTF-8");
     }
 
-    public static String getUniqueBoundaryValue(int part) {
-        StringBuffer s = new StringBuffer();
-        // Unique string is ----=_Part_<part>_<hashcode>.<currentTime>
-        s.append("----=_Part_").append(part++).append("_").append(s.hashCode()).append('.').append(
-                System.currentTimeMillis());
-        return s.toString();
+    public static String getUniqueBoundaryValue() {
+        //generate a random UUID.
+        //we don't need the cryptographically secure random uuid that
+        //UUID.randomUUID() will produce.  Thus, use a faster
+        //pseudo-random thing
+        long leastSigBits = 0;
+        long mostSigBits = 0;
+        synchronized (BOUND_RANDOM) {
+            mostSigBits = BOUND_RANDOM.nextLong();
+            leastSigBits = BOUND_RANDOM.nextLong();
+        }
+        
+        mostSigBits &= 0xFFFFFFFFFFFF0FFFL;  //clear version
+        mostSigBits |= 0x0000000000004000L;  //set version
+
+        leastSigBits &= 0x3FFFFFFFFFFFFFFFL; //clear the variant
+        leastSigBits |= 0x8000000000000000L; //set to IETF variant
+        
+        UUID result = new UUID(mostSigBits, leastSigBits);
+        
+        return "uuid:" + result.toString();
     }
 
     public static String getAttchmentPartHeader(Attachment att) {
@@ -88,7 +106,11 @@
         if (att.isXOP()) {
             buffer.append("Content-Transfer-Encoding: binary\r\n");
         }
-        buffer.append("Content-ID: <" + att.getId() + ">\r\n\r\n");
+        String id = att.getId();
+        if (id.charAt(0) == '<') {
+            id = id.substring(1, id.length() - 1);
+        }
+        buffer.append("Content-ID: <" + id + ">\r\n\r\n");
         return buffer.toString();
     }
 

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=766101&r1=766100&r2=766101&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Fri Apr 17 17:56:29 2009
@@ -240,6 +240,8 @@
         assertTrue(attIs.read() == 'a');
         assertTrue(attIs.read() == 'r');
         assertTrue(attIs.read() == -1);
+        
+        assertFalse(itr.hasNext());
     }
     
     @Test

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java?rev=766101&r1=766100&r2=766101&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/provider/AttachmentProviderXMLClientServerTest.java
Fri Apr 17 17:56:29 2009
@@ -64,8 +64,8 @@
         assertTrue("wrong content type", connection.getContentType().contains("multipart/related"));
         String input = IOUtils.toString(connection.getInputStream());
         
-        int idx = input.indexOf("-----");
-        int idx2 = input.indexOf("-----", idx + 5);
+        int idx = input.indexOf("--uuid");
+        int idx2 = input.indexOf("--uuid", idx + 5);
         String root = input.substring(idx, idx2);
         idx = root.indexOf("\r\n\r\n");
         root = root.substring(idx).trim();



Mime
View raw message