This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 982c441ee0321f508c656e58eb91984c5a65c258 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Mar 30 11:00:48 2022 +0200 CAMEL-17806: camel-yaml-dsl - Make parser more forgiving and not report weird exception if yaml is not camel route. --- .../org/apache/camel/dsl/yaml/common/YamlDeserializerSupport.java | 8 ++++++++ .../java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerSupport.java b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerSupport.java index 7148197..9a2376c 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerSupport.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl-common/src/main/java/org/apache/camel/dsl/yaml/common/YamlDeserializerSupport.java @@ -258,6 +258,14 @@ public class YamlDeserializerSupport { return (SequenceNode) node; } + public static boolean isSequenceNode(Node node) { + if (node == null) { + return false; + } + + return node.getNodeType() == NodeType.SEQUENCE; + } + public static Node getNamedNode(MappingNode node, String name) throws YamlDeserializationException { if (node == null) { return null; diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java index 3d6d141..659cc81 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/java/org/apache/camel/dsl/yaml/YamlRoutesBuilderLoader.java @@ -79,6 +79,7 @@ import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.asMapping import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.asSequenceNode; import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.asStringList; import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.asText; +import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.isSequenceNode; import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.nodeAt; import static org.apache.camel.dsl.yaml.common.YamlDeserializerSupport.setDeserializationContext; @@ -123,7 +124,7 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport { Iterator<?> it = ObjectHelper.createIterator(target); while (it.hasNext()) { target = it.next(); - if (target instanceof Node) { + if (target instanceof Node && isSequenceNode((Node) target)) { SequenceNode seq = asSequenceNode((Node) target); for (Node node : seq.getValue()) { int idx = -1; @@ -215,7 +216,7 @@ public class YamlRoutesBuilderLoader extends YamlRoutesBuilderLoaderSupport { Iterator<?> it = ObjectHelper.createIterator(target); while (it.hasNext()) { target = it.next(); - if (target instanceof Node) { + if (target instanceof Node && isSequenceNode((Node) target)) { SequenceNode seq = asSequenceNode((Node) target); for (Node node : seq.getValue()) { int idx = -1;