【问题标题】:In Camel how to pass an xml node to a method in a class在Camel中如何将xml节点传递给类中的方法
【发布时间】:2016-02-18 16:42:18
【问题描述】:

我有一个 xml 节点,我使用以下代码从 xml 文件中解析该节点

    File file = new File("test.xml");
    DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = dBuilder.parse(file);
    NodeList configNodeList = doc.getElementsByTagName("connector");
    Node configNode = configNodeList.item(0);

我必须将 conigNode 传递给另一个类中的方法。 该项目在骆驼中,我必须测试一个类,它有一个接受 configNode 作为输入的方法。 我是否在ProducerTemplate的sendBody中添加configNode

template.sendBody("");

或在路由构建器中的某个地方

             from("direct:start")
             .to("mock:result"); 

我是 Camel 的新手,我过得很艰难。请帮忙!

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    要处理 XML 文件的选定节点,您可以编写如下所示的路由:

        from("file://test.xml?noop=true") //Read your xml
        .setBody().xpath("//connector/node()")       //select NodeList by xpath
        .split(body()) //Split list - below working with one Node
        .to("log:like-to-see-all?level=INFO&showAll=true&multiline=true") // print all data to log
        //below must be a processing of your node, maybe the data type conversion before that
        .bean(new YourBean(), "methodName");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-15
      • 2019-03-28
      • 1970-01-01
      • 2011-07-19
      • 2015-01-02
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多