Skip to content
This repository was archived by the owner on Jun 29, 2018. It is now read-only.

Commit 447379a

Browse files
author
Johannes Stelzer
committed
Do not handle 5xx or 4xx responses in RestTemplate for the StatusUpdater as error
fixes #105
1 parent 3cb0378 commit 447379a

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

spring-boot-admin-server/src/main/java/de/codecentric/boot/admin/config/AdminServerWebConfiguration.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import org.springframework.context.annotation.Bean;
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.context.annotation.Import;
29+
import org.springframework.http.HttpStatus;
2930
import org.springframework.http.converter.HttpMessageConverter;
3031
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3132
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
3233
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
34+
import org.springframework.web.client.DefaultResponseErrorHandler;
3335
import org.springframework.web.client.RestTemplate;
3436
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
3537

@@ -114,8 +116,13 @@ public ApplicationIdGenerator applicationIdGenerator() {
114116
@ConfigurationProperties("spring.boot.admin.monitor")
115117
public StatusUpdater statusUpdater(ApplicationStore store) {
116118
RestTemplate template = new RestTemplate();
117-
template.getMessageConverters().add(
118-
new MappingJackson2HttpMessageConverter());
119+
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
120+
template.setErrorHandler(new DefaultResponseErrorHandler() {
121+
@Override
122+
protected boolean hasError(HttpStatus statusCode) {
123+
return false;
124+
}
125+
});
119126
return new StatusUpdater(template, store);
120127
}
121128

spring-boot-admin-server/src/test/java/de/codecentric/boot/admin/registry/StatusUpdaterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void test_update_noBody() {
8484

8585
// HTTP != 200 - DOWN
8686
when(template.getForEntity("health", Map.class)).thenReturn(
87-
ResponseEntity.status(500).<Map> body(null));
87+
ResponseEntity.status(503).<Map> body(null));
8888

8989
updater.updateStatus(Application.create("foo").withId("id")
9090
.withHealthUrl("health").build());

0 commit comments

Comments
 (0)