2323
2424package com .iluwatar .api .gateway ;
2525
26+ import static org .slf4j .LoggerFactory .getLogger ;
27+
2628import java .io .IOException ;
2729import java .net .URI ;
2830import java .net .http .HttpClient ;
2931import java .net .http .HttpRequest ;
32+ import java .net .http .HttpResponse ;
3033import java .net .http .HttpResponse .BodyHandlers ;
34+
35+ import org .slf4j .Logger ;
3136import org .springframework .stereotype .Component ;
3237
3338/**
3439 * An adapter to communicate with the Image microservice.
3540 */
3641@ Component
3742public class ImageClientImpl implements ImageClient {
43+ private static final Logger LOGGER = getLogger (ImageClientImpl .class );
44+
3845 /**
3946 * Makes a simple HTTP Get request to the Image microservice.
4047 *
@@ -49,12 +56,26 @@ public String getImagePath() {
4956 .build ();
5057
5158 try {
59+ LOGGER .info ("Sending request to fetch image path" );
5260 var httpResponse = httpClient .send (httpGet , BodyHandlers .ofString ());
61+ logResponse (httpResponse );
5362 return httpResponse .body ();
5463 } catch (IOException | InterruptedException e ) {
55- e . printStackTrace ( );
64+ LOGGER . error ( "Failure occurred while getting image path" , e );
5665 }
5766
5867 return null ;
5968 }
69+
70+ private void logResponse (HttpResponse <String > httpResponse ) {
71+ if (isSuccessResponse (httpResponse .statusCode ())) {
72+ LOGGER .info ("Image path received successfully" );
73+ } else {
74+ LOGGER .warn ("Image path request failed" );
75+ }
76+ }
77+
78+ private boolean isSuccessResponse (int responseCode ) {
79+ return responseCode >= 200 && responseCode <= 299 ;
80+ }
6081}
0 commit comments