0

私は spring mvc サービスにプロキシを作成しました。これは、クライアントが特定の形式で行うリクエストをそれぞれのサービスに渡します。これはうまく機能していますが、いくつかの問題があります。これが私のコードです。

        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        InetSocketAddress address = new InetSocketAddress(this.serviceUrl, Integer.parseInt(this.servicePort));
        Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
        factory.setProxy(proxy);
        factory.setBufferRequestBody(true);
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(factory);

        ResponseEntity<byte[]> responseEntity = restTemplate.exchange(uri, method, new HttpEntity<Object>(body,headers), byte[].class);
        return responseEntity;

ターゲット サーバーが次のヘッダーを含む応答を送信すると、このコードは壊れます。

Access-Control-Allow-Headers:X-Requested-With
Access-Control-Allow-Methods:GET
Access-Control-Allow-Origin:*
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:3636
Content-Type:application/json
Date:Thu, 26 Nov 2015 06:51:26 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.9 (Unix) PHP/5.5.23
X-Powered-By:PHP/5.5.23

そして、ターゲット応答が

Access-Control-Allow-Headers:X-Requested-With
Access-Control-Allow-Methods:GET
Access-Control-Allow-Origin:*
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Type:application/json
Date:Thu, 26 Nov 2015 06:54:14 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=100
Pragma:no-cache
Server:Apache/2.4.9 (Unix) PHP/5.5.23
Transfer-Encoding:chunked
X-Powered-By:PHP/5.5.23

Transfer-Encoding:chunkedContent-Lengthを見つけることができる唯一の違い

プロキシ サービスは、データ全体をクライアントに転送していません。むしろ、ある程度のデータを取得した後に壊れます。

誰かがそれを修正する方法を知っている場合。プロキシ構成に問題があると確信しています。しかし、それを修正することはできません。

4

0 に答える 0