You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2010/11/04 19:21:42 UTC
svn commit: r1031124 - in /cxf/trunk:
rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/
systests/databinding/
systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/
Author: bimargulies
Date: Thu Nov 4 18:21:42 2010
New Revision: 1031124
URL: http://svn.apache.org/viewvc?rev=1031124&view=rev
Log:
CXF-3056: package non-optimized MTOM as streams to match optimized (in Aegis)
Added:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java (with props)
Modified:
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
cxf/trunk/systests/databinding/pom.xml
cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java?rev=1031124&r1=1031123&r2=1031124&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java Thu Nov 4 18:21:42 2010
@@ -18,21 +18,24 @@
*/
package org.apache.cxf.aegis.type.mtom;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import javax.activation.DataHandler;
import org.apache.cxf.aegis.Context;
import org.apache.cxf.attachment.AttachmentImpl;
-import org.apache.cxf.helpers.HttpHeaderHelper;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.message.Attachment;
+/**
+ * Binding for {@link javax.activation.DataHandler}. This assumes that the DataHandler will always
+ * contain a {@link javax.activation.DataSource}, not data in the Object.
+ */
public class DataHandlerType extends AbstractXOPType {
-
+
public DataHandlerType(boolean useXmimeContentType, String expectedContentTypes) {
super(useXmimeContentType, expectedContentTypes);
}
@@ -59,27 +62,9 @@ public class DataHandlerType extends Abs
@Override
protected Object wrapBytes(byte[] bareBytes, String contentType) {
- // for the benefit of those who are working with string data, we have the following
- // trickery
- String charset = null;
- if (contentType != null
- && contentType.indexOf("text/") != -1
- && contentType.indexOf("charset") != -1) {
- charset = contentType.substring(contentType.indexOf("charset") + 8);
- if (charset.indexOf(";") != -1) {
- charset = charset.substring(0, charset.indexOf(";"));
- }
- }
- String normalizedEncoding = HttpHeaderHelper.mapCharset(charset, "UTF-8");
- try {
- String stringData = new String(bareBytes, normalizedEncoding);
- return new DataHandler(stringData, contentType);
- } catch (UnsupportedEncodingException e) {
- // this space intentionally left blank.
- }
- return new DataHandler(bareBytes, contentType);
+ return new DataHandler(new StreamDataSource(contentType, new ByteArrayInputStream(bareBytes)));
}
-
+
@Override
protected byte[] getBytes(Object object) {
DataHandler handler = (DataHandler) object;
Modified: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java?rev=1031124&r1=1031123&r2=1031124&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java (original)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java Thu Nov 4 18:21:42 2010
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.aegis.type.mtom;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -30,6 +31,9 @@ import org.apache.cxf.attachment.Attachm
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.message.Attachment;
+/**
+ * Binding for {@link javax.activation.DataSource}.
+ */
public class DataSourceType extends AbstractXOPType {
public DataSourceType(boolean useXmimeBinaryType, String expectedContentTypes) {
super(useXmimeBinaryType, expectedContentTypes);
@@ -57,7 +61,7 @@ public class DataSourceType extends Abst
@Override
protected Object wrapBytes(byte[] bareBytes, String contentType) {
- return new DataHandler(bareBytes, contentType).getDataSource();
+ return new StreamDataSource(contentType, new ByteArrayInputStream(bareBytes));
}
@Override
Added: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java?rev=1031124&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java (added)
+++ cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java Thu Nov 4 18:21:42 2010
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+
+package org.apache.cxf.aegis.type.mtom;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.DataSource;
+
+/**
+ *
+ */
+public class StreamDataSource implements DataSource {
+
+ private String contentType;
+ private InputStream stream;
+
+ public StreamDataSource(String contentType, InputStream stream) {
+ this.contentType = contentType;
+ this.stream = stream;
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ public String getContentType() {
+ return contentType;
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ public InputStream getInputStream() throws IOException {
+ return stream;
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ /** {@inheritDoc}*/
+ @Override
+ public OutputStream getOutputStream() throws IOException {
+ return null;
+ }
+
+}
Propchange: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/StreamDataSource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/trunk/systests/databinding/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/pom.xml?rev=1031124&r1=1031123&r2=1031124&view=diff
==============================================================================
--- cxf/trunk/systests/databinding/pom.xml (original)
+++ cxf/trunk/systests/databinding/pom.xml Thu Nov 4 18:21:42 2010
@@ -279,6 +279,12 @@
<artifactId>jettison</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
Modified: cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java?rev=1031124&r1=1031123&r2=1031124&view=diff
==============================================================================
--- cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java (original)
+++ cxf/trunk/systests/databinding/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java Thu Nov 4 18:21:42 2010
@@ -19,6 +19,7 @@
package org.apache.cxf.systest.aegis.mtom;
+import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
@@ -48,7 +49,7 @@ import org.springframework.test.context.
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
/**
- *
+ *
*/
@ContextConfiguration(locations = { "classpath:mtomTestBeans.xml" })
public class MtomTest extends AbstractJUnit4SpringContextTests {
@@ -57,11 +58,11 @@ public class MtomTest extends AbstractJU
private org.apache.cxf.systest.aegis.mtom.fortest.MtomTestImpl impl;
private org.apache.cxf.systest.aegis.mtom.fortest.MtomTest client;
private TestUtilities testUtilities;
-
+
public MtomTest() {
testUtilities = new TestUtilities(getClass());
}
-
+
private void setupForTest(boolean enableClientMTOM) throws Exception {
AegisDatabinding aegisBinding = new AegisDatabinding();
aegisBinding.setMtomEnabled(enableClientMTOM);
@@ -78,9 +79,9 @@ public class MtomTest extends AbstractJU
client = (org.apache.cxf.systest.aegis.mtom.fortest.MtomTest)proxyFac.create();
impl = (MtomTestImpl)applicationContext.getBean("mtomImpl");
}
-
-
- @Test
+
+
+ @Test
public void testMtomReply() throws Exception {
setupForTest(true);
DataHandlerBean dhBean = client.produceDataHandlerBean();
@@ -88,7 +89,7 @@ public class MtomTest extends AbstractJU
Assert.assertEquals(MtomTestImpl.STRING_DATA, dhBean.getDataHandler().getContent());
}
- @Test
+ @Test
public void testAcceptDataHandler() throws Exception {
setupForTest(true);
DataHandlerBean dhBean = new DataHandlerBean();
@@ -105,7 +106,7 @@ public class MtomTest extends AbstractJU
Assert.assertEquals("This is the cereal shot from guns.", data);
}
- @Test
+ @Test
public void testAcceptDataHandlerNoMTOM() throws Exception {
setupForTest(false);
DataHandlerBean dhBean = new DataHandlerBean();
@@ -117,9 +118,10 @@ public class MtomTest extends AbstractJU
client.acceptDataHandler(dhBean);
DataHandlerBean accepted = impl.getLastDhBean();
Assert.assertNotNull(accepted);
- Object data = accepted.getDataHandler().getContent();
+ InputStream data = accepted.getDataHandler().getInputStream();
Assert.assertNotNull(data);
- Assert.assertEquals("This is the cereal shot from guns.", data);
+ String dataString = org.apache.commons.io.IOUtils.toString(data, "utf-8");
+ Assert.assertEquals("This is the cereal shot from guns.", dataString);
}
@Test
@@ -128,14 +130,14 @@ public class MtomTest extends AbstractJU
testUtilities.addDefaultNamespaces();
testUtilities.addNamespace("xmime", "http://www.w3.org/2005/05/xmlmime");
Server s = testUtilities.
- getServerForService(new QName("http://fortest.mtom.aegis.systest.cxf.apache.org/",
+ getServerForService(new QName("http://fortest.mtom.aegis.systest.cxf.apache.org/",
"MtomTest"));
- Document wsdl = testUtilities.getWSDLDocument(s);
+ Document wsdl = testUtilities.getWSDLDocument(s);
Assert.assertNotNull(wsdl);
- NodeList typeAttrList =
+ NodeList typeAttrList =
testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
+ "xsd:element[@name='dataHandler']/"
- + "@type",
+ + "@type",
wsdl);
Attr typeAttr = (Attr)typeAttrList.item(0);
String typeAttrValue = typeAttr.getValue();
@@ -145,14 +147,14 @@ public class MtomTest extends AbstractJU
Node elementNode = typeAttr.getOwnerElement();
String url = testUtilities.resolveNamespacePrefix(pieces[0], elementNode);
Assert.assertEquals(SOAPConstants.XSD, url);
-
+
s = testUtilities.getServerForAddress("http://localhost:" + PORT + "/mtomXmime");
- wsdl = testUtilities.getWSDLDocument(s);
+ wsdl = testUtilities.getWSDLDocument(s);
Assert.assertNotNull(wsdl);
- typeAttrList =
+ typeAttrList =
testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
+ "xsd:element[@name='dataHandler']/"
- + "@type",
+ + "@type",
wsdl);
typeAttr = (Attr)typeAttrList.item(0);
typeAttrValue = typeAttr.getValue();
@@ -162,11 +164,11 @@ public class MtomTest extends AbstractJU
elementNode = typeAttr.getOwnerElement();
url = testUtilities.resolveNamespacePrefix(pieces[0], elementNode);
Assert.assertEquals(AbstractXOPType.XML_MIME_NS, url);
-
+
/* when I add a test for a custom mapping.
testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
+ "xsd:element[@name='dataHandler']/"
- + "@xmime:expectedContentType/text()",
+ + "@xmime:expectedContentType/text()",
wsdl);
*/
}