cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1360869 - in /cxf/branches/2.5.x-fixes: rt/core/src/main/java/org/apache/cxf/attachment/ systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ systests/uncategorized/src/test/resources/ testutils/src/main/java/org/apache/cxf/mt...
Date Thu, 12 Jul 2012 19:24:15 GMT
Author: dkulp
Date: Thu Jul 12 19:24:15 2012
New Revision: 1360869

URL: http://svn.apache.org/viewvc?rev=1360869&view=rev
Log:
Merged revisions 1360678 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

........
  r1360678 | dkulp | 2012-07-12 09:47:50 -0400 (Thu, 12 Jul 2012) | 10 lines

  Merged revisions 1360644 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1360644 | ffang | 2012-07-12 07:58:42 -0400 (Thu, 12 Jul 2012) | 2 lines

    [CXF-4420]CXF JAXWS MTOM should be able to extract Content-Disposition and setName accordingly
for AttachmentDataSource

  ........

........

Added:
    cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp   (with props)
Modified:
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
    cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
    cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
    cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=1360869&r1=1360868&r2=1360869&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
Thu Jul 12 19:24:15 2012
@@ -35,6 +35,7 @@ public class AttachmentDataSource implem
     private CachedOutputStream cache;
     private InputStream ins;
     private DelegatingInputStream delegate;
+    private String name;
     
     public AttachmentDataSource(String ctParam, InputStream inParam) throws IOException {
         this.ct = ctParam;        
@@ -86,7 +87,11 @@ public class AttachmentDataSource implem
     }
 
     public String getName() {
-        return null;
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
     }
 
     public OutputStream getOutputStream() throws IOException {

Modified: cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1360869&r1=1360868&r2=1360869&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
Thu Jul 12 19:24:15 2012
@@ -34,6 +34,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
+import java.util.StringTokenizer;
 import java.util.UUID;
 
 import javax.activation.CommandMap;
@@ -45,6 +46,7 @@ import javax.activation.URLDataSource;
 import javax.mail.Header;
 import javax.mail.internet.InternetHeaders;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.HttpHeaderHelper;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
@@ -213,6 +215,24 @@ public final class AttachmentUtil {
         AttachmentImpl att = new AttachmentImpl(id);
         
         final String ct = headers.getHeader("Content-Type", null);
+        String cd = headers.getHeader("Content-Disposition", null);
+        String fileName = null;
+        if (!StringUtils.isEmpty(cd)) {
+            StringTokenizer token = new StringTokenizer(cd, ";");
+            while (token.hasMoreElements()) {
+                fileName = token.nextToken();
+                if (fileName.startsWith("name=")) {
+                    break;
+                }
+            }
+            if (!StringUtils.isEmpty(fileName)) {
+                if (fileName.indexOf("\"") > 0) {
+                    fileName = fileName.substring(fileName.indexOf("\"") + 1, fileName.lastIndexOf("\""));
+                } else {
+                    fileName = fileName.substring(fileName.indexOf("=") + 1);
+                }
+            }
+        }
         
         boolean quotedPrintable = false;
         
@@ -231,9 +251,15 @@ public final class AttachmentUtil {
         if (quotedPrintable) {
             DataSource source = new AttachmentDataSource(ct, 
                                                          new QuotedPrintableDecoderStream(stream));
+            if (!StringUtils.isEmpty(fileName)) {
+                ((AttachmentDataSource)source).setName(fileName);
+            }
             att.setDataHandler(new DataHandler(source));
         } else {
             DataSource source = new AttachmentDataSource(ct, stream);
+            if (!StringUtils.isEmpty(fileName)) {
+                ((AttachmentDataSource)source).setName(fileName);
+            }
             att.setDataHandler(new DataHandler(source));
         }
         
@@ -313,6 +339,14 @@ public final class AttachmentUtil {
             throw new Fault(e);
         }
         AttachmentImpl att = new AttachmentImpl(id, handler);
+        if (!StringUtils.isEmpty(handler.getName())) {
+            //set Content-Disposition attachment header if filename isn't null
+            String file = handler.getName();
+            if (StringUtils.isFileExist(file)) {
+                file = file.substring(file.lastIndexOf(File.separator) + 1);
+            }
+            att.setHeader("Content-Disposition", "attachment;name=\"" + file + "\"");
+        }
         att.setXOP(isXop);
         return att;
     }

Modified: cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=1360869&r1=1360868&r2=1360869&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
Thu Jul 12 19:24:15 2012
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.UndeclaredThrowableException;
+import java.net.URL;
 
 import javax.activation.DataHandler;
 import javax.mail.util.ByteArrayDataSource;
@@ -185,6 +186,40 @@ public class ClientMtomXopTest extends A
             throw ex;
         }
     }
+    
+    @Test
+    public void testMtomWithFileName() throws Exception {
+        TestMtom mtomPort = createPort(MTOM_SERVICE, MTOM_PORT, TestMtom.class, true, true);
+        try {
+            Holder<DataHandler> param = new Holder<DataHandler>();
+            Holder<String> name; 
+                        
+            URL fileURL = getClass().getClassLoader().getResource("me.bmp");
+            
+            ((BindingProvider)mtomPort).getRequestContext().put("schema-validation-enabled",
+                                                                Boolean.TRUE);
+            param.value = new DataHandler(fileURL);
+            name = new Holder<String>("have name");
+            mtomPort.testXop(name, param);
+            assertEquals("can't get file name", "return detail + me.bmp", name.value);
+            assertNotNull(param.value);
+                      
+           
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        } catch (Exception ex) {
+            if (ex.getMessage().contains("Connection reset")
+                && System.getProperty("java.specification.version", "1.5").contains("1.6"))
{
+                //There seems to be a bug/interaction with Java 1.6 and Jetty where
+                //Jetty will occasionally send back a RST prior to all the data being 
+                //sent back to the client when using localhost (which is what we do)
+                //we'll ignore for now
+                return;
+            }
+            System.out.println(System.getProperties());
+            throw ex;
+        }
+    }
 
     @org.junit.Ignore // see CXF-1395
     @Test

Added: cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp?rev=1360869&view=auto
==============================================================================
Files cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp (added) and
cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp Thu Jul 12 19:24:15
2012 differ

Propchange: cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp
------------------------------------------------------------------------------
    svn:executable = *

Modified: cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java?rev=1360869&r1=1360868&r2=1360869&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
Thu Jul 12 19:24:15 2012
@@ -35,7 +35,11 @@ import org.apache.cxf.mime.types.XopStri
 public class TestMtomImpl implements TestMtom {
 
     public void testXop(Holder<String> name, Holder<DataHandler> attachinfo)
{
-        name.value = "return detail + " + name.value;
+        if (name.value.equals("have name") && attachinfo.value.getName() != null)
{
+            name.value = "return detail + " + attachinfo.value.getName();
+        } else {
+            name.value = "return detail + " + name.value;
+        }
     }
 
     public XopStringType testXopString(XopStringType data) {



Mime
View raw message