Apache Camel自定义Producer设置问题

ovfsdjhp  于 9个月前  发布在  Apache
关注(0)|答案(2)|浏览(117)

我正在尝试配置Apache Camel Producer组件(由camel-archetype-component archetype生成),并对其中一个部分的工作原理有疑问。
端点代码:

@UriEndpoint(firstVersion = "1.0-SNAPSHOT", scheme = "xmlGenerator", title = "xmlGenerator", syntax = "xmlGenerator:testScope",
        category = {Category.JAVA, Category.CORE})
public class xmlGeneratorEndpoint extends DefaultEndpoint {

    @UriPath
    @Metadata(required = true)
    private String testScope;

我的问题是,“testScope”从未使用过。默认设置具有setter/getter,但两者都未被调用。
使用.to("xmlGenerator://hello?option=12"),“testScope”变量永远不会被设置。即使使用.to("xmlGenerator://?option=12")也不会引起问题。我想它应该。
如何让它设置值?

fzwojiic

fzwojiic1#

它是负责设置的组件,你需要在组件源代码中添加它。您需要对所有标记为UriPath的选项执行此操作。标记为UriParam的选项可以通过setProperties...从组件自动批量Map。
但看看现有的组件源代码之一,以更好地理解。
还有一些文档在:https://camel.apache.org/manual/writing-components.html
如果你有CiA 2的书,它有一章/一节是关于编写自定义组件的。

xggvc2p6

xggvc2p62#

通过查看google-bigquery组件解决了这个问题(感谢Claus)。
主要的部分是你需要实现一个

public class ProducerContractConfiguration implements Cloneable {
    // this is where you put your path variables (obj://__TheseValues:moreValues)
}

在EndPoint类中添加以下设置:

@UriParam
    protected final ProducerContractConfiguration configuration;

    public ProducerContractEndpoint(String uri, ProducerContractComponent component, ProducerContractConfiguration configuration) {
        super(uri, component);
        this.configuration = configuration;
    }

    /**
     * Note, this seems to be needed for Mojo to not yell at you. 
     * @return
     */
    public ProducerContractConfiguration getConfiguration() {
        return configuration;
    }

还发现,如果你遇到构建问题,清理“生成”文件夹,然后再次运行maven命令。

相关问题