2017-02-10 83 views
1

似乎是一項簡單的任務,但我無法擺脫困境。在Spring集成中使用來自REST調用的XML響應

我有一個Spring集成鏈,它調用一個外部Web服務,它返回一個XML。我想在下游的XpathRouter中使用該XML響應。

應該使用什麼預期響應類型?

<int:chain input-channel="filesChannel"> 

    <!-- ... some previous components in the chain --> 
    <int-http:outbound-gateway 
     http-method="POST" 
     url="http://web/service/url" 
     expected-response-type="java.lang.String" /> 

    <int-xml:xpath-router default-output-channel="resultChannel"> 
     <int-xml:xpath-expression expression="/order/status" /> 
     <int-xml:mapping value="Error" channel="importErrorChannel" /> 
    </int-xml:xpath-router> 
</int:chain> 

看起來好像xpath-router可以消耗Web服務返回的XML。當我用以下行上的斷點調試路由器時:

Node node = this.converter.convertToNode(message.getPayload()); 

雖然消息確實包含有效的XML,但節點爲空。

是因爲我沒有設置正確的expected-response-type

這裏是響應XML我從服務接收:

<apiResponse version="1.0"> 
<orders> 
<order> 
     <orderReference>test_2_3045342</orderReference> 
     <status>Error</status> 
     <errors> 
      <error> 
       <errorCode>1100</errorCode> 
       <errorMessage><![CDATA[ "Field is required: dropWindow" ]]></errorMessage> 
      </error> 
     </errors> 
</order> 
</orders> 
</apiResponse> 

回答

2

好吧,我發現我的錯誤 - 它實際上是在XPath表達式。它應該是//order/status以啓用深度搜索。

java.lang.String預期響應類型在XML XpathRouter中工作得很好。

謝謝

+0

所以,你現在可以接受你自己的答案! –