Author: veithen
Date: Sat Nov 13 11:16:22 2010
New Revision: 1034730
URL: http://svn.apache.org/viewvc?rev=1034730&view=rev
Log:
AXIOM-274: Refactored and deprecated MIMEOutputUtils#writeMM7Message.
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
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/OMMultipartWriter.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java?rev=1034730&r1=1034729&r2=1034730&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMOutputFormat.java
Sat Nov 13 11:16:22 2010
@@ -44,13 +44,13 @@ public class OMOutputFormat {
private static Log log = LogFactory.getLog(OMOutputFormat.class);
- private String mimeBoundary = null;
- private String rootContentId = null;
- private int nextid = 0;
- private boolean doOptimize = false;
- private boolean doingSWA = false;
- private boolean isSoap11 = true;
- private int optimizedThreshold = 0;
+ private String mimeBoundary;
+ private String rootContentId;
+ private int nextid;
+ private boolean doOptimize;
+ private boolean doingSWA;
+ private boolean isSoap11;
+ private int optimizedThreshold;
/** Field DEFAULT_CHAR_SET_ENCODING. Specifies the default character
encoding scheme to be used. */
public static final String DEFAULT_CHAR_SET_ENCODING = "utf-8";
@@ -58,8 +58,16 @@ public class OMOutputFormat {
private String charSetEncoding;
private String xmlVersion;
private String contentType;
- private boolean ignoreXMLDeclaration = false;
- private boolean autoCloseWriter = false;
+
+ /**
+ * Flag set if {...@link #contentType} has been set explicitly through
+ * {...@link #setContentType(String)}. If this attribute is
<code>false</code> and
+ * {...@link #contentType} is non null, then it was calculated by
{...@link #getContentType()}.
+ */
+ private boolean contentTypeSet;
+
+ private boolean ignoreXMLDeclaration;
+ private boolean autoCloseWriter;
public static final String ACTION_PROPERTY = "action";
@@ -94,10 +102,40 @@ public class OMOutputFormat {
Boolean.TRUE;
- HashMap map = null; // Map of generic properties
+ private HashMap map; // Map of generic properties
public OMOutputFormat() {
+ isSoap11 = true;
+ }
+
+ /**
+ * Constructs a new instance by copying the configuration from an existing
instance. Note that
+ * this will only copy configuration data, but not information that is
subject to
+ * auto-generation, such as the root content ID or the MIME boundary.
+ *
+ * @param format
+ * the existing instance
+ */
+ public OMOutputFormat(OMOutputFormat format) {
+ doOptimize = format.doOptimize;
+ doingSWA = format.doingSWA;
+ isSoap11 = format.isSoap11;
+ optimizedThreshold = format.optimizedThreshold;
+ charSetEncoding = format.charSetEncoding;
+ xmlVersion = format.xmlVersion;
+ if (format.contentTypeSet) {
+ contentTypeSet = true;
+ contentType = format.contentType;
+ }
+ ignoreXMLDeclaration = format.ignoreXMLDeclaration;
+ autoCloseWriter = format.autoCloseWriter;
+ xmlStreamWriterFilter = format.xmlStreamWriterFilter;
+ writerConfiguration = format.writerConfiguration;
+ multipartWriterFactory = format.multipartWriterFactory;
+ if (format.map != null) {
+ map = new HashMap(format.map);
+ }
}
/**
@@ -186,6 +224,7 @@ public class OMOutputFormat {
* @param c
*/
public void setContentType(String c) {
+ contentTypeSet = true;
contentType = c;
}
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=1034730&r1=1034729&r2=1034730&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
Sat Nov 13 11:16:22 2010
@@ -41,8 +41,6 @@ import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.OMText;
import org.apache.axiom.om.util.CommonUtils;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.util.activation.DataHandlerWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -334,88 +332,46 @@ public class MIMEOutputUtils {
}
/**
- * Pack all the attachments in to a multipart/related MIME part and
attachs it as the second
- * MIME Part of MIME message
- *
- * @param writer
- * @param outputStream
- * @param attachments
- * @param format
- * @param innerBoundary
+ * @deprecated Axiom only supports standard SwA messages. However,
{...@link OMMultipartWriter}
+ * provides a flexible way to build MIME packages for non
standard formats such as
+ * MM7.
*/
public static void writeMM7Message(StringWriter writer,
OutputStream outputStream, Attachments
attachments,
OMOutputFormat format, String
innerPartCID,
String innerBoundary) {
- String SOAPContentType;
try {
- if (format.isSOAP11()) {
- SOAPContentType = SOAP11Constants.SOAP_11_CONTENT_TYPE;
- } else {
- SOAPContentType = SOAP12Constants.SOAP_12_CONTENT_TYPE;
- }
- startWritingMime(outputStream, format.getMimeBoundary());
-
- javax.activation.DataHandler dh = new javax.activation.DataHandler(
- writer.toString(), "text/xml; charset="
- + format.getCharSetEncoding());
- MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
- rootMimeBodyPart.setDataHandler(dh);
-
- rootMimeBodyPart.addHeader("Content-Type",
- SOAPContentType + "; charset=" +
- format.getCharSetEncoding());
- rootMimeBodyPart.addHeader("Content-ID", "<"
- + format.getRootContentId() + ">");
-
- writeBodyPart(outputStream, rootMimeBodyPart, format
- .getMimeBoundary());
-
+ OMMultipartWriter mpw = new OMMultipartWriter(outputStream,
format);
+
+ Writer rootPartWriter = new
OutputStreamWriter(mpw.writeRootPart(), format.getCharSetEncoding());
+ rootPartWriter.write(writer.toString());
+ rootPartWriter.close();
+
if (attachments.getContentIDSet().size() != 0) {
- outputStream.write(CRLF);
- StringBuffer sb = new StringBuffer();
- sb.append("Content-Type: multipart/related");
- sb.append("; ");
- sb.append("boundary=");
- sb.append("\"" + innerBoundary + "\"");
- // REVIEW Should this be getBytes("UTF-8") or getBytes(charset)
- outputStream.write(sb.toString().getBytes());
- outputStream.write(CRLF);
- StringBuffer sb1 = new StringBuffer();
- sb1.append("Content-ID: ");
- sb1.append("<");
- sb1.append(innerPartCID);
- sb1.append(">");
- // REVIEW Should this be getBytes("UTF-8") or getBytes(charset)
- outputStream.write(sb1.toString().getBytes());
- outputStream.write(CRLF);
- outputStream.write(CRLF);
- startWritingMime(outputStream, innerBoundary);
- Iterator attachmentIDIterator = null;
+ OMOutputFormat innerFormat = new OMOutputFormat(format);
+ innerFormat.setMimeBoundary(innerBoundary);
+ OutputStream innerOutputStream =
mpw.writePart("multipart/related; boundary=\"" + innerBoundary + "\"",
innerPartCID);
+ OMMultipartWriter innerMpw = new
OMMultipartWriter(innerOutputStream, innerFormat);
+ Collection ids;
if (respectSWAAttachmentOrder(format)) {
// ContentIDList is the order of the incoming/added
attachments
- attachmentIDIterator =
attachments.getContentIDList().iterator();
+ ids = Arrays.asList(attachments.getAllContentIDs());
} else {
- // ContentIDSet is an undefined order (the
implemenentation currently
+ // ContentIDSet is an undefined order (the implementation
currently
// orders the attachments using the natural order of the
content ids)
- attachmentIDIterator =
attachments.getContentIDSet().iterator();
+ ids = attachments.getContentIDSet();
}
- while (attachmentIDIterator.hasNext()) {
- String contentID = (String) attachmentIDIterator.next();
- DataHandler dataHandler =
attachments.getDataHandler(contentID);
- writeBodyPart(outputStream, createMimeBodyPart(contentID,
-
dataHandler), innerBoundary);
+ for (Iterator it = ids.iterator(); it.hasNext(); ) {
+ String id = (String)it.next();
+ innerMpw.writePart(attachments.getDataHandler(id), id);
}
- finishWritingMime(outputStream);
- outputStream.write(CRLF);
- writeMimeBoundary(outputStream, format.getMimeBoundary());
+ innerMpw.complete();
+ innerOutputStream.close();
}
- finishWritingMime(outputStream);
- outputStream.flush();
+
+ mpw.complete();
} catch (IOException e) {
throw new OMException("Error while writing to the OutputStream.",
e);
- } catch (MessagingException e) {
- throw new OMException("Problem writing Mime Parts.", e);
}
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java?rev=1034730&r1=1034729&r2=1034730&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMMultipartWriter.java
Sat Nov 13 11:16:22 2010
@@ -97,6 +97,23 @@ public class OMMultipartWriter {
}
/**
+ * Start writing an attachment part of the MIME package. This method
delegates to
+ * {...@link MultipartWriter#writePart(String, String, String)}, but
computes the content transfer
+ * encoding based on the content type and the {...@link OMOutputFormat}.
+ *
+ * @param contentType
+ * the content type of the MIME part to write
+ * @param contentID
+ * the content ID of the MIME part
+ * @return an output stream to write the content of the MIME part
+ * @throws IOException
+ * if an I/O error occurs when writing to the underlying stream
+ */
+ public OutputStream writePart(String contentType, String contentID) throws
IOException {
+ return writer.writePart(contentType,
getContentTransferEncoding(contentType), contentID);
+ }
+
+ /**
* Write a MIME part. This method delegates to
* {...@link MultipartWriter#writePart(DataHandler, String, String)}, but
computes the appropriate
* content transfer encoding from the {...@link OMOutputFormat}.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]