1

我们有一个使用 http-outboundgateway 进行 REST 调用的客户端

<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 的一部分,我缺少任何配置吗?

4

1 回答 1

2

进一步调查显示我们使用了错误的消息转换器 - 如果我们使用 byte[],而不是使用字符串转换器,则根据 bytearraymessageconverter - 它按预期工作。

    <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>
于 2012-10-15T17:17:22.637 回答