Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x d0ed1db15 -> c4d4338e7
  refs/heads/master 1428b7678 -> a558dd68c


CAMEL-9436: camel-catalog - Make it easy to include extra components


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

Branch: refs/heads/camel-2.16.x
Commit: dc7957b6bff3d4c7640c7421f6ffb3765538dd28
Parents: d0ed1db
Author: Claus Ibsen <[email protected]>
Authored: Mon Dec 28 13:49:21 2015 +0100
Committer: Claus Ibsen <[email protected]>
Committed: Mon Dec 28 13:56:57 2015 +0100

----------------------------------------------------------------------
 .../org/apache/camel/catalog/CamelCatalog.java  |  8 ++++
 .../camel/catalog/DefaultCamelCatalog.java      | 37 +++++++++++++++
 .../apache/camel/catalog/CamelCatalogTest.java  | 17 +++++++
 .../src/test/resources/org/foo/camel/dummy.json | 48 ++++++++++++++++++++
 4 files changed, 110 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dc7957b6/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git 
a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java 
b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 6587ad9..3844957 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -41,6 +41,14 @@ public interface CamelCatalog {
     void setSuggestionStrategy(SuggestionStrategy suggestionStrategy);
 
     /**
+     * Adds a 3rd party component to this catalog.
+     *
+     * @param name      the component name
+     * @param className the fully qualified class name for the component class
+     */
+    void addComponent(String name, String className);
+
+    /**
      * The version of this Camel Catalog
      */
     String getCatalogVersion();

http://git-wip-us.apache.org/repos/asf/camel/blob/dc7957b6/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git 
a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
 
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 10dfd96..bff2ca9 100644
--- 
a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ 
b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -75,6 +76,9 @@ public class DefaultCamelCatalog implements CamelCatalog {
 
     private final VersionHelper version = new VersionHelper();
 
+    // 3rd party components
+    private final Map<String, String> extraComponents = new HashMap<String, 
String>();
+
     // cache of operation -> result
     private final Map<String, Object> cache = new HashMap<String, Object>();
 
@@ -107,6 +111,15 @@ public class DefaultCamelCatalog implements CamelCatalog {
     }
 
     @Override
+    public void addComponent(String name, String className) {
+        extraComponents.put(name, className);
+        // invalidate the cache
+        cache.remove("findComponentNames");
+        cache.remove("findComponentLabels");
+        cache.remove("listComponentsAsJson");
+    }
+
+    @Override
     public String getCatalogVersion() {
         return version.getVersion();
     }
@@ -129,6 +142,14 @@ public class DefaultCamelCatalog implements CamelCatalog {
                     // ignore
                 }
             }
+
+            // include third party components
+            for (Map.Entry<String, String> entry : extraComponents.entrySet()) 
{
+                names.add(entry.getKey());
+            }
+            // sort the names
+            Collections.sort(names);
+
             if (caching) {
                 cache.put("findComponentNames", names);
             }
@@ -378,6 +399,22 @@ public class DefaultCamelCatalog implements CamelCatalog {
                 } catch (IOException e) {
                     // ignore
                 }
+            } else {
+                // its maybe a third party so try load it
+                String className = extraComponents.get(name);
+                if (className != null) {
+                    String packageName = className.substring(0, 
className.lastIndexOf('.'));
+                    packageName = packageName.replace('.', '/');
+                    String path = packageName + "/" + name + ".json";
+                    is = 
DefaultCamelCatalog.class.getClassLoader().getResourceAsStream(path);
+                    if (is != null) {
+                        try {
+                            answer = CatalogHelper.loadText(is);
+                        } catch (IOException e) {
+                            // ignore
+                        }
+                    }
+                }
             }
             if (caching) {
                 cache.put(file, answer);

http://git-wip-us.apache.org/repos/asf/camel/blob/dc7957b6/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
----------------------------------------------------------------------
diff --git 
a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
 
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index e3c6d0b..43fc24d 100644
--- 
a/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ 
b/platforms/catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -532,4 +532,21 @@ public class CamelCatalogTest {
         assertNotNull(tree);
     }
 
+    @Test
+    public void testAddComponent() throws Exception {
+        assertFalse(catalog.findComponentNames().contains("dummy"));
+
+        catalog.addComponent("dummy", "org.foo.camel.DummyComponent");
+
+        assertTrue(catalog.findComponentNames().contains("dummy"));
+
+        String json = catalog.componentJSonSchema("dummy");
+        assertNotNull(json);
+
+        // validate we can parse the json
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode tree = mapper.readTree(json);
+        assertNotNull(tree);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dc7957b6/platforms/catalog/src/test/resources/org/foo/camel/dummy.json
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/test/resources/org/foo/camel/dummy.json 
b/platforms/catalog/src/test/resources/org/foo/camel/dummy.json
new file mode 100644
index 0000000..4c04238
--- /dev/null
+++ b/platforms/catalog/src/test/resources/org/foo/camel/dummy.json
@@ -0,0 +1,48 @@
+{
+  "component": {
+    "kind": "component",
+    "scheme": "dummy",
+    "syntax": "dummy:loggerName",
+    "title": "Dummy",
+    "description": "The dummy component logs message exchanges to the 
underlying logging mechanism.",
+    "label": "core,monitoring",
+    "producerOnly": "true",
+    "javaType": "org.foo.camel.DummyComponent",
+    "groupId": "org.foo.camel",
+    "artifactId": "dummy",
+    "version": "1.0"
+  },
+  "componentProperties": {
+    "exchangeFormatter": { "kind": "property", "type": "object", "javaType": 
"org.apache.camel.spi.ExchangeFormatter", "deprecated": "false", "description": 
"Sets a custom ExchangeFormatter to convert the Exchange to a String suitable 
for logging. If not specified we default to DefaultExchangeFormatter." }
+  },
+  "properties": {
+    "loggerName": { "kind": "path", "group": "producer", "required": "true", 
"type": "string", "javaType": "java.lang.String", "deprecated": "false", 
"description": "The logger name to use" },
+    "groupActiveOnly": { "kind": "parameter", "group": "producer", "type": 
"boolean", "javaType": "java.lang.Boolean", "deprecated": "false", 
"defaultValue": "true", "description": "If true will hide stats when no new 
messages have been received for a time interval if false show stats regardless 
of message traffic." },
+    "groupDelay": { "kind": "parameter", "group": "producer", "type": 
"integer", "javaType": "java.lang.Long", "deprecated": "false", "description": 
"Set the initial delay for stats (in millis)" },
+    "groupInterval": { "kind": "parameter", "group": "producer", "type": 
"integer", "javaType": "java.lang.Long", "deprecated": "false", "description": 
"If specified will group message stats by this time interval (in millis)" },
+    "groupSize": { "kind": "parameter", "group": "producer", "type": 
"integer", "javaType": "java.lang.Integer", "deprecated": "false", 
"description": "An integer that specifies a group size for throughput logging." 
},
+    "level": { "kind": "parameter", "group": "producer", "type": "string", 
"javaType": "java.lang.String", "enum": [ "ERROR", "WARN", "INFO", "DEBUG", 
"TRACE", "OFF" ], "deprecated": "false", "defaultValue": "INFO", "description": 
"Logging level to use. The default value is INFO." },
+    "marker": { "kind": "parameter", "group": "producer", "type": "string", 
"javaType": "java.lang.String", "deprecated": "false", "description": "An 
optional Marker name to use." },
+    "exchangePattern": { "kind": "parameter", "group": "advanced", "label": 
"advanced", "type": "string", "javaType": "org.apache.camel.ExchangePattern", 
"enum": [ "InOnly", "RobustInOnly", "InOut", "InOptionalOut", "OutOnly", 
"RobustOutOnly", "OutIn", "OutOptionalIn" ], "deprecated": "false", 
"defaultValue": "InOnly", "description": "Sets the default exchange pattern 
when creating an exchange." },
+    "synchronous": { "kind": "parameter", "group": "advanced", "label": 
"advanced", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Sets whether synchronous processing 
should be strictly used or Camel is allowed to use asynchronous processing (if 
supported)." },
+    "maxChars": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "integer", "javaType": "int", "deprecated": "false", 
"defaultValue": "10000", "description": "Limits the number of characters logged 
per line." },
+    "multiline": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "If enabled then each information is 
outputted on a newline." },
+    "showAll": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Quick option for turning all options 
on. (multiline maxChars has to be manually set if to be used)" },
+    "showBody": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "true", "description": "Show the message body." },
+    "showBodyType": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "true", "description": "Show the body Java type." },
+    "showCaughtException": { "kind": "parameter", "group": "formatting", 
"label": "formatting", "type": "boolean", "javaType": "boolean", "deprecated": 
"false", "defaultValue": "false", "description": "f the exchange has a caught 
exception show the exception message (no stack trace). A caught exception is 
stored as a property on the exchange (using the key link 
org.apache.camel.ExchangeEXCEPTION_CAUGHT and for instance a doCatch can catch 
exceptions." },
+    "showException": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "If the exchange has an exception show 
the exception message (no stacktrace)" },
+    "showExchangeId": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Show the unique exchange ID." },
+    "showExchangePattern": { "kind": "parameter", "group": "formatting", 
"label": "formatting", "type": "boolean", "javaType": "boolean", "deprecated": 
"false", "defaultValue": "true", "description": "Shows the Message Exchange 
Pattern (or MEP for short)." },
+    "showFiles": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "If enabled Camel will output files" },
+    "showFuture": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "If enabled Camel will on Future 
objects wait for it to complete to obtain the payload to be logged." },
+    "showHeaders": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Show the message headers." },
+    "showOut": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "If the exchange has an out message 
show the out message." },
+    "showProperties": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Show the exchange properties." },
+    "showStackTrace": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Show the stack trace if an exchange 
has an exception. Only effective if one of showAll showException or 
showCaughtException are enabled." },
+    "showStreams": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "boolean", "javaType": "boolean", "deprecated": "false", 
"defaultValue": "false", "description": "Whether Camel should show stream 
bodies or not (eg such as java.io.InputStream). Beware if you enable this 
option then you may not be able later to access the message body as the stream 
have already been read by this logger. To remedy this you will have to use 
Stream Caching." },
+    "skipBodyLineSeparator": { "kind": "parameter", "group": "formatting", 
"label": "formatting", "type": "boolean", "javaType": "boolean", "deprecated": 
"false", "defaultValue": "true", "description": "Whether to skip line 
separators when logging the message body. This allows to log the message body 
in one line setting this option to false will preserve any line separators from 
the body which then will log the body as is." },
+    "style": { "kind": "parameter", "group": "formatting", "label": 
"formatting", "type": "string", "javaType": 
"org.apache.camel.processor.DefaultExchangeFormatter.OutputStyle", "enum": [ 
"Default", "Tab", "Fixed" ], "deprecated": "false", "defaultValue": "Default", 
"description": "Sets the outputs style to use." }
+  }
+}
+

Reply via email to