You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/02/07 10:10:43 UTC

[1/2] camel git commit: CAMEL-8023: Model and component javadoc documentation

Repository: camel
Updated Branches:
  refs/heads/master 88f6c1e52 -> 1c7a2d749


CAMEL-8023: Model and component javadoc documentation


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

Branch: refs/heads/master
Commit: 6584c321214a82c9037bea2f5a5a6a74f9b03c92
Parents: 88f6c1e
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Feb 7 09:47:51 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Feb 7 09:58:58 2015 +0100

----------------------------------------------------------------------
 .../controlbus/ControlBusEndpoint.java          | 30 ++++++++++-
 .../dataformat/DataFormatEndpoint.java          | 21 ++++++--
 .../component/dataset/DataSetEndpoint.java      |  2 +-
 .../camel/component/direct/DirectEndpoint.java  |  3 +-
 .../tools/apt/EndpointAnnotationProcessor.java  | 56 +++++++++++++-------
 .../java/org/apache/camel/spi/UriParam.java     | 10 ++++
 .../main/java/org/apache/camel/spi/UriPath.java | 10 ++++
 7 files changed, 106 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
index 951efed..6d1859f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
@@ -35,12 +35,13 @@ import org.apache.camel.util.CamelLogger;
 @UriEndpoint(scheme = "controlbus", label = "core,monitoring")
 public class ControlBusEndpoint extends DefaultEndpoint {
 
-    @UriPath(description = "Command can be either route or language")
+    @UriPath(description = "Command can be either route or language", enums = "route,language")
     private String command;
+    @UriPath
     private Language language;
     @UriParam
     private String routeId;
-    @UriParam
+    @UriParam(enums = "start,stop,suspend,resume,status")
     private String action;
     @UriParam(defaultValue = "false")
     private boolean async;
@@ -77,6 +78,10 @@ public class ControlBusEndpoint extends DefaultEndpoint {
         return language;
     }
 
+    /**
+     * Allows you to specify the name of a Language to use for evaluating the message body.
+     * If there is any result from the evaluation, then the result is put in the message body.
+     */
     public void setLanguage(Language language) {
         this.language = language;
     }
@@ -85,6 +90,9 @@ public class ControlBusEndpoint extends DefaultEndpoint {
         return routeId;
     }
 
+    /**
+     * To specify a route by its id.
+     */
     public void setRouteId(String routeId) {
         this.routeId = routeId;
     }
@@ -93,6 +101,15 @@ public class ControlBusEndpoint extends DefaultEndpoint {
         return action;
     }
 
+    /**
+     * To denote an action that can be either: start, stop, or status.
+     * <p/>
+     * To either start or stop a route, or to get the status of the route as output in the message body.
+     * You can use suspend and resume from Camel 2.11.1 onwards to either suspend or resume a route.
+     * And from Camel 2.11.1 onwards you can use stats to get performance statics returned in XML format;
+     * the routeId option can be used to define which route to get the performance stats for, if routeId is not defined,
+     * then you get statistics for the entire CamelContext.
+     */
     public void setAction(String action) {
         this.action = action;
     }
@@ -101,6 +118,12 @@ public class ControlBusEndpoint extends DefaultEndpoint {
         return async;
     }
 
+    /**
+     * Whether to execute the control bus task asynchronously.
+     * <p/>
+     * Important: If this option is enabled, then any result from the task is not set on the Exchange.
+     * This is only possible if executing tasks synchronously.
+     */
     public void setAsync(boolean async) {
         this.async = async;
     }
@@ -109,6 +132,9 @@ public class ControlBusEndpoint extends DefaultEndpoint {
         return loggingLevel;
     }
 
+    /**
+     * Logging level used for logging when task is done, or if any exceptions occurred during processing the task.
+     */
     public void setLoggingLevel(LoggingLevel loggingLevel) {
         this.loggingLevel = loggingLevel;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/camel-core/src/main/java/org/apache/camel/component/dataformat/DataFormatEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/dataformat/DataFormatEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/dataformat/DataFormatEndpoint.java
index 2dbe86a..a983fda 100644
--- a/camel-core/src/main/java/org/apache/camel/component/dataformat/DataFormatEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/dataformat/DataFormatEndpoint.java
@@ -37,12 +37,11 @@ public class DataFormatEndpoint extends DefaultEndpoint {
 
     private MarshalProcessor marshal;
     private UnmarshalProcessor unmarshal;
+    private DataFormat dataFormat;
 
-    @UriPath(description = "Name of data format followed by operation which must be either marhsal or unmarshal")
+    @UriPath(description = "Name of data format")
     private String name;
-    @UriParam
-    private DataFormat dataFormat;
-    @UriParam
+    @UriPath(enums = "marshal,unmarshal")
     private String operation;
 
     public DataFormatEndpoint() {
@@ -53,6 +52,14 @@ public class DataFormatEndpoint extends DefaultEndpoint {
         this.dataFormat = dataFormat;
     }
 
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
     public DataFormat getDataFormat() {
         return dataFormat;
     }
@@ -65,6 +72,9 @@ public class DataFormatEndpoint extends DefaultEndpoint {
         return operation;
     }
 
+    /**
+     * Operation to use either marshal or unmarshal
+     */
     public void setOperation(String operation) {
         this.operation = operation;
     }
@@ -100,6 +110,9 @@ public class DataFormatEndpoint extends DefaultEndpoint {
 
     @Override
     protected void doStart() throws Exception {
+        if (dataFormat == null && name != null) {
+            dataFormat = getCamelContext().resolveDataFormat(name);
+        }
         if (operation.equals("marshal")) {
             marshal = new MarshalProcessor(dataFormat);
             marshal.setCamelContext(getCamelContext());

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
index 74bc4b5..ae949e6 100644
--- a/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/dataset/DataSetEndpoint.java
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
 public class DataSetEndpoint extends MockEndpoint implements Service {
     private final transient Logger log;
     private final AtomicInteger receivedCounter = new AtomicInteger();
-    @UriPath(name = "name", description = "name of DataSet to lookup in the registry")
+    @UriPath(name = "name", description = "Name of DataSet to lookup in the registry")
     private volatile DataSet dataSet;
     @UriParam(defaultValue = "0")
     private int minRate;

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
index 55fa945..c8f9934 100644
--- a/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/direct/DirectEndpoint.java
@@ -38,9 +38,10 @@ import org.apache.camel.util.ObjectHelper;
 @UriEndpoint(scheme = "direct", consumerClass = DirectConsumer.class, label = "core,endpoint")
 public class DirectEndpoint extends DefaultEndpoint {
 
+    private volatile Map<String, DirectConsumer> consumers;
+
     @UriPath(description = "Name of direct endpoint")
     private String name;
-    private volatile Map<String, DirectConsumer> consumers;
     @UriParam(defaultValue = "false")
     private boolean block;
     @UriParam(defaultValue = "30000")

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
index a431511..e409cd2 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EndpointAnnotationProcessor.java
@@ -444,15 +444,25 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
 
                     // gather enums
                     Set<String> enums = new LinkedHashSet<String>();
-                    boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
-                    if (isEnum) {
-                        TypeElement enumClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
-                        // find all the enum constants which has the possible enum value that can be used
-                        List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
-                        for (VariableElement var : fields) {
-                            if (var.getKind() == ElementKind.ENUM_CONSTANT) {
-                                String val = var.toString();
-                                enums.add(val);
+
+                    boolean isEnum;
+                    if (!Strings.isNullOrEmpty(path.enums())) {
+                        isEnum = true;
+                        String[] values = path.enums().split(",");
+                        for (String val : values) {
+                            enums.add(val);
+                        }
+                    } else {
+                        isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
+                        if (isEnum) {
+                            TypeElement enumClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
+                            // find all the enum constants which has the possible enum value that can be used
+                            List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
+                            for (VariableElement var : fields) {
+                                if (var.getKind() == ElementKind.ENUM_CONSTANT) {
+                                    String val = var.toString();
+                                    enums.add(val);
+                                }
                             }
                         }
                     }
@@ -496,15 +506,25 @@ public class EndpointAnnotationProcessor extends AbstractAnnotationProcessor {
 
                         // gather enums
                         Set<String> enums = new LinkedHashSet<String>();
-                        boolean isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
-                        if (isEnum) {
-                            TypeElement enumClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
-                            // find all the enum constants which has the possible enum value that can be used
-                            List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
-                            for (VariableElement var : fields) {
-                                if (var.getKind() == ElementKind.ENUM_CONSTANT) {
-                                    String val = var.toString();
-                                    enums.add(val);
+
+                        boolean isEnum;
+                        if (!Strings.isNullOrEmpty(param.enums())) {
+                            isEnum = true;
+                            String[] values = param.enums().split(",");
+                            for (String val : values) {
+                                enums.add(val);
+                            }
+                        } else {
+                            isEnum = fieldTypeElement != null && fieldTypeElement.getKind() == ElementKind.ENUM;
+                            if (isEnum) {
+                                TypeElement enumClass = findTypeElement(roundEnv, fieldTypeElement.asType().toString());
+                                // find all the enum constants which has the possible enum value that can be used
+                                List<VariableElement> fields = ElementFilter.fieldsIn(enumClass.getEnclosedElements());
+                                for (VariableElement var : fields) {
+                                    if (var.getKind() == ElementKind.ENUM_CONSTANT) {
+                                        String val = var.toString();
+                                        enums.add(val);
+                                    }
                                 }
                             }
                         }

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriParam.java
----------------------------------------------------------------------
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriParam.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriParam.java
index 3e6b363..2c79b1a 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriParam.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriParam.java
@@ -58,4 +58,14 @@ public @interface UriParam {
      */
     String description() default "";
 
+    /**
+     * Allows to define enums this options accepts.
+     * <p/>
+     * If the type is already an enum, then this option should not be used; instead you can use
+     * this option when the type is a String that only accept certain values.
+     * <p/>
+     * Multiple values is separated by comma.
+     */
+    String enums() default "";
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/6584c321/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriPath.java
----------------------------------------------------------------------
diff --git a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriPath.java b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriPath.java
index e746d3b..5fef8a6 100644
--- a/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriPath.java
+++ b/tooling/spi-annotations/src/main/java/org/apache/camel/spi/UriPath.java
@@ -46,4 +46,14 @@ public @interface UriPath {
      */
     String description() default "";
 
+    /**
+     * Allows to define enums this options accepts.
+     * <p/>
+     * If the type is already an enum, then this option should not be used; instead you can use
+     * this option when the type is a String that only accept certain values.
+     * <p/>
+     * Multiple values is separated by comma.
+     */
+    String enums() default "";
+
 }
\ No newline at end of file


[2/2] camel git commit: Add unit test with inlined groovt script for people who want to code in xml

Posted by da...@apache.org.
Add unit test with inlined groovt script for people who want to code in xml


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

Branch: refs/heads/master
Commit: 1c7a2d749e5f75545aa9899e9b06cdef4cf1d614
Parents: 6584c32
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Feb 7 10:10:58 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Feb 7 10:10:58 2015 +0100

----------------------------------------------------------------------
 .../groovy/InlinedGroovyScriptTest.java         | 44 +++++++++++++++++
 .../processor/groovy/inlinedGroovyScript.xml    | 51 ++++++++++++++++++++
 2 files changed, 95 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1c7a2d74/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
new file mode 100644
index 0000000..d8a42c2
--- /dev/null
+++ b/components/camel-groovy/src/test/java/org/apache/camel/processor/groovy/InlinedGroovyScriptTest.java
@@ -0,0 +1,44 @@
+/**
+ * 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.processor.groovy;
+
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version 
+ */
+public class InlinedGroovyScriptTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/processor/groovy/inlinedGroovyScript.xml");
+    }
+
+    @Test
+    public void testGroovy() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("HelloHelloHello");
+
+        template.sendBodyAndHeader("direct:start", "Hello", "foo", 123);
+        template.sendBodyAndHeader("direct:start", "3", "foo", 123);
+
+        assertMockEndpointsSatisfied();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/1c7a2d74/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml b/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
new file mode 100644
index 0000000..09e2b17
--- /dev/null
+++ b/components/camel-groovy/src/test/resources/org/apache/camel/processor/groovy/inlinedGroovyScript.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:lang="http://www.springframework.org/schema/lang"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <!-- inline a groovy script to use for the aggregator -->
+  <lang:groovy id="myAggregate">
+    <lang:inline-script>
+      class MyAggregate {
+        String someNameHere(String prev, int next) {
+          return prev * next
+        }
+      }
+    </lang:inline-script>
+  </lang:groovy>
+
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:start"/>
+      <!-- we must declare the name of the method, as the inlined groovy script has additional methods -->
+      <aggregate strategyRef="myAggregate" strategyMethodName="someNameHere" completionSize="2">
+        <correlationExpression>
+          <header>foo</header>
+        </correlationExpression>
+        <to uri="mock:result"/>
+      </aggregate>
+    </route>
+  </camelContext>
+
+</beans>