Search in sources :

Example 36 with RestTemplateBuilder

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

the class ProxyResponseAutoConfiguration method proxyExchangeArgumentResolver.

@Bean
@ConditionalOnMissingBean
public ProxyExchangeArgumentResolver proxyExchangeArgumentResolver(Optional<RestTemplateBuilder> optional, ProxyProperties proxy) {
    RestTemplateBuilder builder = optional.orElse(new RestTemplateBuilder());
    RestTemplate template = builder.build();
    template.setErrorHandler(new NoOpResponseErrorHandler());
    template.getMessageConverters().add(new ByteArrayHttpMessageConverter() {

        @Override
        public boolean supports(Class<?> clazz) {
            return true;
        }
    });
    ProxyExchangeArgumentResolver resolver = new ProxyExchangeArgumentResolver(template);
    resolver.setHeaders(proxy.convertHeaders());
    // can be null
    resolver.setSensitive(proxy.getSensitive());
    return resolver;
}
Also used : RestTemplateBuilder(org.springframework.boot.web.client.RestTemplateBuilder) RestTemplate(org.springframework.web.client.RestTemplate) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 37 with RestTemplateBuilder

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

the class HttpRequestServiceImpl method makeApiRequestWithBody.

/*
     * Make an http request to the API with path variables and description in the body.
     */
@SuppressWarnings("lgtm[java/xss]")
@Override
public ResponseEntity<String> makeApiRequestWithBody(String currentUser, String uri, String data, HttpMethod method) {
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.set(CURRENT_USER, currentUser);
    HttpEntity<String> httpEntity = new HttpEntity<>(data, 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)

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