簡體   English   中英

Mule Enrichment:使用http端點響應來豐富xml負載

[英]Mule Enrichment: enrich xml payload with http endpoint response

我是m子的新手,正在研究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>

這里有幾個問題:

  • 您的表達式轉換器將無法在出站端點內工作
  • 您的xpath表達式由於xml中的xmlns ref而無法正常工作
  • 您不能使用增強器來轉換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> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM