Search in sources :

Example 16 with ClientHttpRequestFactory

use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnHttpComponentsRequestFactory.

@Test
void connectTimeoutCanBeConfiguredOnHttpComponentsRequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(HttpComponentsClientHttpRequestFactory.class).setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
    assertThat(((RequestConfig) ReflectionTestUtils.getField(requestFactory, "requestConfig")).getConnectTimeout()).isEqualTo(1234);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 17 with ClientHttpRequestFactory

use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method connectTimeoutCanBeNullToUseDefault.

@Test
void connectTimeoutCanBeNullToUseDefault() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setConnectTimeout(null).build().getRequestFactory();
    assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", -1);
}
Also used : SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 18 with ClientHttpRequestFactory

use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework 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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) UriTemplateHandler(cn.taketoday.web.util.UriTemplateHandler) Arrays(java.util.Arrays) Mock(org.mockito.Mock) HttpMessageConverter(cn.taketoday.http.converter.HttpMessageConverter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequestConfig(org.apache.http.client.config.RequestConfig) Mockito.spy(org.mockito.Mockito.spy) Supplier(java.util.function.Supplier) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) HttpMethod(cn.taketoday.http.HttpMethod) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) HttpHeaders(cn.taketoday.http.HttpHeaders) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Duration(java.time.Duration) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) ReflectionTestUtils(cn.taketoday.util.ReflectionTestUtils) URI(java.net.URI) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) InOrder(org.mockito.InOrder) ClientHttpRequest(cn.taketoday.http.client.ClientHttpRequest) Set(java.util.Set) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) Assertions.entry(org.assertj.core.api.Assertions.entry) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ResourceHttpMessageConverter(cn.taketoday.http.converter.ResourceHttpMessageConverter) Mockito.inOrder(org.mockito.Mockito.inOrder) RestTemplate(cn.taketoday.web.client.RestTemplate) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) StringHttpMessageConverter(cn.taketoday.http.converter.StringHttpMessageConverter) MediaType(cn.taketoday.http.MediaType) Collections(java.util.Collections) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ClientHttpRequestInterceptor(cn.taketoday.http.client.ClientHttpRequestInterceptor) Mockito.mock(org.mockito.Mockito.mock) ClientHttpRequestInitializer(cn.taketoday.http.client.ClientHttpRequestInitializer) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) ResponseErrorHandler(cn.taketoday.web.client.ResponseErrorHandler) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 19 with ClientHttpRequestFactory

use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework by TAKETODAY.

the class RestTemplateBuilderTests method bufferRequestBodyCanBeConfiguredOnSimpleRequestFactory.

@Test
void bufferRequestBodyCanBeConfiguredOnSimpleRequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setBufferRequestBody(false).build().getRequestFactory();
    assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", false);
    requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setBufferRequestBody(true).build().getRequestFactory();
    assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
    requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).build().getRequestFactory();
    assertThat(requestFactory).hasFieldOrPropertyWithValue("bufferRequestBody", true);
}
Also used : SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) InterceptingClientHttpRequestFactory(cn.taketoday.http.client.InterceptingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(cn.taketoday.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(cn.taketoday.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 20 with ClientHttpRequestFactory

use of cn.taketoday.http.client.ClientHttpRequestFactory in project today-framework 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);
}
Also used : OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) ClientHttpRequestFactory(cn.taketoday.http.client.ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory) OkHttpClient(okhttp3.OkHttpClient) Test(org.junit.jupiter.api.Test)

Aggregations

ClientHttpRequestFactory (cn.taketoday.http.client.ClientHttpRequestFactory)32 OkHttp3ClientHttpRequestFactory (cn.taketoday.http.client.OkHttp3ClientHttpRequestFactory)28 Test (org.junit.jupiter.api.Test)28 HttpComponentsClientHttpRequestFactory (cn.taketoday.http.client.HttpComponentsClientHttpRequestFactory)26 InterceptingClientHttpRequestFactory (cn.taketoday.http.client.InterceptingClientHttpRequestFactory)26 SimpleClientHttpRequestFactory (cn.taketoday.http.client.SimpleClientHttpRequestFactory)26 BufferingClientHttpRequestFactory (cn.taketoday.http.client.BufferingClientHttpRequestFactory)24 RequestConfig (org.apache.http.client.config.RequestConfig)6 RestTemplate (cn.taketoday.web.client.RestTemplate)4 OkHttpClient (okhttp3.OkHttpClient)4 HttpHeaders (cn.taketoday.http.HttpHeaders)2 HttpMethod (cn.taketoday.http.HttpMethod)2 MediaType (cn.taketoday.http.MediaType)2 ClientHttpRequest (cn.taketoday.http.client.ClientHttpRequest)2 ClientHttpRequestInitializer (cn.taketoday.http.client.ClientHttpRequestInitializer)2 ClientHttpRequestInterceptor (cn.taketoday.http.client.ClientHttpRequestInterceptor)2 HttpMessageConverter (cn.taketoday.http.converter.HttpMessageConverter)2 ResourceHttpMessageConverter (cn.taketoday.http.converter.ResourceHttpMessageConverter)2 StringHttpMessageConverter (cn.taketoday.http.converter.StringHttpMessageConverter)2 ReflectionTestUtils (cn.taketoday.util.ReflectionTestUtils)2