You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2012/07/12 13:58:42 UTC
svn commit: r1360644 - in /cxf/trunk:
api/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/mtom_xop/
Author: ffang
Date: Thu Jul 12 11:58:42 2012
New Revision: 1360644
URL: http://svn.apache.org/viewvc?rev=1360644&view=rev
Log:
[CXF-4420]CXF JAXWS MTOM should be able to extract Content-Disposition and setName accordingly for AttachmentDataSource
Added:
cxf/trunk/systests/uncategorized/src/test/resources/me.bmp (with props)
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
cxf/trunk/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
Modified: cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java?rev=1360644&r1=1360643&r2=1360644&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentDataSource.java Thu Jul 12 11:58:42 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/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java?rev=1360644&r1=1360643&r2=1360644&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/attachment/AttachmentUtil.java Thu Jul 12 11:58:42 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/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java?rev=1360644&r1=1360643&r2=1360644&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java (original)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/ClientMtomXopTest.java Thu Jul 12 11:58:42 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/trunk/systests/uncategorized/src/test/resources/me.bmp
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/resources/me.bmp?rev=1360644&view=auto
==============================================================================
Binary file - no diff available.
Propchange: cxf/trunk/systests/uncategorized/src/test/resources/me.bmp
------------------------------------------------------------------------------
svn:executable = *
Propchange: cxf/trunk/systests/uncategorized/src/test/resources/me.bmp
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: cxf/trunk/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java?rev=1360644&r1=1360643&r2=1360644&view=diff
==============================================================================
--- cxf/trunk/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java (original)
+++ cxf/trunk/testutils/src/main/java/org/apache/cxf/mtom_xop/TestMtomImpl.java Thu Jul 12 11:58:42 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) {