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

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


The following commit(s) were added to refs/heads/master by this push:
     new 698c04d  CAMEL-12178 - add getMessage/setMessage to Exchange interface
698c04d is described below

commit 698c04dba0721f99abf04fee2030fb64b3601b69
Author: Quinn Stevenson <qu...@apache.org>
AuthorDate: Mon Jan 22 16:18:23 2018 -0700

    CAMEL-12178 - add getMessage/setMessage to Exchange interface
---
 .../src/main/java/org/apache/camel/Exchange.java   | 22 ++++++++++++++++++++++
 .../org/apache/camel/impl/DefaultExchange.java     | 17 +++++++++++++++++
 .../org/apache/camel/scala/RichExchange.scala      |  6 ++++++
 3 files changed, 45 insertions(+)

diff --git a/camel-core/src/main/java/org/apache/camel/Exchange.java 
b/camel-core/src/main/java/org/apache/camel/Exchange.java
index 3ec0fea..541ea16 100644
--- a/camel-core/src/main/java/org/apache/camel/Exchange.java
+++ b/camel-core/src/main/java/org/apache/camel/Exchange.java
@@ -363,6 +363,28 @@ public interface Exchange {
     Message getIn();
 
     /**
+     * Returns the current message
+     *
+     * @return the current message
+     */
+    Message getMessage();
+
+    /**
+     * Returns the current message as the given type
+     *
+     * @param type the given type
+     * @return the message as the given type or <tt>null</tt> if not possible 
to covert to given type
+     */
+    <T> T getMessage(Class<T> type);
+
+    /**
+     * Replace the current message instance.
+     *
+     * @param message the new message
+     */
+    void setMessage(Message message);
+
+    /**
      * Returns the inbound request message as the given type
      *
      * @param type the given type
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
index 417eaae..cccbc72 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
@@ -350,6 +350,23 @@ public final class DefaultExchange implements Exchange {
         configureMessage(out);
     }
 
+    public Message getMessage() {
+        return hasOut() ? getOut() : getIn();
+    }
+
+    public <T> T getMessage(Class<T> type) {
+        return hasOut() ? getOut(type) : getIn(type);
+    }
+
+    public void setMessage(Message message) {
+        if (hasOut()) {
+            setOut(message);
+        } else {
+            setIn(message);
+        }
+    }
+
+
     public Exception getException() {
         return exception;
     }
diff --git 
a/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
 
b/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
index c63373e..aed771d 100644
--- 
a/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
+++ 
b/components/camel-scala/src/main/scala/org/apache/camel/scala/RichExchange.scala
@@ -136,4 +136,10 @@ class RichExchange(val exchange : Exchange) extends 
Exchange {
   def handoverCompletions = exchange.handoverCompletions
 
   def getCreated = exchange.getCreated
+
+  override def getMessage: Message = { if (hasOut) getOut else getIn }
+
+  override def getMessage[T](`type`: Class[T]): T = { if (hasOut) 
getOut(`type`) else getIn(`type`) }
+
+  override def setMessage(message: Message): Unit = { if (hasOut) 
setOut(message) else setIn(message) }
 }

-- 
To stop receiving notification emails like this one, please contact
qu...@apache.org.

Reply via email to