Mule Enrichment: enrich xml payload with http endpoint response

匆匆过客 提交于 2019-12-13 03:44:43

问题


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>

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 ?

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

回答1:


There's a couple of issues here:

  • your expression transformer will not work inside the outbound endpoint
  • your xpath expression will not work due to the xmlns ref in the xml
  • you can not transform an xml string with an enhancer

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> 


来源:https://stackoverflow.com/questions/22059055/mule-enrichment-enrich-xml-payload-with-http-endpoint-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!