Mule Enrichment: enrich xml payload with http endp

2019-08-30 19: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条回答
The star\"
2楼-- · 2019-08-30 19:55

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> 
查看更多
登录 后发表回答