【问题标题】:Mule Enrichment: enrich xml payload with http endpoint responseMule Enrichment:使用 http 端点响应丰富 xml 有效负载
【发布时间】:2014-03-30 07:46:28
【问题描述】:

我是 mule 的新手,正在研究 POC。我想通过调用返回 xml 作为响应 (source.xml) 的 http 端点来丰富有效负载(target.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 端点工作正常,但我收到以下错误

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

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

传入消息负载(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):

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

【问题讨论】:

    标签: java mule mule-studio mule-el


    【解决方案1】:

    这里有几个问题:

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

    要完成这项工作,请将出站端点和表达式传输器放入进程链中,使用处理命名空间或忽略它们的 xpath 表达式,并将初始 xml 字符串有效负载转换为其他内容,例如 DOM,你可以操纵。

    这样的事情应该可以工作:

    <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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-18
      • 2015-07-17
      • 1970-01-01
      相关资源
      最近更新 更多