Author: dims
Date: Tue Feb 19 20:30:07 2008
New Revision: 629349

URL: http://svn.apache.org/viewvc?rev=629349&view=rev
Log:
[Performance] - Don't create an unnecessary string again, pass the byte array 
directly. Use ByteArrayDataSource with the byte array. Internally this avoids a 
lookup/load of DataContentHandler from the mailcap file as well. Please keep an 
eye out for breaking tests...

Modified:
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
    
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java?rev=629349&r1=629348&r2=629349&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MIMEOutputUtils.java
 Tue Feb 19 20:30:07 2008
@@ -31,6 +31,7 @@
 
 import org.apache.axiom.attachments.Attachments;
 import org.apache.axiom.attachments.ConfigurableDataHandler;
+import org.apache.axiom.attachments.ByteArrayDataSource;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMOutputFormat;
 import org.apache.axiom.om.OMText;
@@ -47,6 +48,8 @@
     private static byte[] CRLF = { 13, 10 };
 
     /**
+     * @deprecated is anyone really using this?
+     * 
      * Invoked by MTOMXMLStreamWriter to write the SOAP Part and the attachemts
      * @param outStream OutputStream target
      * @param bufferedXML String containing XML of SOAPPart
@@ -106,6 +109,68 @@
     }
     
     /**
+     * Invoked by MTOMXMLStreamWriter to write the SOAP Part and the 
attachements. 
+     * 
+     * @param outStream OutputStream target
+     * @param bufferedXML String containing XML of SOAPPart
+     * @param binaryNodeList Text nodes with the attachment Data Handlers
+     * @param boundary Boundary String
+     * @param contentId Content-ID of SOAPPart
+     * @param charSetEncoding Character Encoding of SOAPPart
+     * @param SOAPContentType Content-Type of SOAPPart
+     */
+    public static void complete(OutputStream outStream, 
+                                byte[] xmlData,
+                                LinkedList binaryNodeList, 
+                                String boundary, 
+                                String contentId,
+                                String charSetEncoding, 
+                                String SOAPContentType) {
+        try {
+            // TODO: Instead of buffering the SOAPPart contents, it makes more
+            // sense to split this method in two.  Write out the SOAPPart 
headers
+            // and later write out the attachments.  This will avoid the cost 
and
+            // space of buffering.
+            
+            // Write out the mime boundary
+            startWritingMime(outStream, boundary);
+
+            javax.activation.DataHandler dh = 
+                new javax.activation.DataHandler(new 
ByteArrayDataSource(xmlData,
+                                                 "text/xml; charset=" + 
charSetEncoding));
+            MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
+            rootMimeBodyPart.setDataHandler(dh);
+
+            rootMimeBodyPart.addHeader("Content-Type",
+                                       "application/xop+xml; charset=" + 
charSetEncoding +
+                                               "; type=\"" + SOAPContentType + 
"\"");
+            rootMimeBodyPart.addHeader("Content-Transfer-Encoding", "binary");
+            rootMimeBodyPart.addHeader("Content-ID", "<" + contentId + ">");
+
+            // Write out the SOAPPart
+            writeBodyPart(outStream, rootMimeBodyPart, boundary);
+
+            // Now write out the Attachment parts (which are represented by the
+            // text nodes int the binary node list)
+            Iterator binaryNodeIterator = binaryNodeList.iterator();
+            while (binaryNodeIterator.hasNext()) {
+                OMText binaryNode = (OMText) binaryNodeIterator.next();
+                writeBodyPart(outStream, createMimeBodyPart(binaryNode
+                        .getContentID(), (DataHandler) binaryNode
+                        .getDataHandler()), boundary);
+            }
+            finishWritingMime(outStream);
+            outStream.flush();
+        } catch (IOException e) {
+            throw new OMException("Error while writing to the OutputStream.", 
e);
+        } catch (MessagingException e) {
+            throw new OMException("Problem writing Mime Parts.", e);
+        }
+    }
+
+    /**
+     * @deprecated - is anyone really using this?
+     * 
      * Write the SOAPPart and attachments
      * @param outStream
      * @param writer

Modified: 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java?rev=629349&r1=629348&r2=629349&view=diff
==============================================================================
--- 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 (original)
+++ 
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/MTOMXMLStreamWriter.java
 Tue Feb 19 20:30:07 2008
@@ -25,6 +25,7 @@
 import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.attachments.ByteArrayDataSource;
 
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.FactoryConfigurationError;
@@ -149,10 +150,8 @@
                 SOAPContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
             }
             try {
-                String bufferedXMLText =
-                        new String(bufferedXML.toByteArray(), 
format.getCharSetEncoding());
                 MIMEOutputUtils.complete(outStream,
-                                         bufferedXMLText,
+                                         bufferedXML.toByteArray(),
                                          binaryNodeList,
                                          format.getMimeBoundary(),
                                          format.getRootContentId(),



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to