Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-20602: Support user properties on Camel JBang bind command
- Allow to specify properties on source, sink, step in a Pipe - User properties can be set as additional command options targeting either the source or the sink or a specific step
- Loading branch information
1 parent
3cd788c
commit 9f70818
Showing
8 changed files
with
863 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/common/YamlHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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.dsl.jbang.core.common; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import org.yaml.snakeyaml.DumperOptions; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.introspector.Property; | ||
import org.yaml.snakeyaml.nodes.NodeTuple; | ||
import org.yaml.snakeyaml.nodes.Tag; | ||
import org.yaml.snakeyaml.representer.Representer; | ||
|
||
public final class YamlHelper { | ||
|
||
private YamlHelper() { | ||
} | ||
|
||
/** | ||
* Creates new Yaml instance. The implementation provided by Snakeyaml is not thread-safe. It is better to create a | ||
* fresh instance for every YAML stream. | ||
* | ||
* @return | ||
*/ | ||
public static Yaml yaml() { | ||
Representer representer = new Representer(new DumperOptions()) { | ||
@Override | ||
protected NodeTuple representJavaBeanProperty( | ||
Object javaBean, Property property, Object propertyValue, Tag customTag) { | ||
// if value of property is null, ignore it. | ||
if (propertyValue == null || (propertyValue instanceof Collection && ((Collection<?>) propertyValue).isEmpty()) | ||
|| | ||
(propertyValue instanceof Map && ((Map<?, ?>) propertyValue).isEmpty())) { | ||
return null; | ||
} else { | ||
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag); | ||
} | ||
} | ||
}; | ||
representer.getPropertyUtils().setSkipMissingProperties(true); | ||
return new Yaml(representer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,4 @@ spec: | |
{{ .Steps }} | ||
sink: | ||
uri: {{ .Sink }} | ||
#properties: | ||
#key: "value" | ||
{{ .SinkProperties }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.