Author: veithen
Date: Fri Nov 12 19:35:45 2010
New Revision: 1034539
URL: http://svn.apache.org/viewvc?rev=1034539&view=rev
Log:
AXIOM-274: Refactored and deprecated the
MIMEOutputUtils#writeDataHandlerWithAttachmentsMessage method.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java
(with props)
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/OMMultipartWriter.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.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=1034539&r1=1034538&r2=1034539&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
Fri Nov 12 19:35:45 2010
@@ -43,6 +43,7 @@ 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;
@@ -270,6 +271,9 @@ public class MIMEOutputUtils {
}
}
+ /**
+ * @deprecated use {...@link OMMultipartWriter} instead
+ */
public static void writeDataHandlerWithAttachmentsMessage(DataHandler
rootDataHandler,
String contentType,
OutputStream outputStream,
@@ -283,25 +287,28 @@ public class MIMEOutputUtils {
null);
}
+
+ /**
+ * @deprecated use {...@link OMMultipartWriter} instead
+ */
public static void writeDataHandlerWithAttachmentsMessage(DataHandler
rootDataHandler,
- String contentType,
+ final String
contentType,
OutputStream
outputStream,
Map attachments,
OMOutputFormat format,
Collection ids) {
try {
- startWritingMime(outputStream, format.getMimeBoundary());
-
- MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
- rootMimeBodyPart.setDataHandler(rootDataHandler);
-
- rootMimeBodyPart.addHeader("Content-Type", contentType);
- rootMimeBodyPart.addHeader("Content-Transfer-Encoding", "8bit");
- rootMimeBodyPart.addHeader("Content-ID", "<"
- + format.getRootContentId() + ">");
-
- writeBodyPart(outputStream, rootMimeBodyPart, format
- .getMimeBoundary());
+ if (!rootDataHandler.getContentType().equals(contentType)) {
+ rootDataHandler = new DataHandlerWrapper(rootDataHandler) {
+ public String getContentType() {
+ return contentType;
+ }
+ };
+ }
+
+ OMMultipartWriter mpw = new OMMultipartWriter(outputStream,
format);
+
+ mpw.writePart(rootDataHandler, format.getRootContentId());
Iterator idIterator = null;
if (ids == null) {
@@ -317,17 +324,12 @@ public class MIMEOutputUtils {
while (idIterator.hasNext()) {
String key = (String) idIterator.next();
- MimeBodyPart part = createMimeBodyPart(key,
- (DataHandler) attachments.get(key), format);
- writeBodyPart(outputStream, part,
- format.getMimeBoundary());
+ mpw.writePart((DataHandler) attachments.get(key), key);
}
- finishWritingMime(outputStream);
+ mpw.complete();
outputStream.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);
}
}
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=1034539&r1=1034538&r2=1034539&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
Fri Nov 12 19:35:45 2010
@@ -76,6 +76,16 @@ public class OMMultipartWriter {
}
/**
+ * Get the content type of the root part, as determined by the {...@link
OMOutputFormat} passed
+ * to the constructor of this object.
+ *
+ * @return the content type of the root part
+ */
+ public String getRootPartContentType() {
+ return rootPartContentType;
+ }
+
+ /**
* Start writing the root part of the MIME package. This method delegates
to
* {...@link MultipartWriter#writePart(String, String, String)}, but
computes the content type,
* content transfer encoding and content ID from the {...@link
OMOutputFormat}.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java?rev=1034539&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java
Fri Nov 12 19:35:45 2010
@@ -0,0 +1,106 @@
+/*
+ * 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.util.activation;
+
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.UnsupportedFlavorException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.activation.CommandInfo;
+import javax.activation.CommandMap;
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+
+/**
+ * Base class for {...@link DataHandler} wrappers.
+ */
+public class DataHandlerWrapper extends DataHandler {
+ private final DataHandler parent;
+
+ public DataHandlerWrapper(DataHandler parent) {
+ // Some JavaMail implementations allow passing null to the constructor,
+ // but this is not the case for all implementations. We use an empty
data
+ // source to avoid this issue. This approach is known to work with
Sun's
+ // and Geronimo's JavaMail implementations.
+ super(EmptyDataSource.INSTANCE);
+ this.parent = parent;
+ }
+
+ public CommandInfo[] getAllCommands() {
+ return parent.getAllCommands();
+ }
+
+ public Object getBean(CommandInfo cmdinfo) {
+ return parent.getBean(cmdinfo);
+ }
+
+ public CommandInfo getCommand(String cmdName) {
+ return parent.getCommand(cmdName);
+ }
+
+ public Object getContent() throws IOException {
+ return parent.getContent();
+ }
+
+ public String getContentType() {
+ return parent.getContentType();
+ }
+
+ public DataSource getDataSource() {
+ return parent.getDataSource();
+ }
+
+ public InputStream getInputStream() throws IOException {
+ return parent.getInputStream();
+ }
+
+ public String getName() {
+ return parent.getName();
+ }
+
+ public OutputStream getOutputStream() throws IOException {
+ return parent.getOutputStream();
+ }
+
+ public CommandInfo[] getPreferredCommands() {
+ return parent.getPreferredCommands();
+ }
+
+ public Object getTransferData(DataFlavor flavor) throws
UnsupportedFlavorException, IOException {
+ return parent.getTransferData(flavor);
+ }
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return parent.getTransferDataFlavors();
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ return parent.isDataFlavorSupported(flavor);
+ }
+
+ public void setCommandMap(CommandMap commandMap) {
+ parent.setCommandMap(commandMap);
+ }
+
+ public void writeTo(OutputStream os) throws IOException {
+ parent.writeTo(os);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/DataHandlerWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java?rev=1034539&r1=1034538&r2=1034539&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/activation/EmptyDataSource.java
Fri Nov 12 19:35:45 2010
@@ -29,6 +29,11 @@ import org.apache.axiom.ext.activation.S
* A data source with empty (zero length) content.
*/
public class EmptyDataSource implements SizeAwareDataSource {
+ /**
+ * Empty data source instance with content type
<tt>application/octet-stream</tt>.
+ */
+ public static final EmptyDataSource INSTANCE = new
EmptyDataSource("application/octet-stream");
+
private static final InputStream emptyInputStream = new InputStream() {
public int read() throws IOException {
return -1;
@@ -37,6 +42,11 @@ public class EmptyDataSource implements
private final String contentType;
+ /**
+ * Construct an empty data source with the given content type.
+ *
+ * @param contentType the content type
+ */
public EmptyDataSource(String contentType) {
this.contentType = contentType;
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java?rev=1034539&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java
Fri Nov 12 19:35:45 2010
@@ -0,0 +1,33 @@
+/*
+ * 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.util.activation;
+
+import javax.activation.DataHandler;
+
+import junit.framework.TestCase;
+
+public class DataHandlerWrapperTest extends TestCase {
+ public void test() {
+ DataHandler dataHandler = new DataHandler("<root/>", "text/plain;
charset=UTF-8");
+ DataHandler wrapper = new DataHandlerWrapper(dataHandler);
+ assertEquals(dataHandler.getContentType(), wrapper.getContentType());
+ assertEquals(dataHandler.getName(), wrapper.getName());
+ assertSame(dataHandler.getDataSource(), wrapper.getDataSource());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/util/activation/DataHandlerWrapperTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]