camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1158295 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/management/mbean/ main/java/org/apache/camel/util/ test/java/org/apache/camel/management/ test/java/org/apache/camel/util/
Date Tue, 16 Aug 2011 14:37:33 GMT
Author: davsclaus
Date: Tue Aug 16 14:37:32 2011
New Revision: 1158295

URL: http://svn.apache.org/viewvc?rev=1158295&view=rev
Log:
CAMEL-4338: Include exchangeId in xml messages so in JMX browsable endpoint. Be backwards
compatible, marked old method as @deprecated.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBrowsableEndpoint.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointAsXmlTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBrowsableEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBrowsableEndpoint.java?rev=1158295&r1=1158294&r2=1158295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBrowsableEndpoint.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBrowsableEndpoint.java
Tue Aug 16 14:37:32 2011
@@ -85,6 +85,15 @@ public class ManagedBrowsableEndpoint ex
         return body;
     }
 
+    /**
+     * @deprecated use {@link #browseAllMessagesAsXml(Boolean)} instead
+     */
+    @ManagedOperation(description = "Get message as XML from queue by index")
+    @Deprecated
+    public String browseMessageAsXml(Integer index) {
+        return browseMessageAsXml(index, true);
+    }
+
     @ManagedOperation(description = "Get message as XML from queue by index")
     public String browseMessageAsXml(Integer index, Boolean includeBody) {
         List<Exchange> exchanges = endpoint.getExchanges();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java?rev=1158295&r1=1158294&r2=1158295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/MessageHelper.java Tue Aug
16 14:37:32 2011
@@ -263,7 +263,8 @@ public final class MessageHelper {
      */
     public static String dumpAsXml(Message message, boolean includeBody) {
         StringBuilder sb = new StringBuilder();
-        sb.append("<message>\n");
+        // include exchangeId as attribute on the <message> tag
+        sb.append("<message exchangeId=\"").append(message.getExchange().getExchangeId()).append("\">\n");
 
         // headers
         if (message.hasHeaders()) {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointAsXmlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointAsXmlTest.java?rev=1158295&r1=1158294&r2=1158295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointAsXmlTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointAsXmlTest.java
Tue Aug 16 14:37:32 2011
@@ -17,10 +17,12 @@
 package org.apache.camel.management;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 
 /**
@@ -45,6 +47,8 @@ public class ManagedBrowseableEndpointAs
 
         assertMockEndpointsSatisfied();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
@@ -53,41 +57,42 @@ public class ManagedBrowseableEndpointAs
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<message>\n<body type=\"java.lang.String\">&lt;foo&gt;Camel
&amp;gt; Donkey&lt;/foo&gt;</body>\n</message>", out);
+        assertEquals("<message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n<body
type=\"java.lang.String\">&lt;foo&gt;Camel &amp;gt; Donkey&lt;/foo&gt;</body>\n</message>",
out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{1, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<body type=\"java.lang.String\">Camel &gt;
Donkey</body>\n</message>", out);
+        assertEquals("<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<body
type=\"java.lang.String\">Camel &gt; Donkey</body>\n</message>", out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{2, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"name\" type=\"java.lang.String\">Me
&amp; You</header>\n</headers>\n"
+        assertEquals("<message exchangeId=\"" + exchanges.get(2).getExchangeId() + "\">\n<headers>\n<header
key=\"name\" type=\"java.lang.String\">Me &amp; You</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">&lt;foo&gt;Camel &amp;gt;
Donkey&lt;/foo&gt;</body>\n</message>", out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{3, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"title\" type=\"java.lang.String\">&lt;title&gt;Me
&amp;amp; You&lt;/title&gt;</header>\n</headers>\n"
+        assertEquals("<message exchangeId=\"" + exchanges.get(3).getExchangeId() + "\">\n<headers>\n"
+                + "<header key=\"title\" type=\"java.lang.String\">&lt;title&gt;Me
&amp;amp; You&lt;/title&gt;</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">&lt;foo&gt;Camel &amp;gt;
Donkey&lt;/foo&gt;</body>\n</message>", out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{4, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"name\" type=\"java.lang.String\">Me
&amp; You</header>\n</headers>\n"
+        assertEquals("<message exchangeId=\"" + exchanges.get(4).getExchangeId() + "\">\n<headers>\n<header
key=\"name\" type=\"java.lang.String\">Me &amp; You</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">Camel &gt; Donkey</body>\n</message>",
out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{5, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"user\" type=\"java.lang.Boolean\">true</header>\n</headers>\n"
+        assertEquals("<message exchangeId=\"" + exchanges.get(5).getExchangeId() + "\">\n<headers>\n<header
key=\"user\" type=\"java.lang.Boolean\">true</header>\n</headers>\n"
                 + "<body type=\"java.lang.Integer\">123</body>\n</message>",
out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{6, true},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"title\" type=\"java.lang.String\">Camel
rocks</header>\n"
+        assertEquals("<message exchangeId=\"" + exchanges.get(6).getExchangeId() + "\">\n<headers>\n<header
key=\"title\" type=\"java.lang.String\">Camel rocks</header>\n"
                 + "<header key=\"uid\" type=\"java.lang.Integer\">123</header>\n"
                 + "<header key=\"user\" type=\"java.lang.Boolean\">false</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">&lt;animal&gt;&lt;name&gt;Donkey&lt;/name&gt;&lt;age&gt;17&lt;/age&gt;&lt;/animal&gt;</body>\n</message>",
out);
@@ -101,6 +106,8 @@ public class ManagedBrowseableEndpointAs
 
         assertMockEndpointsSatisfied();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
@@ -109,12 +116,12 @@ public class ManagedBrowseableEndpointAs
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>",
out);
+        assertEquals("<message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>",
out);
 
         out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[]{1, false},
new String[]{"java.lang.Integer", "java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
-        assertEquals("<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n</message>",
out);
+        assertEquals("<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n</message>",
out);
     }
 
     public void testBrowseableEndpointAsXmlAllIncludeBody() throws Exception {
@@ -125,6 +132,8 @@ public class ManagedBrowseableEndpointAs
 
         assertMockEndpointsSatisfied();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
@@ -133,8 +142,8 @@ public class ManagedBrowseableEndpointAs
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<messages>\n<message>\n<body type=\"java.lang.String\">Hello
World</body>\n</message>\n"
-                + "<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
+        assertEquals("<messages>\n<message exchangeId=\"" + exchanges.get(0).getExchangeId()
+ "\">\n<body type=\"java.lang.String\">Hello World</body>\n</message>\n"
+                + "<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">Bye World</body>\n</message>\n</messages>",
out);
     }
 
@@ -148,14 +157,18 @@ public class ManagedBrowseableEndpointAs
 
         MBeanServer mbeanServer = getMBeanServer();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
 
         String out = (String) mbeanServer.invoke(name, "browseAllMessagesAsXml", new Object[]{false},
new String[]{"java.lang.Boolean"});
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<messages>\n<message>\n<headers>\n<header key=\"foo\"
type=\"java.lang.Integer\">123</header>\n</headers>\n</message>\n"
-                + "<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n</message>\n</messages>",
out);
+        assertEquals("<messages>\n<message exchangeId=\"" + exchanges.get(0).getExchangeId()
+ "\">\n<headers>\n"
+                + "<header key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>\n"
+                + "<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
+                + "</message>\n</messages>", out);
     }
 
     public void testBrowseableEndpointAsXmlRangeIncludeBody() throws Exception {
@@ -167,6 +180,8 @@ public class ManagedBrowseableEndpointAs
 
         assertMockEndpointsSatisfied();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
@@ -175,8 +190,8 @@ public class ManagedBrowseableEndpointAs
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<messages>\n<message>\n<body type=\"java.lang.String\">Hello
World</body>\n</message>\n"
-                + "<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
+        assertEquals("<messages>\n<message exchangeId=\"" + exchanges.get(0).getExchangeId()
+ "\">\n<body type=\"java.lang.String\">Hello World</body>\n</message>\n"
+                + "<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
                 + "<body type=\"java.lang.String\">Bye World</body>\n</message>\n</messages>",
out);
     }
 
@@ -189,6 +204,8 @@ public class ManagedBrowseableEndpointAs
 
         assertMockEndpointsSatisfied();
 
+        List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
+
         MBeanServer mbeanServer = getMBeanServer();
 
         ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://result\"");
@@ -197,8 +214,9 @@ public class ManagedBrowseableEndpointAs
         assertNotNull(out);
         log.info(out);
 
-        assertEquals("<messages>\n<message>\n<headers>\n<header key=\"foo\"
type=\"java.lang.Integer\">123</header>\n</headers>\n</message>\n"
-                + "<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n</message>\n</messages>",
out);
+        assertEquals("<messages>\n<message exchangeId=\"" + exchanges.get(0).getExchangeId()
+ "\">\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>\n"
+                + "<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n<headers>\n<header
key=\"foo\" type=\"java.lang.Integer\">456</header>\n</headers>\n"
+                + "</message>\n</messages>", out);
     }
 
     public void testBrowseableEndpointAsXmlRangeInvalidIndex() throws Exception {

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java?rev=1158295&r1=1158294&r2=1158295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/MessageHelperTest.java Tue
Aug 16 14:37:32 2011
@@ -130,6 +130,7 @@ public class MessageHelperTest extends T
 
         String out = MessageHelper.dumpAsXml(message);
         assertTrue("Should contain body", out.contains("<body type=\"java.lang.String\">&lt;?xml
version=&quot;1.0&quot;?&gt;&lt;hi&gt;Hello World&lt;/hi&gt;</body>"));
+        assertTrue("Should contain exchangeId", out.contains(message.getExchange().getExchangeId()));
 
         context.stop();
     }
@@ -145,7 +146,9 @@ public class MessageHelperTest extends T
         message.setHeader("foo", 123);
 
         String out = MessageHelper.dumpAsXml(message, false);
-        assertEquals("<message>\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>",
out);
+
+        assertEquals("<message exchangeId=\"" + message.getExchange().getExchangeId()
+ "\">"
+                + "\n<headers>\n<header key=\"foo\" type=\"java.lang.Integer\">123</header>\n</headers>\n</message>",
out);
 
         context.stop();
     }



Mime
View raw message