Author: scheu
Date: Wed Jun 9 12:02:06 2010
New Revision: 952971
URL: http://svn.apache.org/viewvc?rev=952971&view=rev
Log:
AXIS2-4733
Contributor: Phil Adams
Contributed WrappedDataHandler to allow Axis2 to set the appropriate
content-type on a DataHandler.
Also added a validation test.
Added:
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/impl/WrappedDataHandlerTest.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/util/WrappedDataHandler.java
Modified:
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
Modified:
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java?rev=952971&r1=952970&r2=952971&view=diff
==
---
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/impl/MessageFactoryImpl.java
Wed Jun 9 12:02:06 2010
@@ -37,6 +37,7 @@ import org.apache.axis2.jaxws.message.da
import org.apache.axis2.jaxws.message.databinding.DataSourceBlock;
import org.apache.axis2.jaxws.message.factory.MessageFactory;
import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.util.WrappedDataHandler;
import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MimeHeader;
@@ -118,7 +119,7 @@ public class MessageFactoryImpl implemen
m.setDoingSWA(true);
while (it.hasNext()) {
AttachmentPart ap = (AttachmentPart)it.next();
-m.addDataHandler(ap.getDataHandler(), ap.getContentId());
+m.addDataHandler(new
WrappedDataHandler(ap.getDataHandler(), ap.getContentType()),
ap.getContentId());
}
}
return m;
@@ -144,5 +145,4 @@ public class MessageFactoryImpl implemen
}
return createFrom(block.getXMLStreamReader(true), protocol);
}
-
}
Added:
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/impl/WrappedDataHandlerTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/impl/WrappedDataHandlerTest.java?rev=952971&view=auto
==
---
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/impl/WrappedDataHandlerTest.java
(added)
+++
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/message/impl/WrappedDataHandlerTest.java
Wed Jun 9 12:02:06 2010
@@ -0,0 +1,48 @@
+package org.apache.axis2.jaxws.message.impl;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.net.URL;
+import javax.activation.DataHandler;
+
+import org.apache.axis2.util.WrappedDataHandler;
+
+import junit.framework.TestCase;
+
+/**
+ * Test the WrappedDataHandler class.
+ */
+public class WrappedDataHandlerTest extends TestCase {
+
+ /**
+* Verify that the Wrapped DataHandler maintains the correct content-type
value
+* for an XML document attachment.
+*/
+ public void testWrappedDataHandler() throws Exception {
+ URL xmlAttachment = new URL("file:./test-resources/xml/soapmessage.xml");
+
+ DataHandler dh = new DataHandler(xmlAttachment);
+ assertTrue(dh.getContentType().equals("application/xml"));
+
+ WrappedDataHandler wrappedDH = new WrappedDataHandler(dh, "text/xml");
+ assertTrue(wrappedDH.getContentType() != null);
+ assertTrue(wrappedDH.getContentType().equals("text/xml"));
+ }
+}
Added:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/util/WrappedDataHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/util/WrappedDataHandler.java?rev=952971&view=auto
==
---
axis/axis2/jav