Search in sources :

Example 1 with BufferingClientHttpRequestFactory

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;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Example 2 with BufferingClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 3 with BufferingClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 4 with BufferingClientHttpRequestFactory

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);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 5 with BufferingClientHttpRequestFactory

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;
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Aggregations

BufferingClientHttpRequestFactory (org.springframework.http.client.BufferingClientHttpRequestFactory)10 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)7 RestTemplate (org.springframework.web.client.RestTemplate)6 Test (org.junit.jupiter.api.Test)4 ClientHttpRequestInterceptor (org.springframework.http.client.ClientHttpRequestInterceptor)3 ArrayList (java.util.ArrayList)2 Bean (org.springframework.context.annotation.Bean)2 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)2 X509Certificate (java.security.cert.X509Certificate)1 SSLContext (javax.net.ssl.SSLContext)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 LoggingInterceptor (org.eclipse.vorto.repository.utils.LoggingInterceptor)1 RequestResponseLoggingInterceptor (org.esupportail.papercut.services.RequestResponseLoggingInterceptor)1 ExtendedErrorHandler (org.openkilda.testing.tools.ExtendedErrorHandler)1 LoggingRequestInterceptor (org.openkilda.testing.tools.LoggingRequestInterceptor)1 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1