2012-10-11 15 views
1

我們有使用http-outboundgateway放置REST調用HTTP的出站網關沒有表現出特殊字符 - 編碼休息

<int-http:outbound-gateway request-channel="glNewsRequestChannel" 
url="${gl.url}" http-method="GET" expected-response-type="java.lang.String" 
reply-channel="glHeaderEnricher" charset="iso-8859-1"> 
<int-http:uri-variable name="site_code" 
expression="payload" /> 
</int-http:outbound-gateway> 

響應時被取出,並保存記錄在文件中的客戶端,它顯示了一些混亂的字符 - 基本上無法翻譯特定的編碼。 我提到SI文檔有提到,除非工廠指定的Java URLConnection類是用來放置REST調用。 要縮小問題的範圍,我寫了一個小型的Java程序,並直接使用URLConnection類,而無需使用任何開箱模板或網關 - 它成功地獲取並呈現所有的特殊字符。我嘗試了另一個獨立的應用程序,它的Apache HTTP庫,它也能夠獲取字符。 我很想念爲SI的一部分提供的配置?

回答

1

進一步調查顯示,我們使用使用字符串轉換器,如果我們使用的byte [],按照以bytearraymessageconverter - 它運行正常的錯誤消息變換-Instead。

<int-http:outbound-gateway request-channel="glNewsRequestChannel" url="${gl.url}" 
    http-method="GET" message-converters="byteArrayHttpMessageConverter" 
    expected-response-type="byte[]" reply-channel="glHeaderEnricher" 
    charset="iso-8859-1"> <int-http:uri-variable name="site_code" 
    expression="payload" /> 
    </int-http:outbound-gateway> 

哪裏byteArrayHttpMessageConverter可以被定義爲:

<bean id="byteArrayHttpMessageConverter" 
    class="org.springframework.http.converter.ByteArrayHttpMessageConverter"> 
    </bean>