Author: ffang Date: Fri Jul 13 00:13:54 2012 New Revision: 1361011 URL: http://svn.apache.org/viewvc?rev=1361011&view=rev Log: Merged revisions 1360869 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes
................ r1360869 | dkulp | 2012-07-13 03:24:15 +0800 (δΊ”, 13 7 2012) | 17 lines 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.4.x-fixes/systests/uncategorized/src/test/resources/me.bmp - copied unchanged from r1360869, cxf/branches/2.5.x-fixes/systests/uncategorized/src/test/resources/me.bmp Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java cxf/branches/2.4.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/branches/2.5.x-fixes:r1360869 Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=1361011&r1=1361010&r2=1361011&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original) +++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Fri Jul 13 00:13:54 2012 @@ -34,6 +34,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; @@ -84,7 +85,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.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1361011&r1=1361010&r2=1361011&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original) +++ cxf/branches/2.4.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Fri Jul 13 00:13:54 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.message.Attachment; @@ -180,6 +182,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; @@ -198,9 +218,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)); } @@ -280,6 +306,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.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=1361011&r1=1361010&r2=1361011&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original) +++ cxf/branches/2.4.x-fixes/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Fri Jul 13 00:13:54 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; @@ -162,6 +163,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 Modified: cxf/branches/2.4.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java?rev=1361011&r1=1361010&r2=1361011&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java (original) +++ cxf/branches/2.4.x-fixes/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java Fri Jul 13 00:13:54 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) {
