Commit 447379a5 by Johannes Stelzer

Do not handle 5xx or 4xx responses in RestTemplate for the StatusUpdater as error

fixes #105
parent 3cb0378f
...@@ -26,10 +26,12 @@ import org.springframework.context.ApplicationListener; ...@@ -26,10 +26,12 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
...@@ -114,8 +116,13 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter impleme ...@@ -114,8 +116,13 @@ public class AdminServerWebConfiguration extends WebMvcConfigurerAdapter impleme
@ConfigurationProperties("spring.boot.admin.monitor") @ConfigurationProperties("spring.boot.admin.monitor")
public StatusUpdater statusUpdater(ApplicationStore store) { public StatusUpdater statusUpdater(ApplicationStore store) {
RestTemplate template = new RestTemplate(); RestTemplate template = new RestTemplate();
template.getMessageConverters().add( template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
new MappingJackson2HttpMessageConverter()); template.setErrorHandler(new DefaultResponseErrorHandler() {
@Override
protected boolean hasError(HttpStatus statusCode) {
return false;
}
});
return new StatusUpdater(template, store); return new StatusUpdater(template, store);
} }
......
...@@ -84,7 +84,7 @@ public class StatusUpdaterTest { ...@@ -84,7 +84,7 @@ public class StatusUpdaterTest {
// HTTP != 200 - DOWN // HTTP != 200 - DOWN
when(template.getForEntity("health", Map.class)).thenReturn( when(template.getForEntity("health", Map.class)).thenReturn(
ResponseEntity.status(500).<Map> body(null)); ResponseEntity.status(503).<Map> body(null));
updater.updateStatus(Application.create("foo").withId("id") updater.updateStatus(Application.create("foo").withId("id")
.withHealthUrl("health").build()); .withHealthUrl("health").build());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment