This is an automated email from the ASF dual-hosted git repository. veithen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push: new d1132582d [AXIOM-506] Make MultipartBodyWriter use the Blob API d1132582d is described below commit d1132582d32f0d29da71929f922f21b440cf8288 Author: Andreas Veithen <andreas.veit...@gmail.com> AuthorDate: Fri Nov 4 23:17:10 2022 +0000 [AXIOM-506] Make MultipartBodyWriter use the Blob API --- .../org/apache/axiom/mime/MultipartBodyWriter.java | 28 ++++++------------- .../apache/axiom/om/impl/OMMultipartWriter.java | 32 ++++++++++++---------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/axiom-api/src/main/java/org/apache/axiom/mime/MultipartBodyWriter.java b/axiom-api/src/main/java/org/apache/axiom/mime/MultipartBodyWriter.java index 726e0336f..c6d2dc735 100644 --- a/axiom-api/src/main/java/org/apache/axiom/mime/MultipartBodyWriter.java +++ b/axiom-api/src/main/java/org/apache/axiom/mime/MultipartBodyWriter.java @@ -20,17 +20,15 @@ package org.apache.axiom.mime; import java.io.IOException; import java.io.OutputStream; -import java.text.ParseException; import java.util.List; -import javax.activation.DataHandler; - +import org.apache.axiom.blob.Blob; import org.apache.axiom.util.UIDGenerator; /** * Writes a MIME multipart body as used by XOP/MTOM and SOAP with Attachments. MIME parts are * written using {@link #writePart(ContentType, ContentTransferEncoding, String, List)} or - * {@link #writePart(DataHandler, ContentTransferEncoding, String, List)}. Calls to both methods can be mixed, i.e. + * {@link #writePart(Blob, ContentType, ContentTransferEncoding, String, List)}. Calls to both methods can be mixed, i.e. * it is not required to use the same method for all MIME parts. Instead, the caller should choose * the most convenient method for each part (depending on the form in which the content is * available). After all parts have been written, {@link #complete()} must be called to write the @@ -162,11 +160,12 @@ public final class MultipartBodyWriter { } /** - * Write a MIME part. The content is provided by a {@link DataHandler} object, which also - * specifies the content type of the part. + * Write a MIME part. * - * @param dataHandler + * @param blob * the content of the MIME part to write + * @param contentType + * the content type; may be {@code null} * @param contentTransferEncoding * the content transfer encoding to be used (see above); must not be * <code>null</code> @@ -177,21 +176,10 @@ public final class MultipartBodyWriter { * @throws IOException * if an I/O error occurs when writing the part to the underlying stream */ - public void writePart(DataHandler dataHandler, ContentTransferEncoding contentTransferEncoding, String contentID, List<Header> extraHeaders) + public void writePart(Blob blob, ContentType contentType, ContentTransferEncoding contentTransferEncoding, String contentID, List<Header> extraHeaders) throws IOException { - ContentType contentType; - String contentTypeString = dataHandler.getContentType(); - if (contentTypeString == null) { - contentType = null; - } else { - try { - contentType = new ContentType(contentTypeString); - } catch (ParseException ex) { - throw new RuntimeException(ex); - } - } OutputStream partOutputStream = writePart(contentType, contentTransferEncoding, contentID, extraHeaders); - dataHandler.writeTo(partOutputStream); + blob.writeTo(partOutputStream); partOutputStream.close(); } diff --git a/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java b/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java index 9e2f25173..3533e9079 100644 --- a/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java +++ b/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java @@ -27,6 +27,7 @@ import java.util.List; import javax.activation.DataHandler; import org.apache.axiom.attachments.ConfigurableDataHandler; +import org.apache.axiom.blob.Blob; import org.apache.axiom.mime.ContentTransferEncoding; import org.apache.axiom.mime.ContentType; import org.apache.axiom.mime.Header; @@ -34,6 +35,7 @@ import org.apache.axiom.mime.MediaType; import org.apache.axiom.mime.MultipartBodyWriter; import org.apache.axiom.om.OMOutputFormat; import org.apache.axiom.soap.SOAPVersion; +import org.apache.axiom.util.activation.DataHandlerUtils; /** * Writes a MIME multipart package as used by XOP/MTOM and SOAP with Attachments. This class wraps a @@ -143,7 +145,7 @@ public class OMMultipartWriter { /** * Write a MIME part. This method delegates to - * {@link MultipartBodyWriter#writePart(DataHandler, ContentTransferEncoding, String, List)}, but computes the + * {@link MultipartBodyWriter#writePart(Blob, ContentType, ContentTransferEncoding, String, List)}, but computes the * appropriate content transfer encoding from the {@link OMOutputFormat}. * * @param dataHandler @@ -156,6 +158,17 @@ public class OMMultipartWriter { * if an I/O error occurs when writing the part to the underlying stream */ public void writePart(DataHandler dataHandler, String contentID, List<Header> extraHeaders) throws IOException { + ContentType contentType; + String contentTypeString = dataHandler.getContentType(); + if (contentTypeString == null) { + contentType = null; + } else { + try { + contentType = new ContentType(contentTypeString); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + } ContentTransferEncoding contentTransferEncoding = null; if (dataHandler instanceof ConfigurableDataHandler) { switch (((ConfigurableDataHandler)dataHandler).getTransferEncoding()) { @@ -169,27 +182,18 @@ public class OMMultipartWriter { contentTransferEncoding = ContentTransferEncoding.BASE64; } } - if (contentTransferEncoding == null) { - String contentTypeString = dataHandler.getContentType(); - if (contentTypeString != null) { - ContentType contentType; - try { - contentType = new ContentType(contentTypeString); - } catch (ParseException ex) { - throw new RuntimeException(ex); - } - contentTransferEncoding = getContentTransferEncoding(contentType); - } + if (contentTransferEncoding == null && contentType != null) { + contentTransferEncoding = getContentTransferEncoding(contentType); } if (contentTransferEncoding == null) { contentTransferEncoding = ContentTransferEncoding.BINARY; } - writer.writePart(dataHandler, contentTransferEncoding, contentID, extraHeaders); + writer.writePart(DataHandlerUtils.toBlob(dataHandler), contentType, contentTransferEncoding, contentID, extraHeaders); } /** * Write a MIME part. This method delegates to - * {@link MultipartBodyWriter#writePart(DataHandler, ContentTransferEncoding, String, List)}, but computes the appropriate + * {@link MultipartBodyWriter#writePart(Blob, ContentType, ContentTransferEncoding, String, List)}, but computes the appropriate * content transfer encoding from the {@link OMOutputFormat}. * * @param dataHandler