Search in sources :

Example 16 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilder method unwrapRequestFactoryIfNecessary.

private ClientHttpRequestFactory unwrapRequestFactoryIfNecessary(ClientHttpRequestFactory requestFactory) {
    if (!(requestFactory instanceof AbstractClientHttpRequestFactoryWrapper)) {
        return requestFactory;
    }
    ClientHttpRequestFactory unwrappedRequestFactory = requestFactory;
    Field field = ReflectionUtils.findField(AbstractClientHttpRequestFactoryWrapper.class, "requestFactory");
    ReflectionUtils.makeAccessible(field);
    do {
        unwrappedRequestFactory = (ClientHttpRequestFactory) ReflectionUtils.getField(field, unwrappedRequestFactory);
    } while (unwrappedRequestFactory instanceof AbstractClientHttpRequestFactoryWrapper);
    return unwrappedRequestFactory;
}
Also used : Field(java.lang.reflect.Field) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) AbstractClientHttpRequestFactoryWrapper(org.springframework.http.client.AbstractClientHttpRequestFactoryWrapper)

Example 17 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilder method configureRequestFactory.

private void configureRequestFactory(RestTemplate restTemplate) {
    ClientHttpRequestFactory requestFactory = null;
    if (this.requestFactory != null) {
        requestFactory = this.requestFactory;
    } else if (this.detectRequestFactory) {
        requestFactory = detectRequestFactory();
    }
    if (requestFactory != null) {
        ClientHttpRequestFactory unwrappedRequestFactory = unwrapRequestFactoryIfNecessary(requestFactory);
        for (RequestFactoryCustomizer customizer : this.requestFactoryCustomizers) {
            customizer.customize(unwrappedRequestFactory);
        }
        restTemplate.setRequestFactory(requestFactory);
    }
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory)

Example 18 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method readTimeoutCanBeConfiguredOnSimpleRequestFactory.

@Test
public void readTimeoutCanBeConfiguredOnSimpleRequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(1234).build().getRequestFactory();
    assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")).isEqualTo(1234);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Example 19 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method readTimeoutCanBeConfiguredOnHttpComponentsRequestFactory.

@Test
public void readTimeoutCanBeConfiguredOnHttpComponentsRequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(HttpComponentsClientHttpRequestFactory.class).setReadTimeout(1234).build().getRequestFactory();
    assertThat(((RequestConfig) ReflectionTestUtils.getField(requestFactory, "requestConfig")).getSocketTimeout()).isEqualTo(1234);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) Test(org.junit.Test)

Example 20 with ClientHttpRequestFactory

use of org.springframework.http.client.ClientHttpRequestFactory in project spring-boot by spring-projects.

the class RestTemplateBuilderTests method connectTimeoutCanBeConfiguredOnSimpleRequestFactory.

@Test
public void connectTimeoutCanBeConfiguredOnSimpleRequestFactory() {
    ClientHttpRequestFactory requestFactory = this.builder.requestFactory(SimpleClientHttpRequestFactory.class).setConnectTimeout(1234).build().getRequestFactory();
    assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")).isEqualTo(1234);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) Netty4ClientHttpRequestFactory(org.springframework.http.client.Netty4ClientHttpRequestFactory) OkHttp3ClientHttpRequestFactory(org.springframework.http.client.OkHttp3ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.Test)

Aggregations

ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)23 Test (org.junit.Test)17 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)12 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)12 URI (java.net.URI)11 BufferingClientHttpRequestFactory (org.springframework.http.client.BufferingClientHttpRequestFactory)10 Netty4ClientHttpRequestFactory (org.springframework.http.client.Netty4ClientHttpRequestFactory)10 OkHttp3ClientHttpRequestFactory (org.springframework.http.client.OkHttp3ClientHttpRequestFactory)10 HttpMethod (org.springframework.http.HttpMethod)9 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)9 IOException (java.io.IOException)7 RestTemplate (org.springframework.web.client.RestTemplate)6 HttpHeaders (org.springframework.http.HttpHeaders)4 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)4 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 RequestConfig (org.apache.http.client.config.RequestConfig)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2