2727import org .fairdatateam .fairdatapoint .config .properties .PingProperties ;
2828import org .fairdatateam .fairdatapoint .entity .settings .Settings ;
2929import org .fairdatateam .fairdatapoint .service .settings .SettingsService ;
30- import org .springframework .beans .factory .annotation .Autowired ;
3130import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
3231import org .springframework .scheduling .annotation .Async ;
3332import org .springframework .scheduling .annotation .Scheduled ;
3433import org .springframework .stereotype .Service ;
35- import org .springframework .web .client .RestTemplate ;
34+ import org .springframework .web .client .RestClient ;
3635
3736import java .util .List ;
3837import java .util .Map ;
4342@ ConditionalOnProperty (name = "ping.enabled" , havingValue = "true" , matchIfMissing = true )
4443public class PingService {
4544
46- @ Autowired
47- private PingProperties pingProperties ;
45+ private final PingProperties pingProperties ;
4846
49- @ Autowired
50- private InstanceProperties instanceProperties ;
47+ private final InstanceProperties instanceProperties ;
5148
52- @ Autowired
53- private SettingsService settingsService ;
49+ private final SettingsService settingsService ;
5450
55- @ Autowired
56- private RestTemplate client ;
51+ private final RestClient client ;
52+
53+ /**
54+ * Constructor (autowired)
55+ */
56+ public PingService (PingProperties pingProperties , InstanceProperties instanceProperties , SettingsService settingsService , RestClient client ) {
57+ this .pingProperties = pingProperties ;
58+ this .instanceProperties = instanceProperties ;
59+ this .settingsService = settingsService ;
60+ this .client = client ;
61+ }
5762
5863 @ Scheduled (
5964 initialDelayString = "${ping.initDelay:#{10*1000}}" ,
@@ -80,7 +85,7 @@ public void ping() {
8085 void pingEndpoint (String endpoint , Map <String , String > request ) {
8186 try {
8287 log .info ("Pinging {}" , endpoint );
83- client .postForEntity ( endpoint , request , String .class );
88+ client .post (). uri ( endpoint ). body ( request ). retrieve (). toEntity ( String .class );
8489 }
8590 catch (Exception exception ) {
8691 log .warn ("Failed to ping {}: {}" , endpoint , exception .getMessage ());
0 commit comments