use of org.springframework.boot.web.client.RestTemplateBuilder in project FredBoat by Frederikam.
the class RestTemplateConfiguration method quarterdeckRestTemplate.
@Bean
public RestTemplate quarterdeckRestTemplate(BackendConfig backendConfig, GsonHttpMessageConverter gson) {
return new RestTemplateBuilder().basicAuthorization(backendConfig.getQuarterdeck().getUser(), backendConfig.getQuarterdeck().getPass()).requestFactory(this::clientHttpRequestFactory).messageConverters(gson).additionalInterceptors(((req, body, execution) -> {
String method = req.getMethodValue();
String uri = req.getURI().toString();
log.debug(">>>{} {} {}", method, uri, new String(body));
ClientHttpResponse response = execution.execute(req, body);
if (response.getBody().markSupported()) {
// this is true if the buffering http request factory is used
response.getBody().mark(Integer.MAX_VALUE);
log.debug("<<<{} {} {}", method, uri, IOUtils.toString(response.getBody(), "UTF-8"));
response.getBody().reset();
}
return response;
})).build();
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RestTemplateMetricsConfigurationTests method restTemplateCreatedWithBuilderIsInstrumented.
@Test
void restTemplateCreatedWithBuilderIsInstrumented() {
this.contextRunner.run((context) -> {
MeterRegistry registry = context.getBean(MeterRegistry.class);
RestTemplateBuilder builder = context.getBean(RestTemplateBuilder.class);
validateRestTemplate(builder, registry);
});
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class MetricsRestTemplateCustomizerTests method whenAutoTimingIsDisabledUriTemplateHandlerDoesNotCaptureUris.
@Test
void whenAutoTimingIsDisabledUriTemplateHandlerDoesNotCaptureUris() {
AtomicBoolean enabled = new AtomicBoolean();
AutoTimer autoTimer = new AutoTimer() {
@Override
public boolean isEnabled() {
return enabled.get();
}
@Override
public void apply(Builder builder) {
}
};
RestTemplate restTemplate = new RestTemplateBuilder(new MetricsRestTemplateCustomizer(this.registry, new DefaultRestTemplateExchangeTagsProvider(), "http.client.requests", autoTimer)).build();
MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(MockRestRequestMatchers.requestTo("/first/123")).andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators.withSuccess("OK", MediaType.APPLICATION_JSON));
mockServer.expect(MockRestRequestMatchers.requestTo("/second/456")).andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators.withSuccess("OK", MediaType.APPLICATION_JSON));
assertThat(restTemplate.getForObject("/first/{id}", String.class, 123)).isEqualTo("OK");
assertThat(this.registry.find("http.client.requests").timer()).isNull();
enabled.set(true);
assertThat(restTemplate.getForObject(URI.create("/second/456"), String.class)).isEqualTo("OK");
this.registry.get("http.client.requests").tags("uri", "/second/456").timer();
this.mockServer.verify();
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class MetricsRestTemplateCustomizerTests method whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild.
@Test
void whenCustomizerAndLocalHostUriTemplateHandlerAreUsedTogetherThenRestTemplateBuilderCanBuild() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("local.server.port", "8443");
LocalHostUriTemplateHandler uriTemplateHandler = new LocalHostUriTemplateHandler(environment, "https");
RestTemplate restTemplate = new RestTemplateBuilder(this.customizer).uriTemplateHandler(uriTemplateHandler).build();
assertThat(restTemplate.getUriTemplateHandler()).asInstanceOf(InstanceOfAssertFactories.type(RootUriTemplateHandler.class)).extracting(RootUriTemplateHandler::getRootUri).isEqualTo("https://localhost:8443");
}
use of org.springframework.boot.web.client.RestTemplateBuilder in project spring-boot by spring-projects.
the class RootUriRequestExpectationManagerTests method forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager.
@Test
void forRestTemplateWhenNotUsingRootUriTemplateHandlerShouldReturnOriginalRequestExpectationManager() {
RestTemplate restTemplate = new RestTemplateBuilder().build();
RequestExpectationManager actual = RootUriRequestExpectationManager.forRestTemplate(restTemplate, this.delegate);
assertThat(actual).isSameAs(this.delegate);
}
Aggregations