2014-09-28 43 views
0

我遇到了一個小問題..有My Mule流程.. 我將一個SOAP有效內容從Message Enricher組件傳遞到外部Web服務,的想法是讓來自外部Web服務的響應特定的屬性值和值存儲在流量變量... 現在,外部web服務響應的響應如下: -如何使用Enricher將外部Web服務響應值存儲在流變量中

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
     <getDesignationResponse xmlns="http://services.test.getDesignation.com/schema/MainData/V1"> 
     <DesignationCodeResult>Junior Developer</DesignationCodeResult> 
     <Code>Success</Code> 
     </getDesignationResponse> 
    </soap:Body> 
</soap:Envelope> 

現在這裏是我的流程: -

<flow name="testFlow1" doc:name="testFlow1"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="test" doc:name="HTTP"/> 

<set-payload value="<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.getDesignation.com/schema/MainData/V1"><soapenv:Header/><soapenv:Body><v1:getDesignationRequest><v1:DesignationCode>jd</v1:DesignationCode></v1:getDesignationRequest></soapenv:Body></soapenv:Envelope>" doc:name="Set Payload"/> 

    <enricher source="#[xpath://getDesignationResponse/DesignationCodeResult]" target="#[variable:myVal]" doc:name="Message Enricher"> 
    <processor-chain doc:name="Processor Chain"> 
    <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8090/designation" responseTimeout="100000" doc:name="HTTP" /> 
    <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/> 

    <logger message="Value from response #[xpath://getDesignationResponse/DesignationCodeResult]" level="INFO" doc:name="Logger"/> 
    </processor-chain>   
</enricher> 

</flow> 

現在你可以看到我想要的價值#[xpath://getDesignationResponse/DesignationCodeResult]存儲到流量變量設爲myVal ..

現在我得到以下異常: -

Exception stack is: 
1. Expression Evaluator "header" with expression "invocation:myVal" returned null but a value was required. (org.mule.api.expression.RequiredValueException) 
    org.mule.expression.ExpressionUtils:235 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/RequiredValueException.html) 
2. Expression Evaluator "header" with expression "invocation:myVal" returned null but a value was required. (org.mule.api.expression.RequiredValueException). Message payload is of type: String (org.mule.api.MessagingException) 
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html) 
-------------------------------------------------------------------------------- 
Root Exception stack trace: 
org.mule.api.expression.RequiredValueException: Expression Evaluator "header" with expression "invocation:myVal" returned null but a value was required. 
    at org.mule.expression.ExpressionUtils.getPropertyInternal(ExpressionUtils.java:235) 
    at org.mule.expression.ExpressionUtils.getProperty(ExpressionUtils.java:85) 
    at org.mule.expression.ExpressionUtils.getProperty(ExpressionUtils.java:72) 
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 
******************************************************************************** 

但我已經把記錄器內的富集<logger message="Value from response #[xpath://getDesignationResponse/DesignationCodeResult]" level="INFO" doc:name="Logger"/>,我所獲得的價值有.. 不過,我不能把使用濃縮塔... 在流量變量提取值請幫助..

+0

如果刪除記錄器是什麼?我想知道如果你正在使用記錄器的HTTP響應輸入流,從而使它不可用的豐富... – 2014-09-29 13:50:37

+0

試圖從Enricher刪除記錄器...我得到相同的例外 – 2014-09-29 14:08:10

回答

0

首先添加命名空間支持:

<mulexml:namespace-manager> 
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
    <mulexml:namespace prefix="vertu" uri="http://services.vertu.getDesignation.com/schema/MainData/V1"/> 
</mulexml:namespace-manager> 

然後停止使用舊的過時表達式語法和使用MEL來代替:

<enricher 
    source="#[xpath('//vertu:getDesignationResponse/vertu:DesignationCodeResult/text()').text]" 
    target="#[flowVars['myVal']]"> 

此外,如果你想保持記錄,添加後的object-to-string-transformer入站HTTP端點,以便將響應輸入流反序列化到String,這可以多次讀取。

1

從後如果可以看出,被張貼的反應有一個命名空間

xmlns="http://services.test.getDesignation.com/schema/MainData/V1" 

命名空間http://services.test.getDesignation.com/schema/MainData/V1應該在你的騾子配置XML命名空間管理登記。

隨後的XPath將能夠從響應識別XML元素基礎上,正確地評論

更新答案:

試試你的流量以下的變形富集部分。

<enricher source="#[payload]" target="#[variable:myVal]" doc:name="Message Enricher"> 
    <processor-chain doc:name="Processor Chain"> 
    <http:outbound-endpoint exchange-pattern="request-response" method="POST" address="http://localhost:8090/designation" responseTimeout="100000" doc:name="HTTP" /> 
    <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/> 
    <logger message="Value from response #[xpath://getDesignationResponse/DesignationCodeResult]" level="INFO" doc:name="Logger"/> 
    <set-payload value="#[xpath://getDesignationResponse/DesignationCodeResult]" /> 
       </processor-chain>   
</enricher> 

希望這會有所幫助。

+0

是的它已經完成,我在Enricher內部的記錄器中獲得DesignationCodeResult的價值..但無法將其設置在richher的流量變量中 – 2014-09-29 14:37:54

+0

您是對的..名稱空間存在輕微問題..需要修改名稱空間和XPATH以便... ..反正你的偉大建議+1。大衛的建議爲我工作。但很多很多謝謝你的幫助.. – 2014-09-29 19:03:12

+0

總是樂意幫忙:) – user1760178 2014-09-29 19:13:35

0

所以,按照大衛的建議,解決的辦法是正確的命名空間的問題,工作代碼爲: -

<mulexml:namespace-manager> 
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
    <mulexml:namespace prefix="vertu" uri="http://services.vertu.getDesignation.com/schema/MainData/V1"/> 
</mulexml:namespace-manager> 
相關問題