use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method requestFactoryShouldApply.
@Test
void requestFactoryShouldApply() {
ClientHttpRequestFactory requestFactory = mock(ClientHttpRequestFactory.class);
RestTemplate template = this.builder.requestFactory(() -> requestFactory).build();
assertThat(template.getRequestFactory()).isSameAs(requestFactory);
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTests method customizerShouldBeAppliedAtTheEnd.
@Test
void customizerShouldBeAppliedAtTheEnd() {
ResponseErrorHandler errorHandler = mock(ResponseErrorHandler.class);
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
this.builder.interceptors(this.interceptor).messageConverters(this.messageConverter).rootUri("http://localhost:8080").errorHandler(errorHandler).basicAuthentication("spring", "boot").requestFactory(() -> requestFactory).customizers((restTemplate) -> {
assertThat(restTemplate.getInterceptors()).hasSize(1);
assertThat(restTemplate.getMessageConverters()).contains(this.messageConverter);
assertThat(restTemplate.getUriTemplateHandler()).isInstanceOf(RootUriTemplateHandler.class);
assertThat(restTemplate.getErrorHandler()).isEqualTo(errorHandler);
ClientHttpRequestFactory actualRequestFactory = restTemplate.getRequestFactory();
assertThat(actualRequestFactory).isInstanceOf(InterceptingClientHttpRequestFactory.class);
ClientHttpRequestInitializer initializer = restTemplate.getHttpRequestInitializers().get(0);
assertThat(initializer).isInstanceOf(RestTemplateBuilderClientHttpRequestInitializer.class);
}).build();
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilder method configure.
/**
* Configure the provided {@link RestTemplate} instance using this builder.
*
* @param <T> the type of rest template
* @param restTemplate the {@link RestTemplate} to configure
* @return the rest template instance
* @see RestTemplateBuilder#build()
* @see RestTemplateBuilder#build(Class)
*/
public <T extends RestTemplate> T configure(T restTemplate) {
ClientHttpRequestFactory requestFactory = buildRequestFactory();
if (requestFactory != null) {
restTemplate.setRequestFactory(requestFactory);
}
addClientHttpRequestInitializer(restTemplate);
if (CollectionUtils.isNotEmpty(messageConverters)) {
restTemplate.setMessageConverters(new ArrayList<>(messageConverters));
}
if (uriTemplateHandler != null) {
restTemplate.setUriTemplateHandler(uriTemplateHandler);
}
if (errorHandler != null) {
restTemplate.setErrorHandler(errorHandler);
}
if (rootUri != null) {
RootUriTemplateHandler.addTo(restTemplate, rootUri);
}
restTemplate.getInterceptors().addAll(interceptors);
if (CollectionUtils.isNotEmpty(customizers)) {
for (RestTemplateCustomizer customizer : customizers) {
customizer.customize(restTemplate);
}
}
return restTemplate;
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-infrastructure by TAKETODAY.
the class RestTemplateBuilderTestsOkHttp3Tests method readTimeoutCanBeConfiguredOnOkHttpRequestFactory.
@Test
void readTimeoutCanBeConfiguredOnOkHttpRequestFactory() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class).setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(requestFactory).extracting("client", InstanceOfAssertFactories.type(OkHttpClient.class)).extracting(OkHttpClient::readTimeoutMillis).isEqualTo(1234);
}
use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.
the class RestTemplateBuilderTests method readTimeoutCanBeConfiguredOnOkHttp3RequestFactory.
@Test
void readTimeoutCanBeConfiguredOnOkHttp3RequestFactory() {
ClientHttpRequestFactory requestFactory = this.builder.requestFactory(OkHttp3ClientHttpRequestFactory.class).setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(requestFactory).isInstanceOf(OkHttp3ClientHttpRequestFactory.class);
assertThat(requestFactory).extracting("client").extracting("readTimeoutMillis").isEqualTo(1234);
}
Aggregations