Author: veithen
Date: Sat Nov 13 13:29:30 2010
New Revision: 1034754
URL: http://svn.apache.org/viewvc?rev=1034754&view=rev
Log:
AXIS2-4828: Avoid buffering (and the unnecessary byte stream -> char stream ->
byte stream conversion) of the SOAP body in SOAPMessageFormatter. The message
is now streamed directly to the output stream.
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/util/Utils.java
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/misc/MiscTest.java
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java?rev=1034754&r1=1034753&r2=1034754&view=diff
==
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
Sat Nov 13 13:29:30 2010
@@ -19,14 +19,14 @@
package org.apache.axis2.transport.http;
+import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.MIMEOutputUtils;
+import org.apache.axiom.om.impl.OMMultipartWriter;
import org.apache.axiom.util.UIDGenerator;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.Parameter;
import org.apache.axis2.transport.MessageFormatter;
import org.apache.axis2.transport.http.util.URLTemplatingUtil;
import org.apache.axis2.util.JavaUtils;
@@ -37,8 +37,8 @@ import org.apache.commons.logging.LogFac
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.OutputStream;
-import java.io.StringWriter;
import java.net.URL;
public class SOAPMessageFormatter implements MessageFormatter {
@@ -53,7 +53,6 @@ public class SOAPMessageFormatter implem
log.debug(" isOptimized=" + format.isOptimized());
log.debug(" isDoingSWA=" + format.isDoingSWA());
}
-OMElement element = msgCtxt.getEnvelope();
if (msgCtxt.isDoingMTOM()) {
int optimizedThreshold = Utils.getMtomThreshold(msgCtxt);
@@ -66,23 +65,9 @@ public class SOAPMessageFormatter implem
}
try {
if (!(format.isOptimized()) && format.isDoingSWA()) {
-// Write the SOAPBody to an output stream
-// (We prefer an OutputStream because it is faster)
-if (log.isDebugEnabled()) {
-log.debug("Doing SWA and the format is not optimized.
Buffer the SOAPBody in an OutputStream");
-}
-ByteArrayOutputStream bufferedSOAPBodyBAOS = new
ByteArrayOutputStream();
-if (preserve) {
-element.serialize(bufferedSOAPBodyBAOS, format);
-} else {
-element.serializeAndConsume(bufferedSOAPBodyBAOS, format);
-}
-// Convert the ByteArrayOutputStream to StreamWriter so that
SWA can
-// be added.
-String bufferedSOAPBody =
Utils.BAOS2String(bufferedSOAPBodyBAOS, format.getCharSetEncoding());
-StringWriter bufferedSOAPBodySW =
Utils.String2StringWriter(bufferedSOAPBody);
-writeSwAMessage(msgCtxt, bufferedSOAPBodySW, out, format);
+writeSwAMessage(msgCtxt, out, format, preserve);
} else {
+OMElement element = msgCtxt.getEnvelope();
if (preserve) {
element.serialize(out, format);
} else {
@@ -110,17 +95,7 @@ public class SOAPMessageFormatter implem
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
if (!format.isOptimized()) {
if (format.isDoingSWA()) {
-if (log.isDebugEnabled()) {
-log.debug("Doing SWA and the format is not optimized.
Buffer the SOAPBody in an OutputStream");
-}
-// Why are we creating a new OMOutputFormat
-OMOutputFormat format2 = new OMOutputFormat();
-format2.setCharSetEncoding(format.getCharSetEncoding());
-ByteArrayOutputStream bufferedSOAPBodyBAOS = new
ByteArrayOutputStream();
-element.serializeAndConsume(bufferedSOAPBodyBAOS, format2);
-String bufferedSOAPBody =
Uti