Mule Enrichment:使用http端点响应来丰富xml负载 [英] Mule Enrichment: enrich xml payload with http endpoint response

查看:61
本文介绍了Mule Enrichment:使用http端点响应来丰富xml负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是m子的新手,正在研究POC.我想通过调用返回xml作为响应(source.xml)的http端点来丰富有效负载(target.xml).

I'm new to mule and working on a POC. I want to enrich the payload(target.xml) by calling an http endpoint which returns xml as response (source.xml) .

<flow name="mule-configFlow" doc:name="mule-configFlow">
    <jms:inbound-endpoint doc:name="JMS" connector-ref="Active_MQ" queue="QUEUE1"/>
    <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
    <enricher doc:name="Message Enricher" target="#[xpath:Customer/OfficeId]">
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8095" path="myservice/v1/" method="GET" doc:name="HTTP">
         <expression-transformer evaluator="xpath" expression="Response/OffId" />
        </http:outbound-endpoint>
    </enricher>
    <jms:outbound-endpoint queue="QUEUE2" connector-ref="Active_MQ" doc:name="JMS"/>
</flow>

我已经验证并且http端点可以正常工作,但是出现以下错误

I've verified and http endpoint works fine but I'm getting the below error

Expression Evaluator "xpath" with expression "Response/OffId" returned null but a value was required

我正确配置了源表达式和目标表达式吗?

Am i configuring the source and target expression correctly ?

传入消息有效负载(target.xml):

Incoming Message payload (target.xml):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <Customer xmlns="http://www.xyz.com/abc/v1">
   <ActionType>ACCOUNT_ADDED</ActionType>
   <OfficeId></OfficeId>
   <MemberId></MemberId>
</Customer>

丰富资源(source.xml):

Source for enrichment (source.xml):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  <Response xmlns="http://www.xyz.com/abc/v1"> 
    <OffId></OffId>
    <MemId></MemId>
</Response>

推荐答案

这里有几个问题:

  • 您的表达式转换器将不在出站端点内工作
  • 由于xml中的xmlns引用,您的xpath表达式将不起作用
  • 您无法使用增强器来转换xml字符串

要执行此操作,请将出站终结点和表达式传输器放入流程链中,使用xpath表达式处理名称空间或将其忽略,然后将初始xml字符串有效负载转换为其他内容,例如DOM,你可以操纵.

To make this work, put the outbound endpoint and the expression transporter inside a process-chain, use an xpath expression that either handles namespaces or ignores them, and transform your initial xml string payload to something else, for example DOM, that you can manipulate.

类似的事情应该起作用:

Something like this should work:

<mulexml:xml-to-dom-transformer returnClass="org.dom4j.Document"/>
<enricher source="#[payload]" target="#[payload.rootElement.element('OfficeId').text]">
    <processor-chain>
        <http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8095" path="myservice/v1/" method="GET"/>
        <expression-transformer evaluator="xpath" expression="//*[local-name()='OffId']" />
    </processor-chain>
</enricher> 

这篇关于Mule Enrichment:使用http端点响应来丰富xml负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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