在骆驼中,如何在标头上使用xpath拆分路线 [英] In Camel how can i split a route using xpath on a header
问题描述
正如标题所示,我有一条带有标题的路由,该标题包含一些类似于以下代码片段的xml作为字符串;
As the title suggests, i have a route with a header that contains some xml similar to the following snippet as a string;
<files>
<image_file1>image.png</image_file1>
<image_file2>image.png</image_file2>
</files>
我正在尝试做的事情是通过xpath使用类似以下内容的方法来拆分的.如下所示,当xml是主体的一部分时,所有命令都可以正常运行:-
What I'm trying do do is split via xpath using something like the following. As the following suggests when the xml is part of the body, all runs fine:-
from(myIncomingQueue)
.convertBodyTo(String.class, "utf-8")
.split(xpath("//*[local-name()='files']/*"))
.setHeader("FilePropertyToRetrieve", xpath("local-name(//*)").stringResult())
.to(myFileDownloadQueue)
.routeId("COMMON-CON-Attachment_Router-Id");
我使用以下方法找到了解决方案:-
I found a solution using the following:-
from(myIncomingQueue)
.setBody(header("myHeaderWithXml"))
.convertBodyTo(String.class, "utf-8")
.split(xpath("//*[local-name()='files']/*"))
.setHeader("FilePropertyToRetrieve", xpath("local-name(//*)").stringResult())
.setBody(header("CamelOriginalBody"))
.to(myFileDownloadQueue)
.routeId("COMMON-CON-Attachment_Router-Id");
但是出于学习目的,您是否仍然想知道是否有一种方法可以将标头移到主体中,然后再将其反转呢?
But would still like to know for learning purposes, if there is a way to do it without moving the header into the body and then reversing afterwards?
推荐答案
是的,如果您在以下位置阅读了有关xpath的文档: http://camel.apache.org/xpath -然后参见在标题上使用XPath
Yes if you read the docs about xpath at: http://camel.apache.org/xpath - then see the section Using XPath on Headers
类似的东西
.split(xpath("//*[local-name()='files']/*", "myHeaderWithXml"))
这篇关于在骆驼中,如何在标头上使用xpath拆分路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!