88import org .springframework .stereotype .Component ;
99import org .springframework .web .reactive .function .client .WebClient ;
1010import org .springframework .web .util .UriComponentsBuilder ;
11+ import reactor .core .publisher .Mono ;
1112
1213import java .net .URI ;
1314import java .time .Duration ;
@@ -75,7 +76,8 @@ List<Map<String, String>> getStatuses(Map<String, ArchivePVOptions> archivePVS,
7576 }
7677
7778 private List <Map <String , String >> getStatusesFromPvListQuery (String archiverURL , List <String > pvs ) {
78- URI pvStatusURI = UriComponentsBuilder .fromUri (URI .create (archiverURL + PV_STATUS_RESOURCE ))
79+ String uriString = archiverURL + PV_STATUS_RESOURCE ;
80+ URI pvStatusURI = UriComponentsBuilder .fromUri (URI .create (uriString ))
7981 .queryParam ("pv" , String .join ("," , pvs ))
8082 .build ()
8183 .toUri ();
@@ -85,6 +87,7 @@ private List<Map<String, String>> getStatusesFromPvListQuery(String archiverURL,
8587 .retrieve ()
8688 .bodyToMono (String .class )
8789 .timeout (Duration .of (TIMEOUT_SECONDS , ChronoUnit .SECONDS ))
90+ .onErrorResume (e -> showError (uriString , e ))
8891 .block ();
8992
9093 try {
@@ -93,18 +96,22 @@ private List<Map<String, String>> getStatusesFromPvListQuery(String archiverURL,
9396 });
9497 } catch (JsonProcessingException e ) {
9598 logger .log (Level .WARNING , "Could not parse pv status response: " + e .getMessage ());
99+ } catch (Exception e ) {
100+ logger .log (Level .WARNING , String .format ("Error when trying to get status from pv list query: %s" , e .getMessage ()));
96101 }
97102 return List .of ();
98103 }
99104
100105 private List <Map <String , String >> getStatusesFromPvListBody (String archiverURL , List <String > pvs ) {
106+ String uriString = archiverURL + PV_STATUS_RESOURCE ;
101107 String response = client .post ()
102- .uri (URI .create (archiverURL + PV_STATUS_RESOURCE ))
108+ .uri (URI .create (uriString ))
103109 .contentType (MediaType .APPLICATION_JSON )
104110 .bodyValue (pvs )
105111 .retrieve ()
106112 .bodyToMono (String .class )
107113 .timeout (Duration .of (TIMEOUT_SECONDS , ChronoUnit .SECONDS ))
114+ .onErrorResume (e -> showError (uriString , e ))
108115 .block ();
109116
110117 // Structure of response is
@@ -117,19 +124,23 @@ private List<Map<String, String>> getStatusesFromPvListBody(String archiverURL,
117124 });
118125 } catch (JsonProcessingException e ) {
119126 logger .log (Level .WARNING , "Could not parse pv status response: " + e .getMessage ());
127+ } catch (Exception e ) {
128+ logger .log (Level .WARNING , String .format ("Error when trying to get status from pv list query: %s" , e .getMessage ()));
120129 }
121130 return List .of ();
122131 }
123132
124133 private void submitAction (String values , String endpoint , String aaURL ) {
134+ String uriString = aaURL + MGMT_RESOURCE + endpoint ;
125135 try {
126136 String response = client .post ()
127- .uri (URI .create (aaURL + MGMT_RESOURCE + endpoint ))
137+ .uri (URI .create (uriString ))
128138 .contentType (MediaType .APPLICATION_JSON )
129139 .bodyValue (values )
130140 .retrieve ()
131141 .bodyToMono (String .class )
132142 .timeout (Duration .of (TIMEOUT_SECONDS , ChronoUnit .SECONDS ))
143+ .onErrorResume (e -> showError (uriString , e ))
133144 .block ();
134145 logger .log (Level .FINE , () -> response );
135146
@@ -192,11 +203,13 @@ List<String> getAAPolicies(String aaURL) {
192203 return List .of ();
193204 }
194205 try {
206+ String uriString = aaURL + POLICY_RESOURCE ;
195207 String response = client .get ()
196- .uri (URI .create (aaURL + POLICY_RESOURCE ))
208+ .uri (URI .create (uriString ))
197209 .retrieve ()
198210 .bodyToMono (String .class )
199211 .timeout (Duration .of (10 , ChronoUnit .SECONDS ))
212+ .onErrorResume (e -> showError (uriString , e ))
200213 .block ();
201214 Map <String , String > policyMap = objectMapper .readValue (response , Map .class );
202215 return new ArrayList <>(policyMap .keySet ());
@@ -209,12 +222,13 @@ List<String> getAAPolicies(String aaURL) {
209222
210223 String getVersion (String archiverURL ) {
211224 try {
212-
225+ String uriString = archiverURL + ARCHIVER_VERSIONS_RESOURCE ;
213226 String response = client .get ()
214- .uri (URI .create (archiverURL + ARCHIVER_VERSIONS_RESOURCE ))
227+ .uri (URI .create (uriString ))
215228 .retrieve ()
216229 .bodyToMono (String .class )
217230 .timeout (Duration .of (TIMEOUT_SECONDS , ChronoUnit .SECONDS ))
231+ .onErrorResume (e -> showError (uriString , e ))
218232 .block ();
219233 Map <String , String > versionMap = objectMapper .readValue (response , Map .class );
220234 String [] mgmtVersion = versionMap .get ("mgmt_version" ).split ("Archiver Appliance Version " );
@@ -228,4 +242,9 @@ String getVersion(String archiverURL) {
228242 }
229243 return "" ;
230244 }
245+
246+ private Mono <String > showError (String uriString , Throwable error ) {
247+ logger .log (Level .WARNING , String .format ("There was an error getting a response with URI: %s. Error: %s" , uriString , error .getMessage ()));
248+ return Mono .empty ();
249+ }
231250}
0 commit comments