Repository: camel
Updated Branches:
  refs/heads/master f507f4eed -> d676a2f43


CAMEL-10538 Added inputTypeWithValidate()/outputTypeWithValidate() instead of 
adding boolean parameter. Fixed doc.


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

Branch: refs/heads/master
Commit: d676a2f43632578dcfa6ca4ef069ad163cb9db8b
Parents: f9946b2
Author: Tomohisa Igarashi <[email protected]>
Authored: Wed Feb 22 21:42:00 2017 +0900
Committer: Claus Ibsen <[email protected]>
Committed: Wed Feb 22 14:00:32 2017 +0100

----------------------------------------------------------------------
 camel-core/src/main/docs/validator.adoc         | 13 ++--
 .../org/apache/camel/model/RouteDefinition.java | 72 +++++++++++++-------
 .../impl/validator/ValidatorContractTest.java   |  4 +-
 .../impl/validator/ValidatorRouteTest.java      |  8 +--
 .../java/sample/camel/SampleCamelRouter.java    |  2 +-
 5 files changed, 63 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d676a2f4/camel-core/src/main/docs/validator.adoc
----------------------------------------------------------------------
diff --git a/camel-core/src/main/docs/validator.adoc 
b/camel-core/src/main/docs/validator.adoc
index afae832..477bdcd 100644
--- a/camel-core/src/main/docs/validator.adoc
+++ b/camel-core/src/main/docs/validator.adoc
@@ -78,7 +78,7 @@ XML DSL:
 -------------------------------------------------------------------
 <predicateValidator Type="csv:CSVOrder">
     <simple>${body} contains '{name:XOrder'</simple>
-</dataFormatTransformer>
+</predicateValidator>
 -------------------------------------------------------------------
 
 
@@ -107,8 +107,10 @@ And here is an example to specify endpoint ref in XML DSL:
 -------------------------------------------------------------------
 <endpointValidator uri="validator:xsd/schema.xsd" type="xml"/>
 -------------------------------------------------------------------
-
-
+Note that the Endpoint Validator just forwards the message to the specified 
endpoint. In above example,
+camel forwards the message to the `validator:` endpoint, which actually is a
+link:validator-component.adoc[Validation Component]. You can also use any 
other validation component like
+link:bean-validation.html[Bean Validation Component].
 
 [[Validator-Custom]]
 Custom Validator Options
@@ -166,13 +168,14 @@ XML DSL:
 -------------------------------------------------------------------
 
 If you have following route definition, above validator will be applied when 
`direct:abc` endpoint
-receives the message. Note that the `validate` attribute on the inputType 
declaration is set to `true`:
+receives the message. Note that `inputTypeWithValidate` is used instead of 
`inputType` in Java DSL,
+and the `validate` attribute on the inputType declaration is set to `true` in 
XML DSL:
 
 Java DSL:
 [source,java]
 -------------------------------------------------------------------
 from("direct:abc")
-    .inputType("xml:ABCOrder", true)
+    .inputTypeWithValidate("xml:ABCOrder")
     .log("${body}");
 -------------------------------------------------------------------
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d676a2f4/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 0a3a7ac..688cb64 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -636,90 +636,114 @@ public class RouteDefinition extends 
ProcessorDefinition<RouteDefinition> {
 
     /**
      * Declare an input type.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}
      * @param urn input type URN
-     * @param validate if it's true, content validation is performed for this 
input type
      * @return the builder
      */
-    public RouteDefinition inputType(String urn, boolean validate) {
+    public RouteDefinition inputType(String urn) {
         inputType = new InputTypeDefinition();
         inputType.setUrn(urn);
-        inputType.setValidate(validate);
+        inputType.setValidate(false);
         return this;
     }
 
     /**
-     * Declare an input type.
+     * Declare an input type with validation enabled.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}, {@link 
org.apache.camel.spi.Validator}
      * @param urn input type URN
      * @return the builder
      */
-    public RouteDefinition inputType(String urn) {
-        return inputType(urn, false);
+    public RouteDefinition inputTypeWithValidate(String urn) {
+        inputType = new InputTypeDefinition();
+        inputType.setUrn(urn);
+        inputType.setValidate(true);
+        return this;
     }
 
     /**
      * Declare an input type with Java class.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}
      * @param clazz Class object of the input type
-     * @param validate if it's true, content validation is performed for this 
input type
      * @return the builder
      */
-    public RouteDefinition inputType(Class clazz, boolean validate) {
+    public RouteDefinition inputType(Class clazz) {
         inputType = new InputTypeDefinition();
         inputType.setJavaClass(clazz);
-        inputType.setValidate(validate);
+        inputType.setValidate(false);
         return this;
     }
 
     /**
-     * Declare an input type with Java class.
+     * Declare an input type with Java class with validation enabled.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}, {@link 
org.apache.camel.spi.Validator}
      * @param clazz Class object of the input type
      * @return the builder
      */
-    public RouteDefinition inputType(Class clazz) {
-        return inputType(clazz, false);
+    public RouteDefinition inputTypeWithValidate(Class clazz) {
+        inputType = new InputTypeDefinition();
+        inputType.setJavaClass(clazz);
+        inputType.setValidate(true);
+        return this;
     }
 
     /**
      * Declare an output type.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}
      * @param urn output type URN
-     * @param validate if it's true, content validation is performed for this 
output type
      * @return the builder
      */
-    public RouteDefinition outputType(String urn, boolean validate) {
+    public RouteDefinition outputType(String urn) {
         outputType = new OutputTypeDefinition();
         outputType.setUrn(urn);
-        outputType.setValidate(validate);
+        outputType.setValidate(false);
         return this;
     }
 
     /**
-     * Declare an output type.
+     * Declare an output type with validation enabled.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}, {@link 
org.apache.camel.spi.Validator}
      * @param urn output type URN
      * @return the builder
      */
-    public RouteDefinition outputType(String urn) {
-        return outputType(urn, false);
+    public RouteDefinition outputTypeWithValidate(String urn) {
+        outputType = new OutputTypeDefinition();
+        outputType.setUrn(urn);
+        outputType.setValidate(true);
+        return this;
     }
 
     /**
      * Declare an output type with Java class.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}
      * @param clazz Class object of the output type
-     * @param validate if it's true, content validation is performed for this 
output type
      * @return the builder
      */
-    public RouteDefinition outputType(Class clazz, boolean validate) {
+    public RouteDefinition outputType(Class clazz) {
         outputType = new OutputTypeDefinition();
         outputType.setJavaClass(clazz);
-        outputType.setValidate(validate);
+        outputType.setValidate(false);
         return this;
     }
 
     /**
-     * Declare an output type with Java class.
+     * Declare an output type with Java class with validation enabled.
+     * 
+     * @see {@link org.apache.camel.spi.Transformer}, {@link 
org.apache.camel.spi.Validator}
      * @param clazz Class object of the output type
      * @return the builder
      */
-    public RouteDefinition outputType(Class clazz) {
-        return outputType(clazz, false);
+    public RouteDefinition outputTypeWithValidate(Class clazz) {
+        outputType = new OutputTypeDefinition();
+        outputType.setJavaClass(clazz);
+        outputType.setValidate(true);
+        return this;
     }
 
     // Properties

http://git-wip-us.apache.org/repos/asf/camel/blob/d676a2f4/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorContractTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorContractTest.java
 
b/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorContractTest.java
index 8633010..a5f65cc 100644
--- 
a/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorContractTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorContractTest.java
@@ -50,7 +50,7 @@ public class ValidatorContractTest extends ContextTestSupport 
{
                     .type(A.class)
                     .withUri("direct:validator");
                 from("direct:a")
-                    .inputType(A.class, true)
+                    .inputTypeWithValidate(A.class)
                     .to("mock:a");
                 from("direct:validator")
                     .to("mock:validator");
@@ -82,7 +82,7 @@ public class ValidatorContractTest extends ContextTestSupport 
{
                     .type(A.class)
                     .withUri("direct:validator");
                 from("direct:a")
-                    .outputType(A.class, true)
+                    .outputTypeWithValidate(A.class)
                     .to("mock:a");
                 from("direct:validator")
                     .to("mock:validator");

http://git-wip-us.apache.org/repos/asf/camel/blob/d676a2f4/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorRouteTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorRouteTest.java
 
b/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorRouteTest.java
index 3d3f7f1..3d92741 100644
--- 
a/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorRouteTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/impl/validator/ValidatorRouteTest.java
@@ -99,7 +99,7 @@ public class ValidatorRouteTest extends ContextTestSupport {
                     .type("json")
                     
.withExpression(bodyAs(String.class).contains("{name:XOrder}"));
                 from("direct:predicate")
-                    .inputType("json:JsonXOrder", true)
+                    .inputTypeWithValidate("json:JsonXOrder")
                     .outputType("json:JsonXOrderResponse")
                     .setBody(simple("{name:XOrderResponse}"))
                     .setProperty(Exchange.OUTPUT_TYPE, 
constant("json:JsonXOrderResponse"));
@@ -110,7 +110,7 @@ public class ValidatorRouteTest extends ContextTestSupport {
                     .withUri("myxml:endpoint");
                 from("direct:endpoint")
                     .inputType("xml:XmlXOrder")
-                    .outputType("xml:XmlXOrderResponse", true)
+                    .outputTypeWithValidate("xml:XmlXOrderResponse")
                     .validate(exchangeProperty(VALIDATOR_INVOKED).isNull())
                     .setBody(simple("<XOrderResponse/>"))
                     .setProperty(Exchange.OUTPUT_TYPE, 
constant("xml:XmlXOrderResponse"));
@@ -122,8 +122,8 @@ public class ValidatorRouteTest extends ContextTestSupport {
                     .type("other:OtherXOrderResponse")
                     .withJava(OtherXOrderResponseValidator.class);
                 from("direct:custom")
-                    .inputType("other:OtherXOrder", true)
-                    .outputType("other:OtherXOrderResponse", true)
+                    .inputTypeWithValidate("other:OtherXOrder")
+                    .outputTypeWithValidate("other:OtherXOrderResponse")
                     
.validate(exchangeProperty(VALIDATOR_INVOKED).isEqualTo(OtherXOrderValidator.class))
                     .setBody(simple("name=XOrderResponse"))
                     .setProperty(Exchange.OUTPUT_TYPE, 
constant("other:OtherXOrderResponse"));

http://git-wip-us.apache.org/repos/asf/camel/blob/d676a2f4/examples/camel-example-validator-spring-boot/src/main/java/sample/camel/SampleCamelRouter.java
----------------------------------------------------------------------
diff --git 
a/examples/camel-example-validator-spring-boot/src/main/java/sample/camel/SampleCamelRouter.java
 
b/examples/camel-example-validator-spring-boot/src/main/java/sample/camel/SampleCamelRouter.java
index b7535ea..d6a4dcf 100644
--- 
a/examples/camel-example-validator-spring-boot/src/main/java/sample/camel/SampleCamelRouter.java
+++ 
b/examples/camel-example-validator-spring-boot/src/main/java/sample/camel/SampleCamelRouter.java
@@ -34,7 +34,7 @@ public class SampleCamelRouter extends RouteBuilder {
             .withBean("greetingValidator");
         
         from("timer:hello?period={{timer.period}}")
-            .outputType("greeting", true)
+            .outputTypeWithValidate("greeting")
             .transform(method("myBean", "saySomething"))
             .to("stream:out");
     }

Reply via email to