You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/02/03 19:50:10 UTC

(camel) branch fu2 created (now d27c6f9c1f7)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a change to branch fu2
in repository https://gitbox.apache.org/repos/asf/camel.git


      at d27c6f9c1f7 CAMEL-21700: camel-attachments - Fix when wrapping to AttachmentMessage then the exchange should adapt as well

This branch includes the following new commits:

     new d27c6f9c1f7 CAMEL-21700: camel-attachments - Fix when wrapping to AttachmentMessage then the exchange should adapt as well

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-21700: camel-attachments - Fix when wrapping to AttachmentMessage then the exchange should adapt as well

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch fu2
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d27c6f9c1f7a5d22db0199e0152fb07c0817a567
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Feb 3 20:48:38 2025 +0100

    CAMEL-21700: camel-attachments - Fix when wrapping to AttachmentMessage then the exchange should adapt as well
---
 .../java/org/apache/camel/attachment/AttachmentConverter.java  | 10 +++++++++-
 .../java/org/apache/camel/attachment/AttachmentMessage.java    |  6 ++++++
 .../org/apache/camel/attachment/DefaultAttachmentMessage.java  |  6 ++++++
 .../java/org/apache/camel/component/mail/MailConsumer.java     |  9 +++++++--
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentConverter.java b/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentConverter.java
index d4ff827c44b..9fcf132a725 100644
--- a/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentConverter.java
+++ b/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentConverter.java
@@ -32,7 +32,15 @@ public final class AttachmentConverter {
 
     @Converter
     public static AttachmentMessage toAttachmentMessage(final Message message) {
-        return new DefaultAttachmentMessage(message);
+        AttachmentMessage answer;
+        if (message instanceof AttachmentMessage am) {
+            answer = am;
+        } else {
+            answer = new DefaultAttachmentMessage(message);
+            // need to wrap exchange message as attachment capable
+            message.getExchange().setMessage(answer);
+        }
+        return answer;
     }
 
     @Converter
diff --git a/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentMessage.java b/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentMessage.java
index b97461a09c3..44240d265e7 100644
--- a/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentMessage.java
+++ b/components/camel-attachments/src/main/java/org/apache/camel/attachment/AttachmentMessage.java
@@ -28,6 +28,12 @@ import org.apache.camel.Message;
  */
 public interface AttachmentMessage extends Message {
 
+    /**
+     * The {@link AttachmentMessage} will wrap the previous {@link Message} and this method gives access to the previous
+     * message instance.
+     */
+    Message getDelegateMessage();
+
     /**
      * Returns the attachment specified by the id
      *
diff --git a/components/camel-attachments/src/main/java/org/apache/camel/attachment/DefaultAttachmentMessage.java b/components/camel-attachments/src/main/java/org/apache/camel/attachment/DefaultAttachmentMessage.java
index 71ab662adb0..10e53c88b78 100644
--- a/components/camel-attachments/src/main/java/org/apache/camel/attachment/DefaultAttachmentMessage.java
+++ b/components/camel-attachments/src/main/java/org/apache/camel/attachment/DefaultAttachmentMessage.java
@@ -29,6 +29,7 @@ import org.apache.camel.Message;
 import org.apache.camel.trait.message.MessageTrait;
 
 public final class DefaultAttachmentMessage implements AttachmentMessage {
+
     /*
      * Attachments are stores as a property on the {@link Exchange} which ensures they are propagated
      * during routing and we dont have to pollute the generic {@link Message} with attachment APIs
@@ -43,6 +44,11 @@ public final class DefaultAttachmentMessage implements AttachmentMessage {
         this.exchange = delegate.getExchange();
     }
 
+    @Override
+    public Message getDelegateMessage() {
+        return delegate;
+    }
+
     @Override
     public void reset() {
         delegate.reset();
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
index 4a818e112d9..df65c51e00b 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
@@ -233,8 +233,13 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
             // update pending number of exchanges
             pendingExchanges = total - index - 1;
 
-            // must use the original message in case we need to workaround a charset issue when extracting mail content
-            final Message mail = exchange.getIn(MailMessage.class).getOriginalMessage();
+            // must use the original message in case we need to work around a charset issue when extracting mail content
+            var msg = exchange.getIn();
+            if (msg instanceof AttachmentMessage am) {
+                // unwrap from attachment message
+                msg = am.getDelegateMessage();
+            }
+            final Message mail = ((MailMessage) msg).getOriginalMessage();
 
             // add on completion to handle after work when the exchange is done
             exchange.getExchangeExtension().addOnCompletion(new SynchronizationAdapter() {