我構建了一個簡單的Spring集成應用程序,它從目錄中讀取CSV文件,將它們轉換爲XML文檔並通過REST XML Web服務將它們發送到系統。與Spring集成使用HttpOutboundGateway時發生HTTP 415錯誤
集成信息流看起來是這樣的:
<int-file:inbound-channel-adapter channel="filesChannel" ... />
<int:channel id="filesChannel" />
<int:publish-subscribe-channel id="resultChannel" />
<int:chain input-channel="filesChannel" output-channel="resultChannel">
<!-- Parse the CSV into individual messages of Map<String,String> type -->
<int:transformer ref="csvToMapsTransformer" method="transform" />
<int:splitter />
<!-- Transform the map into a simple XML -->
<int:transformer ref="mapToXmlTransformer" method="transform" />
<!-- Use XSLT template to transform the simple XML into the API format -->
<int-xml:xslt-transformer xsl-resource="order-api-transform.xslt" />
<int:header-enricher>
<int:header name="Content-Type" value="text/xml" />
</int:header-enricher>
<!-- Post the XML to the target system -->
<int-http:outbound-gateway
http-method="POST"
url="http://example.com/method"
expected-response-type="javax.xml.transform.Source"
/>
</int:chain>
的mapToXmlTransformer
是在它建立與一個StringBuilder一個XML字符串映射項的簡單循環。然後將這個XML字符串用XSLT轉換爲目標系統預期的格式。
流程的工作原理與我期待的非常相似。它發送一個POST請求到目標系統的有效載荷,但它返回一個HTTP 415迴應:
Caused by: org.springframework.web.client.HttpClientErrorException: 415 Cannot consume content type
好像我做一個簡單的愚蠢的錯誤與我的流量,但我相信新的Spring集成和自己找不到它。
請幫
目標系統所期望的'應用程序/ xml'取代'文/ xml'並非常嚴格的這一點。 Info:'application/xml'也是有效的,並且定義了對人類來說不可讀(模糊的定義)的媒體類型。 – meistermeier
嗨@meistermeier。你是對的,應用程序確實期望'application/xml',但這不是唯一的問題。你和Gary的建議相結合幫助了我! – artemb