1515import org .slf4j .Logger ;
1616import org .slf4j .LoggerFactory ;
1717import org .springframework .beans .factory .annotation .Value ;
18+ import org .springframework .boot .context .event .ApplicationReadyEvent ;
1819import org .springframework .stereotype .Component ;
1920import org .springframework .web .client .RestClient ;
2021
22+ import com .fasterxml .jackson .core .JsonProcessingException ;
23+ import com .fasterxml .jackson .databind .ObjectMapper ;
24+
2125import ch .xxx .aidoclibchat .domain .client .TmdbClient ;
2226
2327@ Component
@@ -32,6 +36,13 @@ public TmdbRestClient(RestClient restClient) {
3236 this .restClient = restClient ;
3337 }
3438
39+ //@EventListener
40+ public void onApplicationEvent (ApplicationReadyEvent event ) {
41+ var request = new Request ("Alien" );
42+ var response = this .apply (request );
43+ LOG .info ("TMDB Response: {}" , toJson (response ));
44+ }
45+
3546 @ Override
3647 public Response apply (Request request ) {
3748 var url = BASE_URL + "search/movie?query=" + request .query ();
@@ -40,9 +51,19 @@ public Response apply(Request request) {
4051 .header ("accept" , "application/json" )
4152 .header ("Authorization" , "Bearer " +this .apiKey )
4253 .retrieve ()
43- .body (Response .class );
44- LOG .info ("Response from TMDB: {}" , response );
54+ .body (Response .class );
55+ // LOG.info("TMDB Response : {}", toJson( response) );
4556 return response ;
4657 }
4758
59+ private static String toJson (Object obj ) {
60+ var result = "" ;
61+ try {
62+ result = new ObjectMapper ().writeValueAsString (obj );
63+ } catch (JsonProcessingException e ) {
64+ LOG .error ("Error converting object to JSON" , e );
65+ }
66+ return result ;
67+ }
68+
4869}
0 commit comments