Search in sources :

Example 16 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project uhgroupings by uhawaii-system-its-ti-iam.

the class HttpRequestServiceImpl method makeApiRequest.

/*
     * Make an http request to the API with path variables.
     */
@SuppressWarnings("lgtm[java/xss]")
@Override
public ResponseEntity<String> makeApiRequest(String currentUser, String uri, HttpMethod method) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set(CURRENT_USER, currentUser);
    HttpEntity<String> httpEntity = new HttpEntity<>(httpHeaders);
    RestTemplate restTemplate = new RestTemplateBuilder().errorHandler(new RestTemplateResponseErrorHandler()).build();
    return restTemplate.exchange(uri, method, httpEntity, String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) HttpEntity(org.springframework.http.HttpEntity) RestTemplateResponseErrorHandler(edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler) RestTemplate(org.springframework.web.client.RestTemplate)

Example 17 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.

the class CloudFoundrySecurityServiceTests method setup.

@Before
public void setup() throws Exception {
    MockServerRestTemplateCustomizer mockServerCustomizer = new MockServerRestTemplateCustomizer();
    RestTemplateBuilder builder = new RestTemplateBuilder(mockServerCustomizer);
    this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
    this.server = mockServerCustomizer.getServer();
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) MockServerRestTemplateCustomizer(org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer) Before(org.junit.Before)

Example 18 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.

the class CloudFoundrySecurityServiceTests method skipSslValidationWhenTrue.

@Test
public void skipSslValidationWhenTrue() throws Exception {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, true);
    RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
    assertThat(restTemplate.getRequestFactory()).isInstanceOf(SkipSslVerificationHttpRequestFactory.class);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 19 with RestTemplateBuilder

use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.

the class CloudFoundrySecurityServiceTests method doNotskipSslValidationWhenFalse.

@Test
public void doNotskipSslValidationWhenFalse() throws Exception {
    RestTemplateBuilder builder = new RestTemplateBuilder();
    this.securityService = new CloudFoundrySecurityService(builder, CLOUD_CONTROLLER, false);
    RestTemplate restTemplate = (RestTemplate) ReflectionTestUtils.getField(this.securityService, "restTemplate");
    assertThat(restTemplate.getRequestFactory()).isNotInstanceOf(SkipSslVerificationHttpRequestFactory.class);
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 20 with RestTemplateBuilder

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;
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplateCustomizer(org.springframework.boot.web.client.RestTemplateCustomizer) HttpMessageConverters(org.springframework.boot.autoconfigure.http.HttpMessageConverters) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

RestTemplateBuilder (org.springframework.boot.web.client.RestTemplateBuilder)37 Test (org.junit.jupiter.api.Test)22 RestTemplate (org.springframework.web.client.RestTemplate)21 MockRestServiceServer (org.springframework.test.web.client.MockRestServiceServer)5 TestRestTemplate (org.springframework.boot.test.web.client.TestRestTemplate)4 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)3 Test (org.junit.Test)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 LocalHostUriTemplateHandler (org.springframework.boot.test.web.client.LocalHostUriTemplateHandler)3 Bean (org.springframework.context.annotation.Bean)3 RestTemplateResponseErrorHandler (edu.hawaii.its.api.controller.RestTemplateResponseErrorHandler)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 MockServerRestTemplateCustomizer (org.springframework.boot.test.web.client.MockServerRestTemplateCustomizer)2 HttpEntity (org.springframework.http.HttpEntity)2 HttpHeaders (org.springframework.http.HttpHeaders)2 RequestExpectationManager (org.springframework.test.web.client.RequestExpectationManager)2 Builder (io.micrometer.core.instrument.Timer.Builder)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1