在 Camel 中,如何在标头上使用 xpath 拆分路线 [英] In Camel how can i split a route using xpath on a header

查看:18
本文介绍了在 Camel 中,如何在标头上使用 xpath 拆分路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所暗示的那样,我有一个带有标题的路由,其中​​包含一些类似于以下代码段的 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"))

这篇关于在 Camel 中,如何在标头上使用 xpath 拆分路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆