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/axis-axis2-java-core.git
The following commit(s) were added to refs/heads/master by this push: new 1fbcee6325 Remove MessageFormatterEx 1fbcee6325 is described below commit 1fbcee6325ae905ea55f8c9cba37687428c4f7d3 Author: Andreas Veithen <andreas.veit...@gmail.com> AuthorDate: Mon Nov 21 00:57:31 2022 +0000 Remove MessageFormatterEx Instead declare getDataSource as a default method on MessageFormatter. --- .../org/apache/axis2/kernel/MessageFormatter.java | 23 ++++++ .../org/apache/axis2/format/BinaryFormatter.java | 3 +- .../apache/axis2/format/MessageFormatterEx.java | 44 ------------ .../axis2/format/MessageFormatterExAdapter.java | 83 ---------------------- .../apache/axis2/format/PlainTextFormatter.java | 3 +- .../axis2/transport/mail/MailTransportSender.java | 11 +-- 6 files changed, 28 insertions(+), 139 deletions(-) diff --git a/modules/kernel/src/org/apache/axis2/kernel/MessageFormatter.java b/modules/kernel/src/org/apache/axis2/kernel/MessageFormatter.java index 5271b3239e..f5148e1642 100644 --- a/modules/kernel/src/org/apache/axis2/kernel/MessageFormatter.java +++ b/modules/kernel/src/org/apache/axis2/kernel/MessageFormatter.java @@ -19,13 +19,19 @@ package org.apache.axis2.kernel; +import org.apache.axiom.blob.Blobs; +import org.apache.axiom.blob.MemoryBlob; +import org.apache.axiom.blob.MemoryBlobOutputStream; import org.apache.axiom.om.OMOutputFormat; +import org.apache.axiom.util.activation.BlobDataSource; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; import java.io.OutputStream; import java.net.URL; +import javax.activation.DataSource; + /** * <p/> * MessageFormatter implementations are used by Axis2 to support serialization @@ -81,4 +87,21 @@ public interface MessageFormatter { */ public String formatSOAPAction(MessageContext messageContext, OMOutputFormat format, String soapAction); + + /** + * Get the formatted message as a {@link DataSource} object. + * + * @param messageContext + * @param format + * @param soapAction + * @return + * @throws AxisFault + */ + default DataSource getDataSource(MessageContext messageContext, OMOutputFormat format, String soapAction) throws AxisFault { + MemoryBlob blob = Blobs.createMemoryBlob(); + MemoryBlobOutputStream out = blob.getOutputStream(); + writeTo(messageContext, format, out, false); + out.close(); + return new BlobDataSource(blob, getContentType(messageContext, format, soapAction)); + } } diff --git a/modules/transport/base/src/main/java/org/apache/axis2/format/BinaryFormatter.java b/modules/transport/base/src/main/java/org/apache/axis2/format/BinaryFormatter.java index ae59ff6622..a183c3f034 100644 --- a/modules/transport/base/src/main/java/org/apache/axis2/format/BinaryFormatter.java +++ b/modules/transport/base/src/main/java/org/apache/axis2/format/BinaryFormatter.java @@ -32,10 +32,11 @@ import org.apache.axiom.om.OMText; import org.apache.axiom.util.activation.DataHandlerUtils; import org.apache.axis2.AxisFault; import org.apache.axis2.context.MessageContext; +import org.apache.axis2.kernel.MessageFormatter; import org.apache.axis2.kernel.http.util.URLTemplatingUtil; import org.apache.axis2.transport.base.BaseConstants; -public class BinaryFormatter implements MessageFormatterEx { +public class BinaryFormatter implements MessageFormatter { private Blob getBlob(MessageContext messageContext) { OMElement firstChild = messageContext.getEnvelope().getBody().getFirstElement(); if (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) { diff --git a/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterEx.java b/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterEx.java deleted file mode 100644 index 0653bb05ab..0000000000 --- a/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterEx.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.axis2.format; - -import javax.activation.DataSource; - -import org.apache.axiom.om.OMOutputFormat; -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.kernel.MessageFormatter; - -/** - * Message formatter with extended capabilities. - * This interface adds new methods to the {@link MessageFormatter} - * interface, allowing transport to optimize data transfers. - */ -public interface MessageFormatterEx extends MessageFormatter { - /** - * Get the formatted message as a {@link DataSource} object. - * - * @param messageContext - * @param format - * @param soapAction - * @return - * @throws AxisFault - */ - DataSource getDataSource(MessageContext messageContext, OMOutputFormat format, String soapAction) throws AxisFault; -} diff --git a/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterExAdapter.java b/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterExAdapter.java deleted file mode 100644 index 5cd0eeaef6..0000000000 --- a/modules/transport/base/src/main/java/org/apache/axis2/format/MessageFormatterExAdapter.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.axis2.format; - -import java.io.OutputStream; -import java.net.URL; - -import javax.activation.DataSource; - -import org.apache.axiom.blob.Blobs; -import org.apache.axiom.blob.MemoryBlob; -import org.apache.axiom.blob.MemoryBlobOutputStream; -import org.apache.axiom.om.OMOutputFormat; -import org.apache.axiom.util.activation.BlobDataSource; -import org.apache.axis2.AxisFault; -import org.apache.axis2.context.MessageContext; -import org.apache.axis2.kernel.MessageFormatter; - -/** - * Adapter to add the {@link MessageFormatterEx} interface to an - * existing {@link MessageFormatter}. - * It implements the {@link MessageFormatterEx#getDataSource(MessageContext, OMOutputFormat, String)} method - * using {@link MessageFormatter#writeTo(MessageContext, OMOutputFormat, OutputStream, boolean)} and - * {@link MessageFormatter#getContentType(MessageContext, OMOutputFormat, String)}. - */ -public class MessageFormatterExAdapter implements MessageFormatterEx { - private final MessageFormatter messageFormatter; - - public MessageFormatterExAdapter(MessageFormatter messageFormatter) { - this.messageFormatter = messageFormatter; - } - - public DataSource getDataSource(MessageContext messageContext, - OMOutputFormat format, - String soapAction) throws AxisFault { - MemoryBlob blob = Blobs.createMemoryBlob(); - MemoryBlobOutputStream out = blob.getOutputStream(); - writeTo(messageContext, format, out, false); - out.close(); - return new BlobDataSource(blob, getContentType(messageContext, format, soapAction)); - } - - public String formatSOAPAction(MessageContext messageContext, - OMOutputFormat format, - String soapAction) { - return messageFormatter.formatSOAPAction(messageContext, format, soapAction); - } - - public String getContentType(MessageContext messageContext, - OMOutputFormat format, - String soapAction) { - return messageFormatter.getContentType(messageContext, format, soapAction); - } - - public URL getTargetAddress(MessageContext messageContext, - OMOutputFormat format, - URL targetURL) throws AxisFault { - return messageFormatter.getTargetAddress(messageContext, format, targetURL); - } - - public void writeTo(MessageContext messageContext, - OMOutputFormat format, - OutputStream outputStream, - boolean preserve) throws AxisFault { - messageFormatter.writeTo(messageContext, format, outputStream, preserve); - } -} diff --git a/modules/transport/base/src/main/java/org/apache/axis2/format/PlainTextFormatter.java b/modules/transport/base/src/main/java/org/apache/axis2/format/PlainTextFormatter.java index cb955b8a98..6f391e6ab1 100644 --- a/modules/transport/base/src/main/java/org/apache/axis2/format/PlainTextFormatter.java +++ b/modules/transport/base/src/main/java/org/apache/axis2/format/PlainTextFormatter.java @@ -19,6 +19,7 @@ package org.apache.axis2.format; +import org.apache.axis2.kernel.MessageFormatter; import org.apache.axis2.kernel.http.util.URLTemplatingUtil; import org.apache.axis2.context.MessageContext; import org.apache.axis2.AxisFault; @@ -34,7 +35,7 @@ import java.net.URL; import javax.activation.DataSource; -public class PlainTextFormatter implements MessageFormatterEx { +public class PlainTextFormatter implements MessageFormatter { public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault { OMElement textElt = messageContext.getEnvelope().getBody().getFirstElement(); if (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(textElt.getQName())) { diff --git a/modules/transport/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java b/modules/transport/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java index 7236ad4789..6b63a6da2b 100644 --- a/modules/transport/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java +++ b/modules/transport/mail/src/main/java/org/apache/axis2/transport/mail/MailTransportSender.java @@ -19,8 +19,6 @@ package org.apache.axis2.transport.mail; -import org.apache.axis2.format.MessageFormatterEx; -import org.apache.axis2.format.MessageFormatterExAdapter; import org.apache.axis2.transport.base.*; import org.apache.commons.logging.LogFactory; import org.apache.axis2.context.ConfigurationContext; @@ -409,14 +407,7 @@ public class MailTransportSender extends AbstractTransportSender message.setHeader(BaseConstants.SOAPACTION, msgContext.getSoapAction()); // write body - MessageFormatterEx messageFormatterEx; - if (messageFormatter instanceof MessageFormatterEx) { - messageFormatterEx = (MessageFormatterEx)messageFormatter; - } else { - messageFormatterEx = new MessageFormatterExAdapter(messageFormatter); - } - - DataHandler dataHandler = new DataHandler(messageFormatterEx.getDataSource(msgContext, format, msgContext.getSoapAction())); + DataHandler dataHandler = new DataHandler(messageFormatter.getDataSource(msgContext, format, msgContext.getSoapAction())); MimeMultipart mimeMultiPart = null;