如何将xpath中的String放到更丰富的URL中

时间:2015-01-20 10:31:18

标签: xpath apache-camel

我需要一个GET参数给一个Enricher。这个参数我希望从带有xpath的Message主体获取。但它不想工作。我错了什么?

.enrich("localhost/getArticle.php?ArticleNumber="+xpath("//POSITION/ARTICLENUMMER[@TYPE='IN']/text()"), new addArticleStrategy())

但是被调用的URL是:

http://localhost/getArticle.php?ArticleNumber=XPath%3A+%2F%2FPOSITION%2FARTICLENUMMER%5B%40TYPE%3D%27IN%27%5D%2Ftext%28%29

如何从xpath获取值,而不是xpath字符串?

谢谢

更新

全程:

from("activemq:in")
.enrich("localhost/getArticle.php?ArticleNumber="+xpath("//POSITION/ARTICLENUMMER[@TYPE='IN']/text()"), new addArticleStrategy())
.to("file://C:/temp/")

更新2: 我尝试评估:

from("activemq:in")
    .enrich("localhost/getArticle.php?ArticleNumber="+xpath("//POSITION/ARTICLENUMMER[@TYPE='IN']/text()").evaluate(getContext(), body().convertToString()), new addArticleStrategy())
    .to("file://C:/temp/")

但我得到了错误:

No type converter available to convert from type: org.apache.camel.builder.ValueBuilder to the required type: org.w3c.dom.Document with value body

1 个答案:

答案 0 :(得分:2)

您无法使用动态网址进行充实。请尝试使用recipientList代替

编辑:

我没有尝试过(对不起可能的拼写错误),但它看起来应该是这样的

XPathBuilder articlexpath=xpath("//POSITION/ARTICLENUMMER[@TYPE='IN']/text()").resultType(String.class);

from("activemq:in")
.enrich("direct:getArticle", new addArticleStrategy())
.to("file://C:/temp/");

from("direct:getArticle")
.setHeader("ArticleNumber", articlexpath)
.recipientList(simple("localhost/getArticle.php?ArticleNumber=${header.ArticleNumber}"));