Author: veithen
Date: Sat Nov 13 00:34:16 2010
New Revision: 1034613
URL: http://svn.apache.org/viewvc?rev=1034613&view=rev
Log:
AXIOM-275: Added a non JavaMail implementation of MultipartWriter. This
implementation allows streaming of the SOAP part and is now the default.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/package.html
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/JavaMailMultipartWriterFactory.java
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/OMMultipartWriter.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java?rev=1034613&r1=1034612&r2=1034613&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/MultipartWriter.java
Sat Nov 13 00:34:16 2010
@@ -58,7 +58,8 @@ public interface MultipartWriter {
* @param contentType
* the value of the <tt>Content-Type</tt> header of the MIME
part
* @param contentTransferEncoding
- * the content transfer encoding to be used (see above)
+ * the content transfer encoding to be used (see above); must
not be
+ * <code>null</code>
* @param contentID
* the content ID of the MIME part (see above)
* @return an output stream to write the content of the MIME part
@@ -75,7 +76,8 @@ public interface MultipartWriter {
* @param dataHandler
* the content of the MIME part to write
* @param contentTransferEncoding
- * the content transfer encoding to be used (see above)
+ * the content transfer encoding to be used (see above); must
not be
+ * <code>null</code>
* @param contentID
* the content ID of the MIME part (see above)
* @throws IOException
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java?rev=1034613&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java
Sat Nov 13 00:34:16 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.mime.impl.axiom;
+
+import java.io.OutputStream;
+
+import org.apache.axiom.mime.MultipartWriter;
+import org.apache.axiom.mime.MultipartWriterFactory;
+
+/**
+ * Factory for Axiom's own {...@link MultipartWriter} implementation.
+ */
+public class AxiomMultipartWriterFactory implements MultipartWriterFactory {
+ public static MultipartWriterFactory INSTANCE = new
AxiomMultipartWriterFactory();
+
+ public MultipartWriter createMultipartWriter(OutputStream out, String
boundary) {
+ return new MultipartWriterImpl(out, boundary);
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/AxiomMultipartWriterFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java?rev=1034613&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
Sat Nov 13 00:34:16 2010
@@ -0,0 +1,123 @@
+/*
+ * 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.mime.impl.axiom;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.activation.DataHandler;
+
+import org.apache.axiom.mime.MultipartWriter;
+import org.apache.axiom.util.base64.Base64EncodingOutputStream;
+
+class MultipartWriterImpl implements MultipartWriter {
+ class PartOutputStream extends OutputStream {
+ private final OutputStream parent;
+
+ public PartOutputStream(OutputStream parent) {
+ this.parent = parent;
+ }
+
+ public void write(int b) throws IOException {
+ parent.write(b);
+ }
+
+ public void write(byte[] b, int off, int len) throws IOException {
+ parent.write(b, off, len);
+ }
+
+ public void write(byte[] b) throws IOException {
+ parent.write(b);
+ }
+
+ public void close() throws IOException {
+ parent.flush();
+ writeAscii("\r\n");
+ }
+ }
+
+ private final OutputStream out;
+ private final String boundary;
+ private final byte[] buffer = new byte[256];
+
+ public MultipartWriterImpl(OutputStream out, String boundary) {
+ this.out = out;
+ this.boundary = boundary;
+ }
+
+ void writeAscii(String s) throws IOException {
+ int count = 0;
+ for (int i=0, len=s.length(); i<len; i++) {
+ char c = s.charAt(i);
+ if (c >= 128) {
+ throw new IOException("Illegal character '" + c + "'");
+ }
+ buffer[count++] = (byte)c;
+ if (count == buffer.length) {
+ out.write(buffer);
+ count = 0;
+ }
+ }
+ if (count > 0) {
+ out.write(buffer, 0, count);
+ }
+ }
+
+ public OutputStream writePart(String contentType, String
contentTransferEncoding,
+ String contentID) throws IOException {
+ OutputStream transferEncoder;
+ if (contentTransferEncoding.equals("8bit") ||
contentTransferEncoding.equals("binary")) {
+ transferEncoder = out;
+ } else {
+ // We support no content transfer encodings other than 8bit,
binary and base64.
+ transferEncoder = new Base64EncodingOutputStream(out);
+ contentTransferEncoding = "base64";
+ }
+ writeAscii("--");
+ writeAscii(boundary);
+ // TODO: specify if contentType == null is legal and check what to do
+ if (contentType != null) {
+ writeAscii("\r\nContent-Type: ");
+ writeAscii(contentType);
+ }
+ writeAscii("\r\nContent-Transfer-Encoding: ");
+ writeAscii(contentTransferEncoding);
+ // TODO: specify that the content ID may be null
+ if (contentID != null) {
+ writeAscii("\r\nContent-ID: <");
+ writeAscii(contentID);
+ out.write('>');
+ }
+ writeAscii("\r\n\r\n");
+ return new PartOutputStream(transferEncoder);
+ }
+
+ public void writePart(DataHandler dataHandler, String
contentTransferEncoding, String contentID)
+ throws IOException {
+ OutputStream partOutputStream =
writePart(dataHandler.getContentType(), contentTransferEncoding, contentID);
+ dataHandler.writeTo(partOutputStream);
+ partOutputStream.close();
+ }
+
+ public void complete() throws IOException {
+ writeAscii("--");
+ writeAscii(boundary);
+ writeAscii("--\r\n");
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/MultipartWriterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/package.html
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/package.html?rev=1034613&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/package.html
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/axiom/package.html
Sat Nov 13 00:34:16 2010
@@ -0,0 +1,23 @@
+<!--
+ ~ 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.
+ -->
+<html>
+<body>
+Default MIME message processing API implementation.
+</body>
+</html>
\ No newline at end of file
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/JavaMailMultipartWriterFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/JavaMailMultipartWriterFactory.java?rev=1034613&r1=1034612&r2=1034613&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/JavaMailMultipartWriterFactory.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/mime/impl/javamail/JavaMailMultipartWriterFactory.java
Sat Nov 13 00:34:16 2010
@@ -28,7 +28,6 @@ import org.apache.axiom.mime.MultipartWr
* Factory for the JavaMail based {...@link MultipartWriter} implementation.
*/
public class JavaMailMultipartWriterFactory implements MultipartWriterFactory {
- // TODO: we should have some sort of service locator to discover the
implementation
public static MultipartWriterFactory INSTANCE = new
JavaMailMultipartWriterFactory();
public MultipartWriter createMultipartWriter(OutputStream out, String
boundary) {
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=1034613&r1=1034612&r2=1034613&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 00:34:16 2010
@@ -21,6 +21,8 @@ package org.apache.axiom.om;
import java.util.HashMap;
+import org.apache.axiom.mime.MultipartWriterFactory;
+import org.apache.axiom.mime.impl.axiom.AxiomMultipartWriterFactory;
import org.apache.axiom.om.impl.MTOMConstants;
import org.apache.axiom.om.util.StAXWriterConfiguration;
import org.apache.axiom.om.util.XMLStreamWriterFilter;
@@ -64,6 +66,8 @@ public class OMOutputFormat {
private XMLStreamWriterFilter xmlStreamWriterFilter = null;
private StAXWriterConfiguration writerConfiguration;
+
+ private MultipartWriterFactory multipartWriterFactory;
// The value of this property is a Boolean.
// A missing value indicates the default action, which is Boolean.FALSE
@@ -428,4 +432,27 @@ public class OMOutputFormat {
public void setStAXWriterConfiguration(StAXWriterConfiguration
writerConfiguration) {
this.writerConfiguration = writerConfiguration;
}
+
+ /**
+ * Get the currently configured multipart writer factory.
+ *
+ * @return the current factory; if none has been set explicitly, an
+ * {...@link AxiomMultipartWriterFactory} instance is returned
+ */
+ public MultipartWriterFactory getMultipartWriterFactory() {
+ return multipartWriterFactory == null
+ ? AxiomMultipartWriterFactory.INSTANCE
+ : multipartWriterFactory;
+ }
+
+ /**
+ * Set the multipart writer factory. This factory is used to create MIME
packages when MTOM or
+ * SwA is enabled.
+ *
+ * @param multipartWriterFactory
+ * the factory
+ */
+ public void setMultipartWriterFactory(MultipartWriterFactory
multipartWriterFactory) {
+ this.multipartWriterFactory = multipartWriterFactory;
+ }
}
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=1034613&r1=1034612&r2=1034613&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 00:34:16 2010
@@ -26,7 +26,6 @@ import javax.activation.DataHandler;
import org.apache.axiom.attachments.ConfigurableDataHandler;
import org.apache.axiom.mime.MultipartWriter;
-import org.apache.axiom.mime.impl.javamail.JavaMailMultipartWriterFactory;
import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.om.util.CommonUtils;
import org.apache.axiom.soap.SOAP11Constants;
@@ -46,8 +45,7 @@ public class OMMultipartWriter {
public OMMultipartWriter(OutputStream out, OMOutputFormat format) {
this.format = format;
- // TODO: need some config mechanism to look up the factory
- writer =
JavaMailMultipartWriterFactory.INSTANCE.createMultipartWriter(out,
+ writer = format.getMultipartWriterFactory().createMultipartWriter(out,
format.getMimeBoundary());
useCTEBase64 = format != null && Boolean.TRUE.equals(
@@ -111,10 +109,11 @@ public class OMMultipartWriter {
* if an I/O error occurs when writing the part to the
underlying stream
*/
public void writePart(DataHandler dataHandler, String contentID) throws
IOException {
- String contentTransferEncoding;
+ String contentTransferEncoding = null;
if (dataHandler instanceof ConfigurableDataHandler) {
contentTransferEncoding =
((ConfigurableDataHandler)dataHandler).getTransferEncoding();
- } else {
+ }
+ if (contentTransferEncoding == null) {
contentTransferEncoding =
getContentTransferEncoding(dataHandler.getContentType());
}
writer.writePart(dataHandler, contentTransferEncoding, contentID);
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java?rev=1034613&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java
Sat Nov 13 00:34:16 2010
@@ -0,0 +1,75 @@
+/*
+ * 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.base64;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * {...@link OutputStream} implementation that writes base64 encoded data to
another
+ * {...@link OutputStream} using ASCII encoding. This class internally buffers
the data before writing
+ * it to the underlying stream.
+ */
+public class Base64EncodingOutputStream extends
AbstractBase64EncodingOutputStream {
+ private final OutputStream parent;
+ private final byte[] buffer;
+ private int len;
+
+ /**
+ * Constructor.
+ *
+ * @param parent the stream to write the encoded data to
+ * @param bufferSize the buffer size to use
+ */
+ public Base64EncodingOutputStream(OutputStream parent, int bufferSize) {
+ this.parent = parent;
+ buffer = new byte[bufferSize];
+ }
+
+ /**
+ * Constructor that sets the buffer size to its default value of 4096
characters.
+ *
+ * @param parent the stream to write the encoded data to
+ */
+ public Base64EncodingOutputStream(OutputStream parent) {
+ this(parent, 4096);
+ }
+
+ protected void doWrite(byte[] b) throws IOException {
+ if (buffer.length - len < 4) {
+ flushBuffer();
+ }
+ System.arraycopy(b, 0, buffer, len, 4);
+ len += 4;
+ }
+
+ protected void flushBuffer() throws IOException {
+ parent.write(buffer, 0, len);
+ len = 0;
+ }
+
+ protected void doFlush() throws IOException {
+ parent.flush();
+ }
+
+ protected void doClose() throws IOException {
+ parent.close();
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/util/base64/Base64EncodingOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]