camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [01/13] camel git commit: CAMEL-8232: Camel Toolbox - Include documentation about data formats
Date Tue, 13 Jan 2015 17:04:27 GMT
Repository: camel
Updated Branches:
  refs/heads/master 9a0c2ff33 -> 00f100403


CAMEL-8232: Camel Toolbox - Include documentation about data formats


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

Branch: refs/heads/master
Commit: 5e94c655154c22846e01e4757a816e888178639d
Parents: 9a0c2ff
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jan 13 09:38:56 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jan 13 17:33:27 2015 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |  7 ++++
 .../mbean/ManagedCamelContextMBean.java         |  9 +++++
 .../apache/camel/impl/DefaultCamelContext.java  | 17 +++++++-
 .../management/mbean/ManagedCamelContext.java   |  4 ++
 ...FormatConfigurationAndDocumentationTest.java | 42 ++++++++++++++++++++
 5 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5e94c655/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 0141473..447511a 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1409,6 +1409,13 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration
{
     String getComponentParameterJsonSchema(String componentName) throws IOException;
 
     /**
+     * Returns the JSON schema representation of the {@link DataFormat} parameters for the
given data format name.
+     *
+     * @return the json or <tt>null</tt> if the data format does not exist
+     */
+    String getDataFormatParameterJsonSchema(String dataFormatName) throws IOException;
+
+    /**
      * Returns the JSON schema representation of the EIP parameters for the given EIP name.
      *
      * @return the json or <tt>null</tt> if the EIP does not exist

http://git-wip-us.apache.org/repos/asf/camel/blob/5e94c655/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index fc9cf6e..60ecd55 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -268,6 +268,15 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     String componentParameterJsonSchema(String componentName) throws Exception;
 
     /**
+     * Returns the JSON schema representation with information about the data format and
the parameters it supports
+     *
+     * @param dataFormatName the name of the data format to lookup
+     * @throws Exception is thrown if error occurred
+     */
+    @ManagedOperation(description = "Returns the JSON schema representation of the data format
parameters for the given data format name")
+    String dataFormatParameterJsonSchema(String dataFormatName) throws Exception;
+
+    /**
      * Returns the JSON schema representation with information about the EIP and the parameters
it supports
      *
      * @param eipName the name of the EIP to lookup

http://git-wip-us.apache.org/repos/asf/camel/blob/5e94c655/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 32dab75..169af1b 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1199,6 +1199,21 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
         }
     }
 
+    public String getDataFormatParameterJsonSchema(String dataFormatName) throws IOException
{
+        String path = CamelContextHelper.MODEL_DOCUMENTATION_PREFIX + "/dataformat" + "/"
+ dataFormatName + ".json";
+        ClassResolver resolver = getClassResolver();
+        InputStream inputStream = resolver.loadResourceAsStream(path);
+        if (inputStream != null) {
+            log.debug("Loading dataformat JSON Schema for: {} using class resolver: {} ->
{}", new Object[]{dataFormatName, resolver, inputStream});
+            try {
+                return IOHelper.loadText(inputStream);
+            } finally {
+                IOHelper.close(inputStream);
+            }
+        }
+        return null;
+    }
+
     public String getEipParameterJsonSchema(String eipName) throws IOException {
         // the eip json schema may be in some of the sub-packages so look until we find it
         String[] subPackages = new String[]{"", "/config", "/dataformat", "/language", "/loadbalancer",
"/rest"};
@@ -1207,7 +1222,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             ClassResolver resolver = getClassResolver();
             InputStream inputStream = resolver.loadResourceAsStream(path);
             if (inputStream != null) {
-                log.debug("Loading component JSON Schema for: {} using class resolver: {}
-> {}", new Object[]{eipName, resolver, inputStream});
+                log.debug("Loading eip JSON Schema for: {} using class resolver: {} ->
{}", new Object[]{eipName, resolver, inputStream});
                 try {
                     return IOHelper.loadText(inputStream);
                 } finally {

http://git-wip-us.apache.org/repos/asf/camel/blob/5e94c655/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index 191a567..2ed82d5 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -611,6 +611,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         return json;
     }
 
+    public String dataFormatParameterJsonSchema(String dataFormatName) throws Exception {
+        return context.getDataFormatParameterJsonSchema(dataFormatName);
+    }
+
     public String eipParameterJsonSchema(String eipName) throws Exception {
         return context.getEipParameterJsonSchema(eipName);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/5e94c655/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
b/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
new file mode 100644
index 0000000..aa363a4
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/impl/StringDataFormatConfigurationAndDocumentationTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.junit.Test;
+
+public class StringDataFormatConfigurationAndDocumentationTest extends ContextTestSupport
{
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testDataFormatJsonSchema() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String json = context.getDataFormatParameterJsonSchema("string");
+        assertNotNull("Should have found some auto-generated JSON", json);
+        log.info(json);
+        System.out.println(json);
+
+        assertTrue(json.contains("\"description\": \"Represents the String (text based) DataFormat\""));
+        assertTrue(json.contains("\"charset\": { \"kind\": \"attribute\", \"required\": \"false\",
\"type\": \"string\", \"javaType\": \"java.lang.String\", \"deprecated\": \"false\" }"));
+    }
+
+}


Mime
View raw message