You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2011/08/24 21:39:02 UTC
svn commit: r1161243 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts:
SOAPTestSuiteBuilder.java soap12/envelope/TestMTOMForwardStreaming.java
Author: veithen
Date: Wed Aug 24 19:39:02 2011
New Revision: 1161243
URL: http://svn.apache.org/viewvc?rev=1161243&view=rev
Log:
AXIOM-377: Added the unit test that will be used to validate the attachment streaming feature.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java?rev=1161243&r1=1161242&r2=1161243&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/SOAPTestSuiteBuilder.java Wed Aug 24 19:39:02 2011
@@ -106,6 +106,7 @@ public class SOAPTestSuiteBuilder extend
addTest(new org.apache.axiom.ts.soap11.header.TestGetHeadersToProcessWithParser(metaFactory));
addTest(new org.apache.axiom.ts.soap12.envelope.TestAddElementAfterBody(metaFactory));
addTest(new org.apache.axiom.ts.soap12.envelope.TestBuildWithAttachments(metaFactory));
+// addTest(new org.apache.axiom.ts.soap12.envelope.TestMTOMForwardStreaming(metaFactory));
addTest(new org.apache.axiom.ts.soap12.fault.TestGetNode(metaFactory));
addTest(new org.apache.axiom.ts.soap12.fault.TestGetNodeWithParser(metaFactory));
addTest(new org.apache.axiom.ts.soap12.fault.TestMoreChildrenAddition(metaFactory));
Added: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java?rev=1161243&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java Wed Aug 24 19:39:02 2011
@@ -0,0 +1,135 @@
+/*
+ * 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.axiom.ts.soap12.envelope;
+
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.attachments.lifecycle.DataHandlerExt;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.impl.builder.MTOMStAXSOAPModelBuilder;
+import org.apache.axiom.testutils.activation.TestDataSource;
+import org.apache.axiom.testutils.io.IOTestUtils;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests that attachments are streamed (i.e. not read entirely into memory) if the original message
+ * was read from an input stream and
+ * {@link OMElement#serializeAndConsume(java.io.OutputStream, OMOutputFormat)} is used to serialize
+ * the message. This feature is important because it allows projects such as Synapse to forward MTOM
+ * messages very efficiently.
+ */
+public class TestMTOMForwardStreaming extends AxiomTestCase {
+ public TestMTOMForwardStreaming(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ DataSource ds1 = new TestDataSource('A', Runtime.getRuntime().maxMemory());
+ DataSource ds2 = new TestDataSource('B', Runtime.getRuntime().maxMemory());
+
+ // Programmatically create the original message
+ SOAPFactory factory = metaFactory.getSOAP12Factory();
+ final SOAPEnvelope orgEnvelope = factory.createSOAPEnvelope();
+ SOAPBody orgBody = factory.createSOAPBody(orgEnvelope);
+ OMElement orgBodyElement = factory.createOMElement("test", factory.createOMNamespace("urn:test", "p"), orgBody);
+ OMElement orgData1 = factory.createOMElement("data", null, orgBodyElement);
+ orgData1.addChild(factory.createOMText(new DataHandler(ds1), true));
+ OMElement orgData2 = factory.createOMElement("data", null, orgBodyElement);
+ orgData2.addChild(factory.createOMText(new DataHandler(ds2), true));
+
+ final OMOutputFormat format = new OMOutputFormat();
+ format.setDoOptimize(true);
+ format.setSOAP11(false);
+ final String contentType = format.getContentType();
+
+ final PipedOutputStream pipe1Out = new PipedOutputStream();
+ final PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
+
+ // Create the producer thread (simulating the client sending the MTOM message)
+ Thread producerThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ try {
+ orgEnvelope.serialize(pipe1Out, format);
+ } finally {
+ pipe1Out.close();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ producerThread.start();
+
+ final PipedOutputStream pipe2Out = new PipedOutputStream();
+ PipedInputStream pipe2In = new PipedInputStream(pipe2Out);
+
+ // Create the forwarder thread (simulating the mediation engine that forwards the message)
+ Thread forwarderThread = new Thread(new Runnable() {
+ public void run() {
+ try {
+ try {
+ Attachments attachments = new Attachments(pipe1In, contentType);
+ SOAPEnvelope envelope = new MTOMStAXSOAPModelBuilder(
+ StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()),
+ attachments).getSOAPEnvelope();
+ // Usage of serializeAndConsume should enable streaming
+ envelope.serializeAndConsume(pipe2Out, format);
+ } finally {
+ pipe2Out.close();
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ });
+ forwarderThread.start();
+
+ try {
+ Attachments attachments = new Attachments(pipe2In, contentType);
+ SOAPEnvelope envelope = new MTOMStAXSOAPModelBuilder(
+ StAXUtils.createXMLStreamReader(attachments.getSOAPPartInputStream()),
+ attachments).getSOAPEnvelope();
+ OMElement bodyElement = envelope.getBody().getFirstElement();
+ Iterator it = bodyElement.getChildElements();
+ OMElement data1 = (OMElement)it.next();
+ OMElement data2 = (OMElement)it.next();
+
+ IOTestUtils.compareStreams(ds1.getInputStream(),
+ ((DataHandlerExt)((OMText)data1.getFirstOMChild()).getDataHandler()).readOnce());
+ IOTestUtils.compareStreams(ds2.getInputStream(),
+ ((DataHandlerExt)((OMText)data2.getFirstOMChild()).getDataHandler()).readOnce());
+ } finally {
+ pipe2In.close();
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java
------------------------------------------------------------------------------
svn:eol-style = native