2727@ Slf4j
2828public class JavaNetHttpPollingClient implements PollingClient <RowData > {
2929
30+ public static final String DEFAULT_REQUEST_MAX_RETRIES = "3" ;
31+
32+ public static final String DEFAULT_REQUEST_RETRY_TIMEOUT_MS = "1000" ;
33+
3034 private final HttpClient httpClient ;
3135
3236 private final HttpStatusCodeChecker statusCodeChecker ;
@@ -37,6 +41,10 @@ public class JavaNetHttpPollingClient implements PollingClient<RowData> {
3741
3842 private final HttpPostRequestCallback <HttpLookupSourceRequestEntry > httpPostRequestCallback ;
3943
44+ protected final int httpRequestMaxRetries ;
45+
46+ protected final int httpRequestRetryTimeoutMs ;
47+
4048 public JavaNetHttpPollingClient (
4149 HttpClient httpClient ,
4250 DeserializationSchema <RowData > responseBodyDecoder ,
@@ -62,6 +70,20 @@ public JavaNetHttpPollingClient(
6270 .build ();
6371
6472 this .statusCodeChecker = new ComposeHttpStatusCodeChecker (checkerConfig );
73+
74+ this .httpRequestMaxRetries = Integer .parseInt (
75+ options .getProperties ().getProperty (
76+ HttpConnectorConfigConstants .LOOKUP_HTTP_MAX_RETRIES ,
77+ DEFAULT_REQUEST_MAX_RETRIES
78+ )
79+ );
80+
81+ this .httpRequestRetryTimeoutMs = Integer .parseInt (
82+ options .getProperties ().getProperty (
83+ HttpConnectorConfigConstants .LOOKUP_HTTP_RETRY_TIMEOUT_MS ,
84+ DEFAULT_REQUEST_RETRY_TIMEOUT_MS
85+ )
86+ );
6587 }
6688
6789 @ Override
@@ -74,15 +96,43 @@ public Optional<RowData> pull(RowData lookupRow) {
7496 }
7597 }
7698
77- // TODO Add Retry Policy And configure TimeOut from properties
78- private Optional <RowData > queryAndProcess (RowData lookupData ) throws Exception {
79-
99+ private Optional <RowData > queryAndProcess (RowData lookupData ) {
80100 HttpLookupSourceRequestEntry request = requestFactory .buildLookupRequest (lookupData );
81- HttpResponse <String > response = httpClient .send (
82- request .getHttpRequest (),
83- BodyHandlers .ofString ()
84- );
85- return processHttpResponse (response , request );
101+ HttpResponse <String > response = null ;
102+
103+ int retryCount = 0 ;
104+
105+ while (retryCount < this .httpRequestMaxRetries ) {
106+ try {
107+ response = httpClient .send (
108+ request .getHttpRequest (),
109+ BodyHandlers .ofString ()
110+ );
111+ break ;
112+ } catch (IOException e ) {
113+ log .error ("IOException during HTTP request. Retrying..." , e );
114+ retryCount ++;
115+ if (retryCount == this .httpRequestMaxRetries ) {
116+ log .error ("Maximum retries reached. Aborting..." );
117+ return Optional .empty ();
118+ }
119+ try {
120+ Thread .sleep (this .httpRequestRetryTimeoutMs );
121+ } catch (InterruptedException ie ) {
122+ Thread .currentThread ().interrupt ();
123+ }
124+ } catch (InterruptedException e ) {
125+ Thread .currentThread ().interrupt ();
126+ log .error ("HTTP request interrupted. Aborting..." , e );
127+ return Optional .empty ();
128+ }
129+ }
130+ try {
131+ return processHttpResponse (response , request );
132+ } catch (IOException e ) {
133+ log .error ("IOException during HTTP response processing." , e );
134+ return Optional .empty ();
135+ }
86136 }
87137
88138 private Optional <RowData > processHttpResponse (
0 commit comments