org.springframework.boot.web.client.RestTemplateCustomizer Java Examples
The following examples show how to use
org.springframework.boot.web.client.RestTemplateCustomizer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringContractWiremockIssueDemoApplication.java From spring-cloud-contract with Apache License 2.0 | 7 votes |
@Bean public RestTemplateCustomizer someNotOrderedInterceptorCustomizer() { return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { return execution.execute(request, body); } }; restTemplate.getInterceptors().add(emptyInterceptor); } }; }
Example #2
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example #3
Source File: SpringContractWiremockIssueDemoApplication.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
@Bean @Order(SOME_NOT_LOWEST_PRECEDENCE) @Profile("bug") public RestTemplateCustomizer someOrderedInterceptorCustomizer() { return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { return execution.execute(request, body); } }; restTemplate.getInterceptors().add(emptyInterceptor); } }; }
Example #4
Source File: SpringContractWiremockIssueDemoApplication.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
@Bean @Order public RestTemplateCustomizer someLowestPrecedenceOrderedInterceptorCustomizer() { return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { ClientHttpRequestInterceptor emptyInterceptor = new ClientHttpRequestInterceptor() { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { return execution.execute(request, body); } }; restTemplate.getInterceptors().add(emptyInterceptor); } }; }
Example #5
Source File: OkHttpRestTemplateAutoConfiguration.java From okhttp-spring-boot with MIT License | 6 votes |
@Bean @Lazy @ConditionalOnMissingBean public RestTemplateBuilder restTemplateBuilder(ObjectProvider<HttpMessageConverters> messageConverters, ObjectProvider<RestTemplateCustomizer> restTemplateCustomizers, ObjectProvider<RestTemplateRequestCustomizer<?>> restTemplateRequestCustomizers, OkHttpClient okHttpClient) { RestTemplateBuilder builder = new RestTemplateBuilder(); HttpMessageConverters converters = messageConverters.getIfUnique(); if (converters != null) { builder = builder.messageConverters(converters.getConverters()); } builder = addCustomizers(builder, restTemplateCustomizers, RestTemplateBuilder::customizers); builder = addCustomizers(builder, restTemplateRequestCustomizers, RestTemplateBuilder::requestCustomizers); builder = builder.requestFactory(() -> new OkHttp3ClientHttpRequestFactory(okHttpClient)); return builder; }
Example #6
Source File: TracingConfiguration.java From java-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) { final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build(); return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); } }; }
Example #7
Source File: WireMockRestTemplateConfiguration.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnClass(SSLContextBuilder.class) @ConditionalOnProperty(value = "wiremock.rest-template-ssl-enabled", matchIfMissing = true) public RestTemplateCustomizer wiremockRestTemplateCustomizer() { return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { if (restTemplate .getRequestFactory() instanceof HttpComponentsClientHttpRequestFactory) { HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) restTemplate .getRequestFactory(); factory.setHttpClient(createSslHttpClient()); } } private HttpClient createSslHttpClient() { try { SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder().loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE).build(), NoopHostnameVerifier.INSTANCE); return HttpClients.custom().setSSLSocketFactory(socketFactory) .build(); } catch (Exception ex) { throw new IllegalStateException("Unable to create SSL HttpClient", ex); } } }; }
Example #8
Source File: TraceWebClientAutoConfigurationTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@Bean RestTemplateCustomizer myRestTemplateCustomizer() { return restTemplate -> { restTemplate.getInterceptors().add(0, new MySecondClientHttpRequestInterceptor()); }; }
Example #9
Source File: TracingConfiguration.java From brave-webmvc-example with MIT License | 5 votes |
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) { final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build(); return new RestTemplateCustomizer() { @Override public void customize(RestTemplate restTemplate) { restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); } }; }
Example #10
Source File: TracingConfiguration.java From txle with Apache License 2.0 | 4 votes |
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) { final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build(); return restTemplate -> restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); }
Example #11
Source File: TracingConfiguration.java From txle with Apache License 2.0 | 4 votes |
@Bean RestTemplateCustomizer useTracedHttpClient(HttpTracing httpTracing) { final CloseableHttpClient httpClient = TracingHttpClientBuilder.create(httpTracing).build(); return restTemplate -> restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); }
Example #12
Source File: TraceWebClientAutoConfiguration.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean @Order RestTemplateCustomizer traceRestTemplateCustomizer() { return new TraceRestTemplateCustomizer( new LazyTracingClientHttpRequestInterceptor(this.beanFactory)); }
Example #13
Source File: WebClientTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean RestTemplateCustomizer myRestTemplateCustomizer() { return new MyRestTemplateCustomizer(); }
Example #14
Source File: TraceWebClientAutoConfigurationTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean RestTemplateBuilder myRestTemplateBuilder( List<RestTemplateCustomizer> customizers) { return new RestTemplateBuilder().additionalCustomizers(customizers) .additionalInterceptors(new MyClientHttpRequestInterceptor()); }
Example #15
Source File: InitializrStatsAutoConfigurationTests.java From initializr with Apache License 2.0 | 4 votes |
@Bean RestTemplateCustomizer testRestTemplateCustomizer() { return (b) -> b.setErrorHandler(errorHandler); }
Example #16
Source File: AbstractInitializrControllerIntegrationTests.java From initializr with Apache License 2.0 | 4 votes |
@Bean RestTemplateCustomizer mockMvcCustomizer(BeanFactory beanFactory) { return (template) -> template.setRequestFactory(beanFactory.getBean(MockMvcClientHttpRequestFactory.class)); }