use of org.springframework.http.client.BufferingClientHttpRequestFactory in project tutorials by eugenp.
the class ApiClient method buildRestTemplate.
/**
* Build the RestTemplate used to make HTTP requests.
* @return RestTemplate
*/
protected RestTemplate buildRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// This allows us to read the response more than once - Necessary for debugging.
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
return restTemplate;
}
use of org.springframework.http.client.BufferingClientHttpRequestFactory in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method bufferRequestBodyCanBeConfiguredOnAWrappedRequestFactory.
@Test
void bufferRequestBodyCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setBufferRequestBody(false).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", false);
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setBufferRequestBody(true).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
}
use of org.springframework.http.client.BufferingClientHttpRequestFactory in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate.
@Test
void unwrappingDoesNotAffectRequestFactoryThatIsSetOnTheBuiltTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
RestTemplate template = this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).build();
assertThat(template.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
use of org.springframework.http.client.BufferingClientHttpRequestFactory in project spring-boot by spring-projects.
the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnAWrappedRequestFactory.
@Test
void connectTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setConnectTimeout(Duration.ofMillis(1234)).build();
assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 1234);
}
use of org.springframework.http.client.BufferingClientHttpRequestFactory in project xm-ms-entity by xm-online.
the class TemplateUtil method getTemplate.
public static RestTemplate getTemplate(ClientHttpRequestInterceptor interceptor) {
RestTemplate restTemplate = new RestTemplate();
List<ClientHttpRequestInterceptor> ris = new ArrayList<>();
ris.add(interceptor);
restTemplate.setInterceptors(ris);
SimpleClientHttpRequestFactory httpFactory = new SimpleClientHttpRequestFactory();
httpFactory.setOutputStreaming(false);
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(httpFactory));
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
return restTemplate;
}
Aggregations