karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject karaf-decanter git commit: [KARAF-4647] Make sure we send maps as object not as String
Date Fri, 05 Aug 2016 07:27:27 GMT
Repository: karaf-decanter
Updated Branches:
  refs/heads/master c5235eae0 -> f3f93755b


[KARAF-4647] Make sure we send maps as object not as String


Project: http://git-wip-us.apache.org/repos/asf/karaf-decanter/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-decanter/commit/f3f93755
Tree: http://git-wip-us.apache.org/repos/asf/karaf-decanter/tree/f3f93755
Diff: http://git-wip-us.apache.org/repos/asf/karaf-decanter/diff/f3f93755

Branch: refs/heads/master
Commit: f3f93755b672fff0ce5e87003e875f89cecb68d1
Parents: c5235ea
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Aug 5 09:27:13 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Fri Aug 5 09:27:13 2016 +0200

----------------------------------------------------------------------
 .../karaf/decanter/appender/jms/JmsAppender.java | 19 ++++++++++++-------
 .../decanter/appender/jms/JmsAppenderTest.java   |  3 +++
 2 files changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/f3f93755/appender/jms/src/main/java/org/apache/karaf/decanter/appender/jms/JmsAppender.java
----------------------------------------------------------------------
diff --git a/appender/jms/src/main/java/org/apache/karaf/decanter/appender/jms/JmsAppender.java
b/appender/jms/src/main/java/org/apache/karaf/decanter/appender/jms/JmsAppender.java
index 021c491..38d9bb4 100644
--- a/appender/jms/src/main/java/org/apache/karaf/decanter/appender/jms/JmsAppender.java
+++ b/appender/jms/src/main/java/org/apache/karaf/decanter/appender/jms/JmsAppender.java
@@ -17,6 +17,7 @@
 package org.apache.karaf.decanter.appender.jms;
 
 import java.util.Dictionary;
+import java.util.Map;
 
 import javax.jms.*;
 
@@ -94,18 +95,22 @@ public class JmsAppender implements EventHandler {
         if (value == null) {
             return;
         }
-        if (value instanceof String)
+        if (value instanceof String) {
             message.setString(name, (String) value);
-        else if (value instanceof Boolean)
+        } else if (value instanceof Boolean) {
             message.setBoolean(name, (Boolean) value);
-        else if (value instanceof Double)
+        } else if (value instanceof Double) {
             message.setDouble(name, (Double) value);
-        else if (value instanceof Integer)
+        } else if (value instanceof Integer) {
             message.setInt(name, (Integer) value);
-        else if (value instanceof Long)
+        } else if (value instanceof Long) {
             message.setLong(name, (Long) value);
-        else message.setString(name, value.toString());
-        // we can setObject with List, Map, but they have to contain only primitives
+        } else if (value instanceof Map) {
+            // Must only contain primitives
+            message.setObject(name, value);
+        } else {
+            message.setString(name, value.toString());
+        }
     }
 
     private Destination createDestination(Session session) throws JMSException {

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/f3f93755/appender/jms/src/test/java/org/apache/karaf/decanter/appender/jms/JmsAppenderTest.java
----------------------------------------------------------------------
diff --git a/appender/jms/src/test/java/org/apache/karaf/decanter/appender/jms/JmsAppenderTest.java
b/appender/jms/src/test/java/org/apache/karaf/decanter/appender/jms/JmsAppenderTest.java
index dfb3a64..d1a1c9e 100644
--- a/appender/jms/src/test/java/org/apache/karaf/decanter/appender/jms/JmsAppenderTest.java
+++ b/appender/jms/src/test/java/org/apache/karaf/decanter/appender/jms/JmsAppenderTest.java
@@ -56,6 +56,7 @@ public class JmsAppenderTest {
         props.put("boolean", true);
         props.put("integer", 1);
         props.put("testnull", null);
+        props.put("map", new HashMap<String, String>());
         appender.handleEvent(new Event("decanter/collect", props));
         
         MapMessage message = (MapMessage)consumer.receive(1000);
@@ -67,5 +68,7 @@ public class JmsAppenderTest {
         Assert.assertEquals("test", message.getObject("string"));
         Assert.assertEquals(true, message.getObject("boolean"));
         Assert.assertEquals(1, message.getObject("integer"));
+        Object map = message.getObject("map");
+        Assert.assertTrue(map instanceof Map);
     }
 }


Mime
View raw message