15
15
import org .slf4j .Logger ;
16
16
import org .slf4j .LoggerFactory ;
17
17
import org .springframework .beans .factory .annotation .Value ;
18
+ import org .springframework .boot .context .event .ApplicationReadyEvent ;
18
19
import org .springframework .stereotype .Component ;
19
20
import org .springframework .web .client .RestClient ;
20
21
22
+ import com .fasterxml .jackson .core .JsonProcessingException ;
23
+ import com .fasterxml .jackson .databind .ObjectMapper ;
24
+
21
25
import ch .xxx .aidoclibchat .domain .client .TmdbClient ;
22
26
23
27
@ Component
@@ -32,6 +36,13 @@ public TmdbRestClient(RestClient restClient) {
32
36
this .restClient = restClient ;
33
37
}
34
38
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
+
35
46
@ Override
36
47
public Response apply (Request request ) {
37
48
var url = BASE_URL + "search/movie?query=" + request .query ();
@@ -40,9 +51,19 @@ public Response apply(Request request) {
40
51
.header ("accept" , "application/json" )
41
52
.header ("Authorization" , "Bearer " +this .apiKey )
42
53
.retrieve ()
43
- .body (Response .class );
44
- LOG .info ("Response from TMDB: {}" , response );
54
+ .body (Response .class );
55
+ // LOG.info("TMDB Response : {}", toJson( response) );
45
56
return response ;
46
57
}
47
58
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
+
48
69
}
0 commit comments