use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RestTemplateAutoConfiguration method restTemplateBuilder.
@Bean
@ConditionalOnMissingBean
public RestTemplateBuilder restTemplateBuilder() {
RestTemplateBuilder builder = new RestTemplateBuilder();
HttpMessageConverters converters = this.messageConverters.getIfUnique();
if (converters != null) {
builder = builder.messageConverters(converters.getConverters());
}
List<RestTemplateCustomizer> customizers = this.restTemplateCustomizers.getIfAvailable();
if (!CollectionUtils.isEmpty(customizers)) {
customizers = new ArrayList<>(customizers);
AnnotationAwareOrderComparator.sort(customizers);
builder = builder.customizers(customizers);
}
return builder;
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method boundRestTemplateShouldPrefixRootUri.
@Test
public void boundRestTemplateShouldPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
restTemplate.getForEntity("/hello", String.class);
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri.
@Test
public void boundRestTemplateWhenUrlIncludesDomainShouldNotPrefixRootUri() {
RestTemplate restTemplate = new RestTemplateBuilder().rootUri("http://example.com").build();
MockRestServiceServer server = RootUriRequestExpectationManager.bindTo(restTemplate);
server.expect(requestTo("/hello")).andRespond(withSuccess());
this.thrown.expect(AssertionError.class);
this.thrown.expectMessage("expected:<http://example.com/hello> but was:<http://spring.io/hello>");
restTemplate.getForEntity("http://spring.io/hello", String.class);
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager.
@Test
public void forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager() throws Exception {
RestTemplate restTemplate = new RestTemplateBuilder().build();
RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate, this.delegate);
assertThat(actual).isSameAs(this.delegate);
}
Aggregations