Search in sources :

Example 6 with BufferingClientHttpRequestFactory

use of org.springframework.http.client.BufferingClientHttpRequestFactory in project esup-papercut by EsupPortail.

the class RestConfig method restTemplate.

@Bean
public RestTemplate restTemplate() throws Exception {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(requestFactory));
    restTemplate.setInterceptors(Collections.singletonList(new RequestResponseLoggingInterceptor()));
    restTemplate.getMessageConverters().add(0, jacksonConverter());
    return restTemplate;
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) RestTemplate(org.springframework.web.client.RestTemplate) RequestResponseLoggingInterceptor(org.esupportail.papercut.services.RequestResponseLoggingInterceptor) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

Example 7 with BufferingClientHttpRequestFactory

use of org.springframework.http.client.BufferingClientHttpRequestFactory in project open-kilda by telstra.

the class DefaultServiceConfig method buildLoggingRestTemplate.

/**
 * Build rest template with enabled logging support.
 */
public static RestTemplate buildLoggingRestTemplate() {
    final RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));
    List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
    interceptors.add(new LoggingRequestInterceptor());
    restTemplate.setErrorHandler(new ExtendedErrorHandler());
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ExtendedErrorHandler(org.openkilda.testing.tools.ExtendedErrorHandler) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) LoggingRequestInterceptor(org.openkilda.testing.tools.LoggingRequestInterceptor) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Example 8 with BufferingClientHttpRequestFactory

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

the class RestTemplateBuilderTests method readTimeoutCanBeConfiguredOnAWrappedRequestFactory.

@Test
void readTimeoutCanBeConfiguredOnAWrappedRequestFactory() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    this.builder.requestFactory(() -> new BufferingClientHttpRequestFactory(requestFactory)).setReadTimeout(Duration.ofMillis(1234)).build();
    assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 1234);
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Test(org.junit.jupiter.api.Test)

Example 9 with BufferingClientHttpRequestFactory

use of org.springframework.http.client.BufferingClientHttpRequestFactory in project xm-ms-entity by xm-online.

the class TemplateUtil method disableSSL.

public static void disableSSL(RestTemplate restTemplate) {
    try {
        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true).build();
        CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE)).build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(requestFactory));
    } catch (Exception e) {
        log.error("Exception occurred while creating http factory, error={}", e.getMessage(), e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) SSLContext(javax.net.ssl.SSLContext) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) X509Certificate(java.security.cert.X509Certificate) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory)

Example 10 with BufferingClientHttpRequestFactory

use of org.springframework.http.client.BufferingClientHttpRequestFactory in project vorto by eclipse.

the class RepositoryConfiguration method restTemplate.

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
    List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(new LoggingInterceptor());
    restTemplate.setInterceptors(interceptors);
    restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
    return restTemplate;
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) LoggingInterceptor(org.eclipse.vorto.repository.utils.LoggingInterceptor) RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ClientHttpRequestInterceptor(org.springframework.http.client.ClientHttpRequestInterceptor) BufferingClientHttpRequestFactory(org.springframework.http.client.BufferingClientHttpRequestFactory) Bean(org.springframework.context.annotation.Bean)

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