2222import org .springframework .context .ApplicationEventPublisher ;
2323import org .springframework .context .ApplicationEventPublisherAware ;
2424import org .springframework .http .ResponseEntity ;
25- import org .springframework .web .client .RestClientException ;
2625import org .springframework .web .client .RestTemplate ;
2726
2827import de .codecentric .boot .admin .event .ClientApplicationStatusChangedEvent ;
3433 * The StatusUpdater is responsible for updatig the status of all or a single
3534 * application querying the healthUrl.
3635 *
37- * @author Johannes Stelzer
36+ * @author Johannes Edmeier
3837 *
3938 */
4039public class StatusUpdater implements ApplicationEventPublisherAware {
@@ -50,7 +49,6 @@ public class StatusUpdater implements ApplicationEventPublisherAware {
5049 */
5150 private long statusLifetime = 30_000L ;
5251
53-
5452 public StatusUpdater (RestTemplate restTemplate , ApplicationStore store ) {
5553 this .restTemplate = restTemplate ;
5654 this .store = store ;
@@ -59,7 +57,7 @@ public StatusUpdater(RestTemplate restTemplate, ApplicationStore store) {
5957 public void updateStatusForAllApplications () {
6058 long now = System .currentTimeMillis ();
6159 for (Application application : store .findAll ()) {
62- if ( now - statusLifetime > application .getStatusInfo ().getTimestamp ()) {
60+ if (now - statusLifetime > application .getStatusInfo ().getTimestamp ()) {
6361 updateStatus (application );
6462 }
6563 }
@@ -85,18 +83,18 @@ private StatusInfo queryStatus(Application application) {
8583
8684 try {
8785 @ SuppressWarnings ("unchecked" )
88- ResponseEntity <Map <String , String >> response = restTemplate .getForEntity (application .getHealthUrl (), (Class <Map <String , String >>)(Class <?>) Map .class );
86+ ResponseEntity <Map <String , Object >> response = restTemplate .getForEntity (application .getHealthUrl (), (Class <Map <String , Object >>)(Class <?>) Map .class );
8987 LOGGER .debug ("/health for {} responded with {}" , application , response );
9088
91- if (response .hasBody () && response .getBody ().get ("status" ) != null ) {
92- return StatusInfo .valueOf (response .getBody ().get ("status" ));
89+ if (response .hasBody () && response .getBody ().get ("status" ) instanceof String ) {
90+ return StatusInfo .valueOf (( String ) response .getBody ().get ("status" ));
9391 } else if (response .getStatusCode ().is2xxSuccessful ()) {
9492 return StatusInfo .ofUp ();
9593 } else {
9694 return StatusInfo .ofDown ();
9795 }
9896
99- } catch (RestClientException ex ){
97+ } catch (Exception ex ){
10098 LOGGER .warn ("Couldn't retrieve status for {}" , application , ex );
10199 return StatusInfo .ofOffline ();
102100 }
@@ -111,5 +109,4 @@ public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
111109 this .publisher = publisher ;
112110 }
113111
114-
115112}
0 commit comments