Merge pull request #223 from jbonofre/KARAF-6987

[KARAF-6987] Add host property on socket collector allowing to define the binding address/host
diff --git a/assembly/src/main/feature/feature.xml b/assembly/src/main/feature/feature.xml
index f8fe563..53b32b6 100644
--- a/assembly/src/main/feature/feature.xml
+++ b/assembly/src/main/feature/feature.xml
@@ -30,6 +30,7 @@
         <bundle>mvn:org.apache.karaf.decanter/org.apache.karaf.decanter.api/${project.version}</bundle>
         <bundle>mvn:org.apache.karaf.decanter.marshaller/org.apache.karaf.decanter.marshaller.raw/${project.version}</bundle>
         <bundle>mvn:org.apache.karaf.decanter.marshaller/org.apache.karaf.decanter.marshaller.json/${project.version}</bundle>
+        <configfile finalname="/etc/org.apache.karaf.decanter.marshaller.json.cfg">mvn:org.apache.karaf.decanter.marshaller/org.apache.karaf.decanter.marshaller.json/${project.version}/cfg</configfile>
         <bundle>mvn:org.apache.karaf.decanter.marshaller/org.apache.karaf.decanter.marshaller.csv/${project.version}</bundle>
         <bundle>mvn:org.apache.karaf.decanter.parser/org.apache.karaf.decanter.parser.identity/${project.version}</bundle>
         <configfile finalname="/etc/org.apache.karaf.decanter.parser.split.cfg">mvn:org.apache.karaf.decanter.parser/org.apache.karaf.decanter.parser.split/${project.version}/cfg</configfile>
diff --git a/marshaller/json/pom.xml b/marshaller/json/pom.xml
index 35fd6db..a461444 100644
--- a/marshaller/json/pom.xml
+++ b/marshaller/json/pom.xml
@@ -48,5 +48,29 @@
             <scope>test</scope>
         </dependency>
     </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>attach-artifact</goal>
+                        </goals>
+                        <configuration>
+                            <artifacts>
+                                <artifact>
+                                    <file>src/main/cfg/org.apache.karaf.decanter.marshaller.json.cfg</file>
+                                    <type>cfg</type>
+                                </artifact>
+                            </artifacts>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 
-</project>
\ No newline at end of file
+</project>
diff --git a/marshaller/json/src/main/cfg/org.apache.karaf.decanter.marshaller.json.cfg b/marshaller/json/src/main/cfg/org.apache.karaf.decanter.marshaller.json.cfg
new file mode 100644
index 0000000..b2690dd
--- /dev/null
+++ b/marshaller/json/src/main/cfg/org.apache.karaf.decanter.marshaller.json.cfg
@@ -0,0 +1,24 @@
+################################################################################
+#
+#    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.
+#
+################################################################################
+
+#
+# Decanter JSON marshaller configuration
+#
+
+# replaceDotsByUnderscores=true
diff --git a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
index 79347df..b006c51 100644
--- a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
+++ b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
@@ -59,7 +59,10 @@
 
     @Activate
     public void activate(ComponentContext componentContext) {
-        Dictionary<String, Object> config = componentContext.getProperties();
+	activate(componentContext.getProperties());
+    }
+
+    public void activate(Dictionary<String, Object> config) {
         replaceDotsByUnderscores = (config.get("replaceDotsByUnderscores") != null) ? 
             Boolean.valueOf((String) config.get("replaceDotsByUnderscores")) : true;
     }
diff --git a/marshaller/json/src/test/java/org/apache/karaf/decanter/marshaller/json/TestJsonMarshaller.java b/marshaller/json/src/test/java/org/apache/karaf/decanter/marshaller/json/TestJsonMarshaller.java
index 7abb5f4..b5b8e71 100644
--- a/marshaller/json/src/test/java/org/apache/karaf/decanter/marshaller/json/TestJsonMarshaller.java
+++ b/marshaller/json/src/test/java/org/apache/karaf/decanter/marshaller/json/TestJsonMarshaller.java
@@ -17,6 +17,8 @@
 package org.apache.karaf.decanter.marshaller.json;
 
 import java.io.StringReader;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -34,6 +36,10 @@
 
     private static final long EXPECTED_TIMESTAMP = 1454428780634L;
     private static final String EXPECTED_TOPIC = "testTopic";
+    private static final String DOT_KEY = "test.key";
+    private static final String DOT_VALUE = "test.value";
+    private static final String EXPECTED_DOT_KEY = "test.key";
+    private static final String EXPECTED_UNDERLINE_KEY = "test_key";
 
    @Test
    public void testMarshal() throws Exception {
@@ -53,6 +59,53 @@
    }
 
    @Test
+   public void testMarshalWithDot() throws Exception {
+       JsonMarshaller marshaller = new JsonMarshaller();
+
+       Dictionary<String, Object> config = new Hashtable<>();
+       config.put("replaceDotsByUnderscores", "false");
+       marshaller.activate(config);
+
+       Map<String, Object> map = new HashMap<>();
+       map.put(DOT_KEY, DOT_VALUE);
+       String jsonSt = marshaller.marshal(new Event(EXPECTED_TOPIC, map));
+       System.out.println(jsonSt);
+       JsonReader reader = Json.createReader(new StringReader(jsonSt));
+       JsonObject jsonO = reader.readObject();
+       Assert.assertEquals("Value", DOT_VALUE, jsonO.getString(EXPECTED_DOT_KEY));
+        try {
+           jsonO.getString(EXPECTED_UNDERLINE_KEY);
+	   Assert.fail("Key "+ EXPECTED_UNDERLINE_KEY + " exists");
+       } catch (NullPointerException e) {
+	   // This is expected
+       }
+   }
+
+
+   @Test
+   public void testMarshalWithUnderscore() throws Exception {
+       JsonMarshaller marshaller = new JsonMarshaller();
+
+       Dictionary<String, Object> config = new Hashtable<>();
+       config.put("replaceDotsByUnderscores", "true");
+       marshaller.activate(config);
+
+       Map<String, Object> map = new HashMap<>();
+       map.put(DOT_KEY, DOT_VALUE);
+       String jsonSt = marshaller.marshal(new Event(EXPECTED_TOPIC, map));
+       System.out.println(jsonSt);
+       JsonReader reader = Json.createReader(new StringReader(jsonSt));
+       JsonObject jsonO = reader.readObject();
+       Assert.assertEquals("Value", DOT_VALUE, jsonO.getString(EXPECTED_UNDERLINE_KEY));
+       try {
+           jsonO.getString(EXPECTED_DOT_KEY);
+	   Assert.fail("Key "+ EXPECTED_DOT_KEY + " exists");
+       } catch (NullPointerException e) {
+	   // This is expected
+       }
+   }
+
+   @Test
    public void testInnerMap() throws Exception {
        Marshaller marshaller = new JsonMarshaller();