Spring RestTemplate - BufferingClientHttpRequestFactory & SimpleClientHttpRequestFactory
Spring RestTemplate - BufferingClientHttpRequestFactory & SimpleClientHttpRequestFactory
我在使用 Spring 构建的 Rest 客户端之一中看到了以下代码。此 Rest Client 存在于 REST 服务中并正在调用另一个 REST 服务。此声明的目的是什么?
return new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())
BufferingClientHttpRequestFactory
is a decorator around ClientHttpRequestFactory
, which the RestTemplate uses to create ClientHttpRequest
s which faciliate HTTP communication. This decorator in particular provides buffering of outgoing/incoming streams. This wrapper/decorator also allows multiple reads of the response body, which you won't be able to do if you only use SimpleClientHttpRequestFactory
or HttpComponentsClientHttpRequestFactory
没有这个包装。
SimpleClientHttpRequestFactory
is an implementation of ClientHttpRequestFactory
, which uses JDK facilities (classes from java.net
package) and therefore does not depend on third party libraries, such as Apache HttpComponents HTTP client, which is required by another implementation HttpComponentsClientHttpRequestFactory
.
我在使用 Spring 构建的 Rest 客户端之一中看到了以下代码。此 Rest Client 存在于 REST 服务中并正在调用另一个 REST 服务。此声明的目的是什么?
return new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())
BufferingClientHttpRequestFactory
is a decorator around ClientHttpRequestFactory
, which the RestTemplate uses to create ClientHttpRequest
s which faciliate HTTP communication. This decorator in particular provides buffering of outgoing/incoming streams. This wrapper/decorator also allows multiple reads of the response body, which you won't be able to do if you only use SimpleClientHttpRequestFactory
or HttpComponentsClientHttpRequestFactory
没有这个包装。
SimpleClientHttpRequestFactory
is an implementation of ClientHttpRequestFactory
, which uses JDK facilities (classes from java.net
package) and therefore does not depend on third party libraries, such as Apache HttpComponents HTTP client, which is required by another implementation HttpComponentsClientHttpRequestFactory
.