出站网关如何处理来自远程服务器的json字符串

出站网关如何处理来自远程服务器的json字符串,json,spring-integration,Json,Spring Integration,我是spring集成的新手,我正在用它开发一个代理 以下是我的配置: <int-http:inbound-gateway id="testInboundGateway" supported-methods="GET" request-channel="test-request" extract-reply-payload="false"

我是spring集成的新手,我正在用它开发一个代理

以下是我的配置:

<int-http:inbound-gateway id="testInboundGateway"
                          supported-methods="GET"
                          request-channel="test-request"
                          extract-reply-payload="false"
                          reply-channel="test-reply"
                          path="/user/{id}/info"
                          reply-timeout="50000">
    <int-http:header name="id" expression="#pathVariables.id"/>
</int-http:inbound-gateway>


<int-http:outbound-gateway id="testOutboundGateway"
                           http-method="GET"
                           request-channel="test-request"
                           reply-channel="test-process"
                           url="http://remoteserver/{id}.json"
                           extract-request-payload="false"
                           expected-response-type="java.lang.String"
                           reply-timeout="50000"
                           charset="UTF-8">
    <int-http:uri-variable name="id" expression="headers.id" />
</int-http:outbound-gateway>

<int:service-activator id="activator"
                       input-channel="test-process"
                       output-channel="test-reply"
                       ref="hubBean"
                       method="process"></int:service-activator>

<bean id="hubBean" class="com.test.testhub.HubService"/>

My remote server返回内容类型为application/JSON的JSON;字符集=UTF-8

然而,我的服务bean得到这样的字符串:\u001F\b\u0000\u0000

我不知道是什么。我试图用gzip解码,但格式不正确。
有人能告诉我如何得到实际结果吗?

问题似乎是远程响应被压缩了,而被压缩的字符串已经错了,所以我无法解压缩它。我必须设置预期的响应类型=“byte[]”,以便我可以通过代码对其进行解压缩。

因为我们已经知道您来自该远程服务的响应是
gzip
,即使是JSON,也有两种方法可以克服na问题并提供强健的解决方案:

  • 将响应接受为
    字节[]
    (您现在可以这样做)并手动解压缩

  • 使用
    HttpComponents客户端HttpRequestFactory
    注入到
    中,并使用
    解压缩HttpClient
    装饰器引用


  • 我认为第二个更好。

    您可以使用网络嗅探器(wireshark或eclipse的tcp/ip监视器等)查看实际内容吗?您好,远程服务器返回整洁的json,我直接调用它。编码或转换一定有问题。。。